changeset 9614:58edd448da4f

archive: add branch and tag informations to the .hg_archival.txt file Up to this changeset, only the repo (first node) and current node hash were included. This adds also the named branch and tags. So the additional lines to .hg_archival.txt are branch: the named branch tag: the global tags of this revision, one per line in case of multiple tags latesttag: if the revision is untagged, the latest tag (most recent in ancestors), again one per line if this ancestor has multiple tags. latestagdistance: the longest distance (changesets) to this latest ancestor.
author Gilles Moris <gilles.moris@free.fr>
date Tue, 11 Aug 2009 09:04:02 +0200
parents d051db8e9e44
children f51d1822d6fd
files mercurial/archival.py tests/test-archive tests/test-archive.out
diffstat 3 files changed, 39 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/archival.py	Mon Oct 19 23:27:20 2009 +0300
+++ b/mercurial/archival.py	Tue Aug 11 09:04:02 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/tests/test-archive	Mon Oct 19 23:27:20 2009 +0300
+++ b/tests/test-archive	Tue Aug 11 09:04:02 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	Mon Oct 19 23:27:20 2009 +0300
+++ b/tests/test-archive.out	Tue Aug 11 09:04:02 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