[PATCH 1 of 5] archive: add branch and tag informations to the .hg_archival.txt file
Gilles Moris
gilles.moris at free.fr
Fri Oct 9 22:02:31 UTC 2009
mercurial/archival.py | 30 +++++++++++++++++++++++++++---
tests/test-archive | 8 ++++++++
tests/test-archive.out | 11 +++++++++++
3 files changed, 46 insertions(+), 3 deletions(-)
# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1249974242 -7200
# Node ID 1992f6d6d2c9f11a5633a9bfbdb1b4e397a3d20a
# Parent 7d429eedeb0d72c9e363aa9d799501299f50f72c
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 where
printed. This adds also the named branch and tags.
So the additional line to .hg_archival.txt are
branch: the named branch
tag: the global tags of this revision, one per line in case of multiple tags
localtag: the local tags of this revision, one per line in case of multiple tags
latesttag: if there is no tag, 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.
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
+import cmdutil
import util
import cStringIO, os, stat, tarfile, time, zipfile
import zlib, gzip
@@ -217,9 +218,32 @@
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))
+
+ content += 'branch: %s\n' % ctx.branch()
+ # global tags show as 'tag', local tag as 'localtag'
+ tags = ''.join(['%stag: %s\n' % (repo.tagtype(t) != 'global' and
+ repo.tagtype(t) or '', t)
+ for t in ctx.tags() if repo.tagtype(t)])
+ if tags:
+ return content + tags
+
+ opts = { 'template': '{latesttag}:{latesttagdistance}',
+ 'style': '', 'patch': None, 'git': None }
+ repo.ui.pushbuffer()
+ cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
+ ltinfo = repo.ui.popbuffer().split(':')
+ # latesttag can contain multiple tag on the same changeset
+ # separated by ':'. Drop each tag on a separate line.
+ content += ''.join('latesttag: %s\n' % t for t in ltinfo[:-1])
+ if len(ltinfo) > 1:
+ content += 'latesttagdistance: %s\n' % ltinfo[-1]
+ return content
+
+ 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 -l -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,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
+localtag: anothertag
+tag: mytag
abort: unknown archive type 'bogus'
% server errors
% empty repo
More information about the Mercurial-devel
mailing list