hg --version

Thomas Arendsen Hein thomas at intevation.de
Sun Jun 19 13:36:00 UTC 2005


* Thomas Arendsen Hein <thomas at intevation.de> [20050619 12:54]:
> * Vincent Danjean <vdanjean.ml at free.fr> [20050619 11:58]:
> >   Moreover, we allways get an 'version unknown' is we build from a
> > tarball got from "python setup.py sdist"
> 
> This is indeed a bug. Before calling "setup.py install" the sdist
> package includes the version number, but overwrites it.

Fixed with the attached patch and in my repo. Please try it.

With this version "hg --version" doesn't work for "build_ext -i"
installations yet. A possible check for this would be:

if directory of sys.argv[0] contains a repo:
    cd to this directory
    do the version dance

But maybe this is too much magic? Imagine someone managing his ~/bin
with Mercurial, this would yield strange results if ~/bin/hg is used
for this. Or maybe one has to check for the existence of
.hg/data/mercurial/version.py.i ... sound like too much magic.

Thomas

-- 
Email: thomas at intevation.de
http://intevation.de/~thomas/
-------------- next part --------------
# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID 719663b7f235d6810ac180d802d541502d8f153f
# Parent  9294dce4b633fedca293b22858431b9acfc61245

remember_version() only writes version if called in a Mercurial repository.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

remember_version() only writes version if called in a Mercurial repository.
forget_version() resets version only if remember_version() wrote it.

manifest hash: b30df9d93c233f4bf07150cc5067f294a98c16f4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCtXFiW7P1GVgWeRoRAgkjAJ9jkwCAHf3yJyDI8R582XjNFNFeWgCZAe27
iqGPYzrRErf6gPKZcoBMsD4=
=t2Bx
-----END PGP SIGNATURE-----

diff -r 9294dce4b633 -r 719663b7f235 mercurial/version.py
--- a/mercurial/version.py	Sat Jun 18 20:56:31 2005
+++ b/mercurial/version.py	Sun Jun 19 13:21:38 2005
@@ -15,6 +15,7 @@
 import time
 
 unknown_version = 'unknown'
+remembered_version = False
 
 def get_version():
     """Return version information if available."""
@@ -34,29 +35,31 @@
 
 def remember_version():
     """Store version information."""
-    f = os.popen("hg identify 2>/dev/null")  # use real hg installation
-    ident = f.read()[:-1]
-    if not f.close() and ident:
-        ids = ident.split(' ', 1)
-        version = ids.pop(0)
-        if version[-1] == '+':
-            version = version[:-1]
-            modified = True
-        else:
-            modified = False
-        if version.isalnum() and ids:
-            for tag in ids[0].split('/'):
-                # is a tag is suitable as a version number?
-                if re.match(r'^(\d+\.)+[\w.-]+$', tag):
-                    version = tag
-                    break
-        if modified:
-            version += time.strftime('+%Y%m%d')
-    else:
-        version = unknown_version
-    write_version(version)
+    global remembered_version
+    if os.access(".hg", os.F_OK):
+        f = os.popen("hg identify 2>/dev/null")  # use real hg installation
+        ident = f.read()[:-1]
+        if not f.close() and ident:
+            ids = ident.split(' ', 1)
+            version = ids.pop(0)
+            if version[-1] == '+':
+                version = version[:-1]
+                modified = True
+            else:
+                modified = False
+            if version.isalnum() and ids:
+                for tag in ids[0].split('/'):
+                    # is a tag is suitable as a version number?
+                    if re.match(r'^(\d+\.)+[\w.-]+$', tag):
+                        version = tag
+                        break
+            if modified:
+                version += time.strftime('+%Y%m%d')
+            remembered_version = True
+            write_version(version)
 
 def forget_version():
     """Remove version information."""
-    write_version(unknown_version)
+    if remembered_version:
+        write_version(unknown_version)
 


More information about the Mercurial mailing list