##// END OF EJS Templates
bisect: avoid adding irrelevant revisions to bisect state...
bisect: avoid adding irrelevant revisions to bisect state When adding new revisions to the bisect state, it only makes sense to add information about revisions that are under consideration (i.e., those that are topologically between the known good and bad revisions). However, if the user passes in a revset (e.g., '!merge()' to exclude merge commits), hg will resolve the revset first and add all matching revisions to the bisect state (which in this case would likely be the majority of revisions in the repo). To avoid this, revisions should only be added to the bisect state if they are between the good and bad revisions (and therefore relevant to the bisection). -- Here are the results of some performance tests using the `mozilla-central` repo (since it is one of the largest freely-available hg repositories in the wild). These tests compare the performance of a locally-built `hg` before and after application of this series. Note that `--noupdate` is passed to avoid including update time (which should not vary across cases). Setup (run between each test): $ hg bisect --reset $ hg bisect --noupdate --bad 56c3ad4bde5c70714b784ccf15d099e0df0f5bde $ hg bisect --noupdate --good 57426696adaf08298af3027fa77486fee0633b13 Test using a revset that returns a very large number of revisions: $ time hg bisect --noupdate --skip '!merge()' > /dev/null Before: real 0m9.398s user 0m9.233s sys 0m0.120s After: real 0m1.513s user 0m1.425s sys 0m0.052s Test using a revset that is expensive to compute: $ time hg bisect --noupdate --skip 'desc("Bug")' > /dev/null Before: real 0m49.853s user 0m49.580s sys 0m0.243s After: real 0m4.120s user 0m4.036s sys 0m0.048s

File last commit:

r50180:56f98406 default
r50337:81623652 default
Show More
test-fastannotate-revmap.py
221 lines | 5.0 KiB | text/x-python | PythonLexer
/ tests / test-fastannotate-revmap.py
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 import os
import tempfile
Pulkit Goyal
py3: alias xrange to range in tests/test-fastannotate-revmap.py...
r39444 from mercurial import (
pycompat,
util,
)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 from hgext.fastannotate import error, revmap
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 def genhsh(i):
Pulkit Goyal
py3: use pycompat.bytechr() instead of chr() in test-fastannotate-revmap.py...
r40982 return pycompat.bytechr(i) + b'\0' * 19
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 def gettemppath():
fd, path = tempfile.mkstemp()
Matt Harbison
test-fastannotate: close fd before unlinking to keep Windows happy
r39286 os.close(fd)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 os.unlink(path)
return path
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 def ensure(condition):
if not condition:
raise RuntimeError('Unexpected')
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 def testbasicreadwrite():
path = gettemppath()
rm = revmap.revmap(path)
ensure(rm.maxrev == 0)
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(5):
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ensure(rm.rev2hsh(i) is None)
ensure(rm.hsh2rev(b'\0' * 20) is None)
Augie Fackler
tests: add lots of b prefix goo to test-fastannotate-revmap.py...
r41152 paths = [
Augie Fackler
formatting: blacken the codebase...
r43346 b'',
b'a',
None,
b'b',
b'b',
b'c',
b'c',
None,
b'a',
b'b',
b'a',
b'a',
]
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 5):
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ensure(rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i]) == i)
ensure(rm.maxrev == 4)
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 5):
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ensure(rm.hsh2rev(genhsh(i)) == i)
ensure(rm.rev2hsh(i) == genhsh(i))
# re-load and verify
rm.flush()
rm = revmap.revmap(path)
ensure(rm.maxrev == 4)
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 5):
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ensure(rm.hsh2rev(genhsh(i)) == i)
ensure(rm.rev2hsh(i) == genhsh(i))
ensure(bool(rm.rev2flag(i) & revmap.sidebranchflag) == bool(i & 1))
# append without calling save() explicitly
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(5, 12):
Augie Fackler
formatting: blacken the codebase...
r43346 ensure(
rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i], flush=True)
== i
)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243
# re-load and verify
rm = revmap.revmap(path)
ensure(rm.maxrev == 11)
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 12):
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ensure(rm.hsh2rev(genhsh(i)) == i)
ensure(rm.rev2hsh(i) == genhsh(i))
ensure(rm.rev2path(i) == paths[i] or paths[i - 1])
ensure(bool(rm.rev2flag(i) & revmap.sidebranchflag) == bool(i & 1))
os.unlink(path)
# missing keys
ensure(rm.rev2hsh(12) is None)
ensure(rm.rev2hsh(0) is None)
ensure(rm.rev2hsh(-1) is None)
ensure(rm.rev2flag(12) is None)
ensure(rm.rev2path(12) is None)
ensure(rm.hsh2rev(b'\1' * 20) is None)
# illformed hash (not 20 bytes)
try:
rm.append(b'\0')
ensure(False)
except Exception:
pass
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 def testcorruptformat():
path = gettemppath()
# incorrect header
Augie Fackler
tests: add lots of b prefix goo to test-fastannotate-revmap.py...
r41152 with open(path, 'wb') as f:
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 f.write(b'NOT A VALID HEADER')
try:
revmap.revmap(path)
ensure(False)
except error.CorruptedFileError:
pass
# rewrite the file
os.unlink(path)
rm = revmap.revmap(path)
rm.append(genhsh(0), flush=True)
rm = revmap.revmap(path)
ensure(rm.maxrev == 1)
# corrupt the file by appending a byte
size = os.stat(path).st_size
Augie Fackler
tests: add lots of b prefix goo to test-fastannotate-revmap.py...
r41152 with open(path, 'ab') as f:
f.write(b'\xff')
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 try:
revmap.revmap(path)
ensure(False)
except error.CorruptedFileError:
pass
# corrupt the file by removing the last byte
ensure(size > 0)
Augie Fackler
tests: add lots of b prefix goo to test-fastannotate-revmap.py...
r41152 with open(path, 'wb') as f:
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 f.truncate(size - 1)
try:
revmap.revmap(path)
ensure(False)
except error.CorruptedFileError:
pass
os.unlink(path)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 def testcopyfrom():
path = gettemppath()
rm = revmap.revmap(path)
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 10):
Augie Fackler
formatting: blacken the codebase...
r43346 ensure(
rm.append(genhsh(i), sidebranch=(i & 1), path=(b'%d' % (i // 3)))
== i
)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 rm.flush()
# copy rm to rm2
rm2 = revmap.revmap()
rm2.copyfrom(rm)
path2 = gettemppath()
rm2.path = path2
rm2.flush()
# two files should be the same
Augie Fackler
cleanup: run pyupgrade on our source tree to clean up varying things...
r44937 ensure(len({util.readfile(p) for p in [path, path2]}) == 1)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243
os.unlink(path)
os.unlink(path2)
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class fakefctx:
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 def __init__(self, node, path=None):
self._node = node
self._path = path
def node(self):
return self._node
def path(self):
return self._path
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 def testcontains():
path = gettemppath()
rm = revmap.revmap(path)
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 5):
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ensure(rm.append(genhsh(i), sidebranch=(i & 1)) == i)
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 5):
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ensure(((genhsh(i), None) in rm) == ((i & 1) == 0))
ensure((fakefctx(genhsh(i)) in rm) == ((i & 1) == 0))
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(5, 10):
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ensure(fakefctx(genhsh(i)) not in rm)
ensure((genhsh(i), None) not in rm)
# "contains" checks paths
rm = revmap.revmap()
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 5):
Augie Fackler
tests: add lots of b prefix goo to test-fastannotate-revmap.py...
r41152 ensure(rm.append(genhsh(i), path=(b'%d' % (i // 2))) == i)
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 5):
Augie Fackler
tests: add lots of b prefix goo to test-fastannotate-revmap.py...
r41152 ensure(fakefctx(genhsh(i), path=(b'%d' % (i // 2))) in rm)
ensure(fakefctx(genhsh(i), path=b'a') not in rm)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 def testlastnode():
path = gettemppath()
ensure(revmap.getlastnode(path) is None)
rm = revmap.revmap(path)
ensure(revmap.getlastnode(path) is None)
Manuel Jacob
py3: remove xrange() compatibility code...
r50180 for i in range(1, 10):
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 hsh = genhsh(i)
Augie Fackler
tests: add lots of b prefix goo to test-fastannotate-revmap.py...
r41152 rm.append(hsh, path=(b'%d' % (i // 2)), flush=True)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ensure(revmap.getlastnode(path) == hsh)
rm2 = revmap.revmap(path)
ensure(rm2.rev2hsh(rm2.maxrev) == hsh)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 testbasicreadwrite()
testcorruptformat()
testcopyfrom()
testcontains()
testlastnode()