setup: calculate version more correctly
authorBryan O'Sullivan <bryano@fb.com>
Fri, 05 Oct 2012 13:44:52 -0500
changeset 17709 b7fff47bb128
parent 17708 4f2f0f367ef6
child 17713 2c6382772db0
setup: calculate version more correctly The old calculation code failed to properly identify revs that weren't tagged, leaving us with a version of "unknown" most of the time during development.
setup.py
--- a/setup.py	Thu Oct 04 17:00:32 2012 -0500
+++ b/setup.py	Fri Oct 05 13:44:52 2012 -0500
@@ -172,18 +172,17 @@
     env['SystemRoot'] = os.environ['SystemRoot']
 
 if os.path.isdir('.hg'):
-    cmd = [sys.executable, 'hg', 'id', '-i', '-t']
-    l = runhg(cmd, env).split()
-    while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
-        l.pop()
-    if len(l) > 1: # tag found
-        version = l[-1]
-        if l[0].endswith('+'): # propagate the dirty status to the tag
+    cmd = [sys.executable, 'hg', 'log', '-r', '.', '--template', '{tags}\n']
+    numerictags = [t for t in runhg(cmd, env).split() if t[0].isdigit()]
+    hgid = runhg([sys.executable, 'hg', 'id', '-i'], env).strip()
+    if numerictags: # tag(s) found
+        version = numerictags[-1]
+        if hgid.endswith('+'): # propagate the dirty status to the tag
             version += '+'
-    elif len(l) == 1: # no tag found
+    else: # no tag found
         cmd = [sys.executable, 'hg', 'parents', '--template',
                '{latesttag}+{latesttagdistance}-']
-        version = runhg(cmd, env) + l[0]
+        version = runhg(cmd, env) + hgid
     if version.endswith('+'):
         version += time.strftime('%Y%m%d')
 elif os.path.exists('.hg_archival.txt'):