Patchwork [5,of,5] archive: look for first visible revision to build repo identity (issue4591)

login
register
mail settings
Submitter Yuya Nishihara
Date April 9, 2015, 12:57 p.m.
Message ID <2559dd8c528d83c16268.1428584237@mimosa>
Download mbox | patch
Permalink /patch/8574/
State Accepted
Commit 33ab99a6ad9b2492af4f3c7a45736d2aac50f980
Headers show

Comments

Yuya Nishihara - April 9, 2015, 12:57 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1428503402 -32400
#      Wed Apr 08 23:30:02 2015 +0900
# Node ID 2559dd8c528d83c1626827cac8f9caef99b2233c
# Parent  8837e54c611889f857f111dcec7720af63bb334a
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.
Matt Mackall - April 9, 2015, 5:45 p.m.
On Thu, 2015-04-09 at 21:57 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1428503402 -32400
> #      Wed Apr 08 23:30:02 2015 +0900
> # Node ID 2559dd8c528d83c1626827cac8f9caef99b2233c
> # Parent  8837e54c611889f857f111dcec7720af63bb334a
> archive: look for first visible revision to build repo identity (issue4591)

These are queued for default, thanks.

Patch

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 ..