[PATCH 2 of 4] archive: add tags to the .hg_archival.txt file
Gilles Moris
gilles.moris at free.fr
Tue Aug 11 03:08:12 CDT 2009
mercurial/archival.py | 19 ++++++++++++++++---
tests/test-archive | 8 ++++++++
tests/test-archive.out | 9 +++++++++
3 files changed, 33 insertions(+), 3 deletions(-)
# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1249974242 -7200
# Node ID 976e9da9ae80a86f2f7d0e64858d9a84c078b699
# Parent aa102afa2e7b61a2d09b71ff8916397b1de8456a
archive: add tags to the .hg_archival.txt file
If multiple tags exist on this changeset, they will be displayed one by line.
If the changeset has no tag, the last tag in history (most recent ancestor)
will be displayed instead, along to the longest distance to it.
diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -7,6 +7,7 @@
from i18n import _
from node import hex
+from cmdutil import computelasttagmap
import util
import cStringIO, os, stat, tarfile, time, zipfile
import zlib, gzip
@@ -217,9 +218,21 @@
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():
+ content = 'repo: %s\nnode: %s\n' % (
+ hex(repo.changelog.node(0)), hex(node))
+
+ tags = ''.join(['tag: %s\n' % t for t in ctx.tags()
+ if repo.tagtype(t) == 'global'])
+ if tags:
+ return content + tags
+
+ ltmap = computelasttagmap(repo)
+ return content + 'lasttag: %s\nlasttagdistance: %d\n' % \
+ (ltmap[ctx.rev()][2], ltmap[ctx.rev()][1])
+
+ 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)
diff --git a/tests/test-archive b/tests/test-archive
--- a/tests/test-archive
+++ b/tests/test-archive
@@ -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
diff --git a/tests/test-archive.out b/tests/test-archive.out
--- a/tests/test-archive.out
+++ b/tests/test-archive.out
@@ -57,6 +57,15 @@
test-TIP/baz/bletch
test-TIP/foo
rev-0.tar created
+% test .hg_archival.txt
+repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
+node: 2c0277f05ed49d1c8328fb9ba92fba7a5ebcb33e
+lasttag: null
+lasttagdistance: 3
+repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
+node: 2c0277f05ed49d1c8328fb9ba92fba7a5ebcb33e
+tag: anothertag
+tag: mytag
abort: unknown archive type 'bogus'
% server errors
% empty repo
More information about the Mercurial-devel
mailing list