diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -477,8 +477,9 @@ i = int(prefix) # if we are a pure int, then starting with zero will not be # confused as a rev; or, obviously, if the int is larger - # than the value of the tip rev - if prefix[0:1] == b'0' or i >= len(repo): + # than the value of the tip rev. We still need to disambiguate if + # prefix == '0', since that *is* a valid revnum. + if (prefix != b'0' and prefix[0:1] == b'0') or i >= len(repo): return False return True except ValueError: diff --git a/tests/test-revisions.t b/tests/test-revisions.t --- a/tests/test-revisions.t +++ b/tests/test-revisions.t @@ -25,7 +25,7 @@ > revisions.disambiguatewithin=not 4 > EOF $ hg l - 5:0 + 5:00 4:7ba5d 3:7b 2:72 diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t --- a/tests/test-template-functions.t +++ b/tests/test-template-functions.t @@ -804,6 +804,8 @@ e777603221 bcc7ff960b f7769ec2ab + $ hg log --template '{shortest(node, 1)}\n' -r null + 00 $ hg log --template '{node|shortest}\n' -l1 e777 @@ -915,6 +917,55 @@ $ cd .. +Test prefixhexnode when the first character of the hash is 0. + $ hg init hashcollision2 + $ cd hashcollision2 + $ cat <> .hg/hgrc + > [experimental] + > evolution.createmarkers=True + > EOF + $ echo 0 > a + $ hg ci -qAm 0 + $ echo 21 > a + $ hg ci -qm 21 + $ hg up -q null + $ hg log -r0: -T '{rev}:{node}\n' + 0:b4e73ffab476aa0ee32ed81ca51e07169844bc6a + 1:0cf177ba2b1dc3862a00fb81715fec90950201be + + we need the 'x' prefix to ensure we aren't colliding with rev0. We identify + the collision with nullid if we aren't using disambiguatewithin, so we need to set + that as well. + $ hg --config experimental.revisions.disambiguatewithin='descendants(0)' \ + > --config experimental.revisions.prefixhexnode=yes \ + > log -r 1 -T '{rev}:{shortest(node, 0)}\n' + 1:x0 + + $ hg debugobsolete 0cf177ba2b1dc3862a00fb81715fec90950201be + obsoleted 1 changesets + $ hg up -q 0 + $ echo 61 > a + $ hg ci -m 61 + $ hg log -r0: -T '{rev}:{node}\n' + 0:b4e73ffab476aa0ee32ed81ca51e07169844bc6a + 2:01384dde84b3a511ae0835f35ac40bd806c99bb8 + + we still have the 'x' prefix because '0' is still the shortest prefix, since + rev1's '0c' is hidden. + $ hg --config experimental.revisions.disambiguatewithin=0:-1-0 \ + > --config experimental.revisions.prefixhexnode=yes \ + > log -r 0:-1-0 -T '{rev}:{shortest(node, 0)}\n' + 2:x0 + + we don't have the 'x' prefix on 2 because '01' is not a synonym for rev1. + $ hg --config experimental.revisions.disambiguatewithin=0:-1-0 \ + > --config experimental.revisions.prefixhexnode=yes \ + > log -r 0:-1-0 -T '{rev}:{shortest(node, 0)}\n' --hidden + 1:0c + 2:01 + + $ cd .. + Test pad function $ cd r