changeset 50149:0f0880c8a7e5

branching: merge with stable
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 18 Feb 2023 02:39:32 +0100
parents 06659dea51b0 (current diff) 889d2a2e9326 (diff)
children b900f40c343e
files Makefile mercurial/dirstate.py mercurial/dirstatemap.py setup.py
diffstat 4 files changed, 67 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Feb 16 14:56:59 2023 +0000
+++ b/Makefile	Sat Feb 18 02:39:32 2023 +0100
@@ -58,7 +58,7 @@
 all: build doc
 
 local:
-	$(PYTHON) setup.py $(PURE) \
+	MERCURIAL_SETUP_MAKE_LOCAL=1 $(PYTHON) setup.py $(PURE) \
 	  build_py -c -d . \
 	  build_ext $(COMPILERFLAG) -i \
 	  build_hgexe $(COMPILERFLAG) -i \
--- a/mercurial/dirstatemap.py	Thu Feb 16 14:56:59 2023 +0000
+++ b/mercurial/dirstatemap.py	Sat Feb 18 02:39:32 2023 +0100
@@ -114,6 +114,8 @@
         new_docket = docketmod.DirstateDocket.with_new_uuid(
             self.parents(), len(packed), meta
         )
+        if old_docket.uuid == new_docket.uuid:
+            raise error.ProgrammingError(b'dirstate docket name collision')
         data_filename = new_docket.data_filename()
         self._opener.write(data_filename, packed)
         # tell the transaction that we are adding a new file
--- a/setup.py	Thu Feb 16 14:56:59 2023 +0000
+++ b/setup.py	Sat Feb 18 02:39:32 2023 +0100
@@ -21,6 +21,11 @@
     return s.decode('latin-1')
 
 
+def eprint(*args, **kwargs):
+    kwargs['file'] = sys.stderr
+    print(*args, **kwargs)
+
+
 import ssl
 
 # ssl.HAS_TLSv1* are preferred to check support but they were added in Python
@@ -288,10 +293,11 @@
     if retcode == 0 and not filterhgerr(err):
         return hgcommand(hgcmd, hgenv)
 
-    raise SystemExit(
-        'Unable to find a working hg binary to extract the '
-        'version from the repository tags'
-    )
+    eprint("/!\\")
+    eprint(r"/!\ Unable to find a working hg binary")
+    eprint(r"/!\ Version cannot be extract from the repository")
+    eprint(r"/!\ Re-run the setup once a first version is built")
+    return None
 
 
 def localhgenv():
@@ -316,33 +322,46 @@
 
 version = ''
 
-if os.path.isdir('.hg'):
+
+def _try_get_version():
     hg = findhg()
+    if hg is None:
+        return ''
+    hgid = None
+    numerictags = []
     cmd = ['log', '-r', '.', '--template', '{tags}\n']
-    numerictags = [t for t in sysstr(hg.run(cmd)).split() if t[0:1].isdigit()]
+    pieces = sysstr(hg.run(cmd)).split()
+    numerictags = [t for t in pieces if t[0:1].isdigit()]
     hgid = sysstr(hg.run(['id', '-i'])).strip()
     if not hgid:
-        # Bail out if hg is having problems interacting with this repository,
-        # rather than falling through and producing a bogus version number.
-        # Continuing with an invalid version number will break extensions
-        # that define minimumhgversion.
-        raise SystemExit('Unable to determine hg version from local repository')
+        eprint("/!\\")
+        eprint(r"/!\ Unable to determine hg version from local repository")
+        eprint(r"/!\ Failed to retrieve current revision tags")
+        return ''
     if numerictags:  # tag(s) found
         version = numerictags[-1]
         if hgid.endswith('+'):  # propagate the dirty status to the tag
             version += '+'
-    else:  # no tag found
+    else:  # no tag found on the checked out revision
         ltagcmd = ['parents', '--template', '{latesttag}']
         ltag = sysstr(hg.run(ltagcmd))
         if not ltag:
-            ltag = 'null'
+            eprint("/!\\")
+            eprint(r"/!\ Unable to determine hg version from local repository")
+            eprint(
+                r"/!\ Failed to retrieve current revision distance to lated tag"
+            )
+            return ''
         changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag]
         changessince = len(hg.run(changessincecmd).splitlines())
-        if ltag == 'null':
-            ltag = '0.0'
         version = '%s+hg%s.%s' % (ltag, changessince, hgid)
     if version.endswith('+'):
         version = version[:-1] + 'local' + time.strftime('%Y%m%d')
+    return version
+
+
+if os.path.isdir('.hg'):
+    version = _try_get_version()
 elif os.path.exists('.hg_archival.txt'):
     kw = dict(
         [[t.strip() for t in l.split(':', 1)] for l in open('.hg_archival.txt')]
@@ -362,21 +381,35 @@
     with open('mercurial/__version__.py') as f:
         data = f.read()
     version = re.search('version = b"(.*)"', data).group(1)
-
-if version:
-    versionb = version
-    if not isinstance(versionb, bytes):
-        versionb = versionb.encode('ascii')
+if not version:
+    if os.environ.get("MERCURIAL_SETUP_MAKE_LOCAL") == "1":
+        version = "0.0+0"
+        eprint("/!\\")
+        eprint(r"/!\ Using '0.0+0' as the default version")
+        eprint(r"/!\ Re-run make local once that first version is built")
+        eprint("/!\\")
+    else:
+        eprint("/!\\")
+        eprint(r"/!\ Could not determine the Mercurial version")
+        eprint(r"/!\ You need to build a local version first")
+        eprint(r"/!\ Run `make local` and try again")
+        eprint("/!\\")
+        msg = "Run `make local` first to get a working local version"
+        raise SystemExit(msg)
 
-    write_if_changed(
-        'mercurial/__version__.py',
-        b''.join(
-            [
-                b'# this file is autogenerated by setup.py\n'
-                b'version = b"%s"\n' % versionb,
-            ]
-        ),
-    )
+versionb = version
+if not isinstance(versionb, bytes):
+    versionb = versionb.encode('ascii')
+
+write_if_changed(
+    'mercurial/__version__.py',
+    b''.join(
+        [
+            b'# this file is autogenerated by setup.py\n'
+            b'version = b"%s"\n' % versionb,
+        ]
+    ),
+)
 
 
 class hgbuild(build):
--- a/tests/test-chg.t	Thu Feb 16 14:56:59 2023 +0000
+++ b/tests/test-chg.t	Sat Feb 18 02:39:32 2023 +0100
@@ -352,11 +352,10 @@
 repository cache
 ----------------
 
-  $ rm log/server.log*
   $ cp $HGRCPATH.unconfigured $HGRCPATH
   $ cat <<'EOF' >> $HGRCPATH
   > [cmdserver]
-  > log = $TESTTMP/log/server.log
+  > log = $TESTTMP/log/server-cached.log
   > max-repo-cache = 1
   > track-log = command, repocache
   > EOF
@@ -420,9 +419,7 @@
 
 check server log:
 
-  $ cat log/server.log | filterlog
-  YYYY/MM/DD HH:MM:SS (PID)> worker process exited (pid=...)
-  YYYY/MM/DD HH:MM:SS (PID)> worker process exited (pid=...) (?)
+  $ cat log/server-cached.log | filterlog
   YYYY/MM/DD HH:MM:SS (PID)> init cached
   YYYY/MM/DD HH:MM:SS (PID)> id -R cached
   YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in  ...s)