[PATCH 2 of 5 v6] revset: use localrepo branchcache for branch name filtering
Mads Kiilerich
mads at kiilerich.com
Sat Oct 18 13:43:34 CDT 2014
# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1413657723 -7200
# Sat Oct 18 20:42:03 2014 +0200
# Node ID dd89e376f28eaad38c3c5e18bc0daff3c416a0be
# Parent a504712dc5ac07e5ddf550f47818267f783f85de
revset: use localrepo branchcache for branch name filtering
Branch name filtering in revsets was expensive. For every rev it created a
changectx and called .branch(). (Using changelog.branchinfo() would make it a
bit faster.)
Instead, use the new localrepo caching branch lookup method.
On the small hg repo:
hg log --time -r 'branch(stable) & branch(default)'
Before:
time: real 1.260 secs (user 1.230+0.000 sys 0.010+0.000)
After:
time: real 0.970 secs (user 0.950+0.000 sys 0.020+0.000)
time: real 0.120 secs (user 0.110+0.000 sys 0.010+0.000)
On mozilla-central with 210557:a280a03c9f3c :
hg --time log -r 'branch(mobile)' -T.
Before:
time: real 10.450 secs (user 10.390+0.000 sys 0.060+0.000)
After:
time: real 8.550 secs (user 8.480+0.000 sys 0.060+0.000)
time: real 0.850 secs (user 0.830+0.000 sys 0.020+0.000)
First run is 20% faster (primarily because the new code path uses
changelog.branchinfo instead changectx.branch and we avoid messing with
localrepo). Following runs will use the cache and are 10 x faster.
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -478,6 +478,7 @@ def branch(repo, subset, x):
a regular expression. To match a branch that actually starts with `re:`,
use the prefix `literal:`.
"""
+ branch = repo.revbranchcache.branch
try:
b = getstring(x, '')
except error.ParseError:
@@ -489,16 +490,16 @@ def branch(repo, subset, x):
# note: falls through to the revspec case if no branch with
# this name exists
if pattern in repo.branchmap():
- return subset.filter(lambda r: matcher(repo[r].branch()))
+ return subset.filter(lambda r: matcher(branch(r)))
else:
- return subset.filter(lambda r: matcher(repo[r].branch()))
+ return subset.filter(lambda r: matcher(branch(r)))
s = getset(repo, spanset(repo), x)
b = set()
for r in s:
- b.add(repo[r].branch())
+ b.add(branch(r))
c = s.__contains__
- return subset.filter(lambda r: c(r) or repo[r].branch() in b)
+ return subset.filter(lambda r: c(r) or branch(r) in b)
def bumped(repo, subset, x):
"""``bumped()``
@@ -1438,7 +1439,7 @@ def matching(repo, subset, x):
getfieldfuncs = []
_funcs = {
'user': lambda r: repo[r].user(),
- 'branch': lambda r: repo[r].branch(),
+ 'branch': repo.revbranchcache.branch,
'date': lambda r: repo[r].date(),
'description': lambda r: repo[r].description(),
'files': lambda r: repo[r].files(),
@@ -1541,9 +1542,9 @@ def sort(repo, subset, x):
elif k == '-rev':
e.append(-r)
elif k == 'branch':
- e.append(c.branch())
+ e.append(repo.revbranchcache.branch(r))
elif k == '-branch':
- e.append(invert(c.branch()))
+ e.append(invert(repo.revbranchcache.branch(r)))
elif k == 'desc':
e.append(c.description())
elif k == '-desc':
diff --git a/tests/test-branches.t b/tests/test-branches.t
--- a/tests/test-branches.t
+++ b/tests/test-branches.t
@@ -516,4 +516,75 @@ template output:
}
]
+revision branch name caching implementation
+
+cache creation
+ $ rm .hg/cache/branchnames
+ $ hg debugrevspec 'branch("re:a ")'
+ 7
+ $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
+ b90894765458b0298f0c822fb5193c1e .hg/cache/branchnames
+recovery from invalid cache file
+ $ echo > .hg/cache/branchnames
+ $ hg debugrevspec 'branch("re:a ")'
+ 7
+ $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
+ b90894765458b0298f0c822fb5193c1e .hg/cache/branchnames
+recovery from other corruption - extra trailing data
+ $ echo >> .hg/cache/branchnames
+ $ hg debugrevspec 'branch("re:a ")'
+ 7
+ $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
+ b90894765458b0298f0c822fb5193c1e .hg/cache/branchnames
+lazy update after commit
+ $ hg tag tag
+ $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
+ b90894765458b0298f0c822fb5193c1e .hg/cache/branchnames
+ $ hg debugrevspec 'branch("re:a ")'
+ 7
+ $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
+ 807c628e9f3f9040cc1da7124c4cb2d8 .hg/cache/branchnames
+update after rollback - cache keeps stripped revs until written for other reasons
+ $ hg up -qr '.^'
+ $ hg rollback -qf
+ $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
+ 807c628e9f3f9040cc1da7124c4cb2d8 .hg/cache/branchnames
+ $ hg debugrevspec 'branch("re:a ")'
+ 7
+ $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
+ 807c628e9f3f9040cc1da7124c4cb2d8 .hg/cache/branchnames
+handle history mutations that doesn't change the tip node - this is a problem
+with the cache invalidation scheme used by branchmap
+ $ hg log -r tip+b -T'{rev}:{node|short} {branch}\n'
+ 14:f894c25619d3 c
+ 13:e23b5505d1ad b
+ $ hg bundle -q --all bu.hg
+ $ hg --config extensions.strip= strip --no-b -qr -1:
+ $ hg up -q tip
+ $ hg branch
+ b
+ $ hg branch -q hacked
+ $ hg ci --amend -qm 'hacked'
+ $ hg pull -q bu.hg -r f894c25619d3
+ $ hg log -r tip+b -T'{rev}:{node|short} {branch}\n'
+ 14:f894c25619d3 c
+ 12:e3d49c0575d8 b
+ $ hg debugrevspec 'branch("hacked")'
+ 13
+ $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
+ b4401727ffd84a7c339faf8a6e470671 .hg/cache/branchnames
+cleanup, restore old state
+ $ hg --config extensions.strip= strip --no-b -qr -2:
+ $ hg pull -q bu.hg
+ $ rm bu.hg
+ $ hg up -qr tip
+ $ hg log -r tip -T'{rev}:{node|short}\n'
+ 14:f894c25619d3
+the cache file do not go back to the old state - it still contains the
+now unused 'hacked' branch name)
+ $ hg debugrevspec 'branch("re:a ")'
+ 7
+ $ "$TESTDIR/md5sum.py" .hg/cache/branchnames
+ e1a76da810555ed88e3b2f467395e2ff .hg/cache/branchnames
+
$ cd ..
More information about the Mercurial-devel
mailing list