--- a/hgext/directaccess.py Fri May 27 17:33:53 2016 +0200
+++ b/hgext/directaccess.py Mon Aug 01 22:37:48 2016 +0200
@@ -132,38 +132,35 @@
_listtuple = ('symbol', '_list')
+def _ishashsymbol(symbol, maxrev):
+ # Returns true if symbol looks like a hash
+ try:
+ n = int(symbol)
+ if n <= maxrev:
+ # It's a rev number
+ return False
+ except ValueError:
+ pass
+ return hashre.match(symbol)
+
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:
return []
+ results = []
if len(tree) == 2 and tree[0] == "symbol":
- try:
- 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]]
- return []
+ results.append(tree[1])
elif tree[0] == "func" and tree[1] == _listtuple:
# the optimiser will group sequence of hash request
- result = []
- for entry in tree[2][1].split('\0'):
- if hashre.match(entry):
- result.append(entry)
- return result
+ results += tree[2][1].split('\0')
elif len(tree) >= 3:
- results = []
for subtree in tree[1:]:
results += gethashsymbols(subtree, maxrev)
+ # return directly, we don't need to filter symbols again
return results
- else:
- return []
+ return [s for s in results if _ishashsymbol(s, maxrev)]
def _posttreebuilthook(orig, tree, repo):
# This is use to enabled direct hash access
--- a/hgext/evolve.py Fri May 27 17:33:53 2016 +0200
+++ b/hgext/evolve.py Mon Aug 01 22:37:48 2016 +0200
@@ -71,6 +71,7 @@
import collections
import socket
import errno
+import hashlib
import struct
sha1re = re.compile(r'\b[0-9a-f]{6,40}\b')
@@ -3859,7 +3860,7 @@
for i in unfi:
ctx = unfi[i]
entry = 0
- sha = util.sha1()
+ sha = hashlib.sha1()
# add data from p1
for p in ctx.parents():
p = p.rev()
--- a/hgext/simple4server.py Fri May 27 17:33:53 2016 +0200
+++ b/hgext/simple4server.py Mon Aug 01 22:37:48 2016 +0200
@@ -13,6 +13,7 @@
import mercurial.obsolete
+import hashlib
import struct
from mercurial import util
from mercurial import wireproto
@@ -192,7 +193,7 @@
for i in unfi:
ctx = unfi[i]
entry = 0
- sha = util.sha1()
+ sha = hashlib.sha1()
# add data from p1
for p in ctx.parents():
p = p.rev()
--- a/tests/test-inhibit.t Fri May 27 17:33:53 2016 +0200
+++ b/tests/test-inhibit.t Mon Aug 01 22:37:48 2016 +0200
@@ -375,6 +375,21 @@
cf5c4f4554ce
2db36d8066ff
+Test directaccess only takes hashes
+
+ $ HOOKPATH=$TESTTMP/printexplicitaccess.py
+ $ cat >> $HOOKPATH <<EOF
+ > def hook(ui, repo, **kwds):
+ > for i in sorted(repo._explicitaccess):
+ > ui.write('directaccess: %s\n' % i)
+ > EOF
+
+ $ hg log -r 1 -r 2 -r 2db36d8066f -T '{rev}\n' --config hooks.post-log=python:$HOOKPATH:hook
+ 1
+ 2
+ 3
+ directaccess: 3
+
With severals hidden sha, rebase of one hidden stack onto another one:
$ hg update -C 0
0 files updated, 0 files merged, 4 files removed, 0 files unresolved