changeset 425:719663b7f235

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-----
author Thomas Arendsen Hein <thomas@intevation.de>
date Sun, 19 Jun 2005 14:21:38 +0100
parents 9294dce4b633
children 8c90ab5644c9
files mercurial/version.py
diffstat 1 files changed, 25 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/version.py	Sat Jun 18 21:56:31 2005 +0100
+++ b/mercurial/version.py	Sun Jun 19 14:21:38 2005 +0100
@@ -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)