changeset 9616:0fedf8233b21

merge with crew
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Tue, 20 Oct 2009 00:30:36 +0200
parents f51d1822d6fd (diff) c63c336ee2f7 (current diff)
children fafd653134d0
files
diffstat 4 files changed, 75 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/archival.py	Tue Oct 20 00:17:36 2009 +0200
+++ b/mercurial/archival.py	Tue Oct 20 00:30:36 2009 +0200
@@ -7,6 +7,7 @@
 
 from i18n import _
 from node import hex
+import cmdutil
 import util
 import cStringIO, os, stat, tarfile, time, zipfile
 import zlib, gzip
@@ -217,9 +218,25 @@
     archiver = archivers[kind](dest, prefix, mtime or ctx.date()[0])
 
     if repo.ui.configbool("ui", "archivemeta", True):
-        write('.hg_archival.txt', 0644, False,
-              lambda: 'repo: %s\nnode: %s\n' % (
-                  hex(repo.changelog.node(0)), hex(node)))
+        def metadata():
+            base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
+                hex(repo.changelog.node(0)), hex(node), ctx.branch())
+
+            tags = ''.join('tag: %s\n' % t for t in ctx.tags()
+                           if repo.tagtype(t) == 'global')
+            if not tags:
+                repo.ui.pushbuffer()
+                opts = {'template': '{latesttag}\n{latesttagdistance}',
+                        'style': '', 'patch': None, 'git': None}
+                cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
+                ltags, dist = repo.ui.popbuffer().split('\n')
+                tags = ''.join('latesttag: %s\n' % t for t in ltags.split(':'))
+                tags += 'latesttagdistance: %s\n' % dist
+
+            return base + tags
+
+        write('.hg_archival.txt', 0644, False, metadata)
+
     for f in ctx:
         ff = ctx.flags(f)
         write(f, 'x' in ff and 0755 or 0644, 'l' in ff, ctx[f].data)
--- a/setup.py	Tue Oct 20 00:17:36 2009 +0200
+++ b/setup.py	Tue Oct 20 00:30:36 2009 +0200
@@ -97,7 +97,21 @@
 except ImportError:
     pass
 
-version = None
+def runcmd(cmd):
+    p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE, env=env)
+    out, err = p.communicate()
+    # If root is executing setup.py, but the repository is owned by
+    # another user (as in "sudo python setup.py install") we will get
+    # trust warnings since the .hg/hgrc file is untrusted. That is
+    # fine, we don't want to load it anyway.
+    err = [e for e in err.splitlines()
+           if not e.startswith('Not trusting file')]
+    if err:
+        return ''
+    return out
+
+version = ''
 
 if os.path.isdir('.hg'):
     # Execute hg out of this directory with a custom environment which
@@ -113,34 +127,28 @@
         # error 0xc0150004. See: http://bugs.python.org/issue3440
         env['SystemRoot'] = os.environ['SystemRoot']
     cmd = [sys.executable, 'hg', 'id', '-i', '-t']
-
-    p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-                         stderr=subprocess.PIPE, env=env)
-    out, err = p.communicate()
-
-    # If root is executing setup.py, but the repository is owned by
-    # another user (as in "sudo python setup.py install") we will get
-    # trust warnings since the .hg/hgrc file is untrusted. That is
-    # fine, we don't want to load it anyway.
-    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))
+    l = runcmd(cmd).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
+            version += '+'
+    elif len(l) == 1: # no tag found
+        cmd = [sys.executable, 'hg', 'parents', '--template',
+               '{latesttag}+{latesttagdistance}-']
+        version = runcmd(cmd) + l[0]
+    if version.endswith('+'):
+        version += time.strftime('%Y%m%d')
+elif os.path.exists('.hg_archival.txt'):
+    kw = dict([t.strip() for t in l.split(':', 1)]
+              for l in open('.hg_archival.txt'))
+    if 'tag' in kw:
+        version =  kw['tag']
+    elif 'latesttag' in kw:
+        version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
     else:
-        l = out.split()
-        while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
-            l.pop()
-        if l:
-            version = l[-1] # latest tag or revision number
-            if version.endswith('+'):
-                version += time.strftime('%Y%m%d')
-elif os.path.exists('.hg_archival.txt'):
-    hgarchival = open('.hg_archival.txt')
-    for line in hgarchival:
-        if line.startswith('node:'):
-            version = line.split(':')[1].strip()[:12]
-            break
+        version = kw.get('node', '')[:12]
 
 if version:
     f = open("mercurial/__version__.py", "w")
--- a/tests/test-archive	Tue Oct 20 00:17:36 2009 +0200
+++ b/tests/test-archive	Tue Oct 20 00:30:36 2009 +0200
@@ -108,6 +108,14 @@
     echo 'rev-0.tar created'
 fi
 
+echo '% test .hg_archival.txt'
+hg archive ../test-tags
+cat ../test-tags/.hg_archival.txt
+hg tag -r 2 mytag
+hg tag -r 2 anothertag
+hg archive -r 2 ../test-lasttag
+cat ../test-lasttag/.hg_archival.txt
+
 hg archive -t bogus test.bogus
 
 echo % server errors
--- a/tests/test-archive.out	Tue Oct 20 00:17:36 2009 +0200
+++ b/tests/test-archive.out	Tue Oct 20 00:30:36 2009 +0200
@@ -57,6 +57,17 @@
 test-TIP/baz/bletch
 test-TIP/foo
 rev-0.tar created
+% test .hg_archival.txt
+repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
+node: 2c0277f05ed49d1c8328fb9ba92fba7a5ebcb33e
+branch: default
+latesttag: null
+latesttagdistance: 3
+repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
+node: 2c0277f05ed49d1c8328fb9ba92fba7a5ebcb33e
+branch: default
+tag: anothertag
+tag: mytag
 abort: unknown archive type 'bogus'
 % server errors
 % empty repo