[PATCH 3 of 3] setup: improve tag retrieval for archives and fallback to lasttag otherwise

Gilles Moris gilles.moris at free.fr
Sun Aug 9 12:46:08 CDT 2009


 setup.py |  23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)


# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1249839101 -7200
# Node ID f2d442385d9c8e9fb82f9acc030371de6d7b9573
# Parent  5819241694828b709e33b4ebcbcb74dbafc48857
setup: improve tag retrieval for archives and fallback to lasttag otherwise

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -135,12 +135,35 @@
             version = l[-1] # latest tag or revision number
             if version.endswith('+'):
                 version += time.strftime('%Y%m%d')
+        if len(l) == 1: # no tag found for that rev
+            cmd = [sys.executable, 'hg', 'parents',
+                   '--template', '{lasttag}:{lasttagdistance}']
+            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                                 stderr=subprocess.PIPE, env=env)
+            out, err = p.communicate()
+
+            err = [e for e in err.splitlines()
+                   if not e.startswith('Not trusting file')]
+            if err:
+                sys.stderr.write('warning: could not establish Mercurial '
+                                 'version:\n%s\n' % '\n'.join(err))
+            else:
+                l = out.split(':')
+                # append distance to the last tag
+                version += ' (%s+%s)' % (l[0], l[-1])
 elif os.path.exists('.hg_archival.txt'):
     hgarchival = open('.hg_archival.txt')
+    lasttag = None
     for line in hgarchival:
         if line.startswith('node:'):
             version = line.split(':')[1].strip()[:12]
+        if line.startswith('tag:'):
+            version = line.split(':')[1].strip()
             break
+        if line.startswith('lasttag:'):
+            lasttag = line.split(':')[1].strip()
+        if lasttag and line.startswith('lasttagdistance:'):
+            version += ' (%s+%s)' % (lasttag, line.split(':')[1].strip())
 
 if version:
     f = open("mercurial/__version__.py", "w")


More information about the Mercurial-devel mailing list