# HG changeset patch # User Yuya Nishihara # Date 2015-04-08 14:30:02 # Node ID 33ab99a6ad9b2492af4f3c7a45736d2aac50f980 # Parent 0974d3a0be294fb5327f9d8c228120258725097b archive: look for first visible revision to build repo identity (issue4591) No test for the case where all revisions are hidden because "archive" command aborts if the target revision is null. diff --git a/mercurial/archival.py b/mercurial/archival.py --- a/mercurial/archival.py +++ b/mercurial/archival.py @@ -54,11 +54,17 @@ def guesskind(dest): return kind return None +def _rootctx(repo): + # repo[0] may be hidden + for rev in repo: + return repo[rev] + return repo['null'] + def buildmetadata(ctx): '''build content of .hg_archival.txt''' repo = ctx.repo() base = 'repo: %s\nnode: %s\nbranch: %s\n' % ( - repo[0].hex(), ctx.hex(), encoding.fromlocal(ctx.branch())) + _rootctx(repo).hex(), ctx.hex(), encoding.fromlocal(ctx.branch())) tags = ''.join('tag: %s\n' % t for t in ctx.tags() if repo.tagtype(t) == 'global') diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t --- a/tests/test-obsolete.t +++ b/tests/test-obsolete.t @@ -250,6 +250,30 @@ We need to create a clone of 5 and add a o 0:1f0dee641bb7 (public) [ ] add a + $ cd .. + +Revision 0 is hidden +-------------------- + + $ hg init rev0hidden + $ cd rev0hidden + + $ mkcommit kill0 + $ hg up -q null + $ hg debugobsolete `getid kill0` + $ mkcommit a + $ mkcommit b + +Should pick the first visible revision as "repo" node + + $ hg archive ../archive-null + $ cat ../archive-null/.hg_archival.txt + repo: 1f0dee641bb7258c56bd60e93edfa2405381c41e + node: 7c3bad9141dcb46ff89abf5f61856facd56e476c + branch: default + latesttag: null + latesttagdistance: 2 + changessincelatesttag: 2 $ cd ..