[PATCH evolve-ext] directaccess: fix case of shortened hash containing only digits
Laurent Charignon
lcharignon at fb.com
Tue Nov 17 20:46:30 UTC 2015
# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1447793182 28800
# Tue Nov 17 12:46:22 2015 -0800
# Node ID 1b006eb2ab078174134bd63e1b7f56e1ce821b56
# Parent 48547b4c77defdd17c670b1eb0eb94272edf0207
directaccess: fix case of shortened hash containing only digits
Before this patch, directaccess was not working for prefix of hashes solely made
of digits. Let's assume the hash 210589181b14 in a repository with less than
210589 revisions.
Direct access asked to access 210589 was not working and was assuming that
we were referring to the revision 210589 (because it is a number).
This patch fixes the issue and directaccess now works in that case.
Note that a choice is made to prioritize revnumbers compare to hashes.
For example if the revision 210589181b14 appears in a repository with more than
210589 revisions; given "210589", directaccess will make the revision numbered
210589 visible and not the revision with the hash "210589181b14".
diff --git a/hgext/directaccess.py b/hgext/directaccess.py
--- a/hgext/directaccess.py
+++ b/hgext/directaccess.py
@@ -131,7 +131,7 @@ hashre = util.re.compile('[0-9a-fA-F]{1,
_listtuple = ('symbol', '_list')
-def gethashsymbols(tree):
+def gethashsymbols(tree, maxrev):
# Returns the list of symbols of the tree that look like hashes
# for example for the revset 3::abe3ff it will return ('abe3ff')
if not tree:
@@ -139,8 +139,12 @@ def gethashsymbols(tree):
if len(tree) == 2 and tree[0] == "symbol":
try:
- int(tree[1])
- return []
+ n = int(tree[1])
+ # This isn't necessarily a rev number, could be a hash prefix
+ if n > maxrev:
+ return [tree[1]]
+ else:
+ return []
except ValueError as e:
if hashre.match(tree[1]):
return [tree[1]]
@@ -155,7 +159,7 @@ def gethashsymbols(tree):
elif len(tree) >= 3:
results = []
for subtree in tree[1:]:
- results += gethashsymbols(subtree)
+ results += gethashsymbols(subtree, maxrev)
return results
else:
return []
@@ -171,8 +175,8 @@ def _posttreebuilthook(orig, tree, repo)
if filternm is not None and filternm.startswith('visible-directaccess'):
prelength = len(repo._explicitaccess)
accessbefore = set(repo._explicitaccess)
- repo.symbols = gethashsymbols(tree)
cl = repo.unfiltered().changelog
+ repo.symbols = gethashsymbols(tree, len(cl))
for node in repo.symbols:
try:
node = cl._partialmatch(node)
diff --git a/tests/test-inhibit.t b/tests/test-inhibit.t
--- a/tests/test-inhibit.t
+++ b/tests/test-inhibit.t
@@ -525,8 +525,14 @@ Check that rebasing a commit twice makes
|/
o 14:d66ccb8c5871 add cL
|
- $ hg strip -r 104eed5354c7
- 1 changesets pruned
+ $ hg strip -r 210589181b14
+ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+ working directory now at d66ccb8c5871
+ 2 changesets pruned
+
+Using a hash prefix solely made of digits should work
+ $ hg update 210589181
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg rebase -d 18 -r 16 --keep
rebasing 16:a438c045eb37 "add cN"
$ hg log -r 14:: -G
More information about the Mercurial-devel
mailing list