D3455: shortest: make {shortest("fffffffff")} work again
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Mon May 7 16:37:20 UTC 2018
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
{shortest("fffffffff")} should shorten it to the shortest unambiguous
prefix for the working directory. It used to do that until I broke it
in https://phab.mercurial-scm.org/rHG7b29556247776a86ead7eb98fd3a20dafd0c08b4 (scmutil: make shortesthexnodeidprefix() take a full
binary nodeid, 2018-04-14), when we started returning the full hex
nodeid for any working directory prefix shorter than 40 hex
digits. This patch fixes it by catching WdirUnsupported
specifically.
It turned out that I was already testing this and had accidentally
protected the bad behavior in the tests by doing {shortest("f")}
without realizing that "f" was unambiguous and thus resolved to the
working copy id, so that needed to change in the test case ("a"
happened to no be a valid prefix, so I picked that).
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D3455
AFFECTED FILES
mercurial/templatefuncs.py
tests/test-command-template.t
CHANGE DETAILS
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -3901,8 +3901,8 @@
$ hg log -r 'wdir()' -T '{node|shortest}\n'
ffff
- $ hg log --template '{shortest("f")}\n' -l1
- f
+ $ hg log --template '{shortest("a")}\n' -l1
+ a
$ hg log --template '{shortest("0123456789012345678901234567890123456789")}\n' -l1
0123456789012345678901234567890123456789
@@ -3916,6 +3916,15 @@
$ hg log --template '{shortest("not a hex string, but it'\''s 40 bytes long")}\n' -l1
not a hex string, but it's 40 bytes long
+ $ hg log --template '{shortest("ffffffffffffffffffffffffffffffffffffffff")}\n' -l1
+ ffff
+
+ $ hg log --template '{shortest("fffffff")}\n' -l1
+ ffff
+
+ $ hg log --template '{shortest("f")}\n' -l1
+ ffff
+
$ cd ..
Test shortest(node) with the repo having short hash collision:
diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
--- a/mercurial/templatefuncs.py
+++ b/mercurial/templatefuncs.py
@@ -12,6 +12,7 @@
from .i18n import _
from .node import (
bin,
+ wdirid,
)
from . import (
color,
@@ -601,7 +602,9 @@
else:
try:
node = scmutil.resolvehexnodeidprefix(repo, hexnode)
- except (error.LookupError, error.WdirUnsupported):
+ except error.WdirUnsupported:
+ node = wdirid
+ except error.LookupError:
return hexnode
if not node:
return hexnode
To: martinvonz, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list