author | pacien <pacien.trangirard@pacien.net> |
Mon, 21 Feb 2022 15:53:03 +0100 | |
changeset 48851 | d739cd69bb6a |
parent 44452 | 9d2b2df2c2ba |
child 48875 | 6000f5b25c9b |
permissions | -rw-r--r-- |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 |
from __future__ import absolute_import, print_function |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 |
import os |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 |
import tempfile |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 |
|
39407
aa95fd0257df
py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39250
diff
changeset
|
6 |
from mercurial import ( |
aa95fd0257df
py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39250
diff
changeset
|
7 |
pycompat, |
aa95fd0257df
py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39250
diff
changeset
|
8 |
util, |
aa95fd0257df
py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39250
diff
changeset
|
9 |
) |
aa95fd0257df
py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39250
diff
changeset
|
10 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 |
from hgext.fastannotate import error, revmap |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 |
|
39407
aa95fd0257df
py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39250
diff
changeset
|
13 |
if pycompat.ispy3: |
aa95fd0257df
py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39250
diff
changeset
|
14 |
xrange = range |
aa95fd0257df
py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39250
diff
changeset
|
15 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
16 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 |
def genhsh(i): |
40946
5fd63bca43a4
py3: use pycompat.bytechr() instead of chr() in test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39407
diff
changeset
|
18 |
return pycompat.bytechr(i) + b'\0' * 19 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
20 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 |
def gettemppath(): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 |
fd, path = tempfile.mkstemp() |
39250
659f010ffa7e
test-fastannotate: close fd before unlinking to keep Windows happy
Matt Harbison <matt_harbison@yahoo.com>
parents:
39210
diff
changeset
|
23 |
os.close(fd) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 |
os.unlink(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 |
return path |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
27 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 |
def ensure(condition): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 |
if not condition: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 |
raise RuntimeError('Unexpected') |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
32 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 |
def testbasicreadwrite(): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 |
path = gettemppath() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 |
rm = revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
ensure(rm.maxrev == 0) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 |
for i in xrange(5): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 |
ensure(rm.rev2hsh(i) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 |
ensure(rm.hsh2rev(b'\0' * 20) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 |
|
41117
0fea133780bf
tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents:
40946
diff
changeset
|
42 |
paths = [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
43 |
b'', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
44 |
b'a', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
45 |
None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
46 |
b'b', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
47 |
b'b', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
48 |
b'c', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
49 |
b'c', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
50 |
None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
51 |
b'a', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
52 |
b'b', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
53 |
b'a', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
54 |
b'a', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
55 |
] |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 |
for i in xrange(1, 5): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
57 |
ensure(rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i]) == i) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
58 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
59 |
ensure(rm.maxrev == 4) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 |
for i in xrange(1, 5): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
61 |
ensure(rm.hsh2rev(genhsh(i)) == i) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
62 |
ensure(rm.rev2hsh(i) == genhsh(i)) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
63 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
64 |
# re-load and verify |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
65 |
rm.flush() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
66 |
rm = revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
67 |
ensure(rm.maxrev == 4) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
68 |
for i in xrange(1, 5): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
69 |
ensure(rm.hsh2rev(genhsh(i)) == i) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
70 |
ensure(rm.rev2hsh(i) == genhsh(i)) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
71 |
ensure(bool(rm.rev2flag(i) & revmap.sidebranchflag) == bool(i & 1)) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
72 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
73 |
# append without calling save() explicitly |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
74 |
for i in xrange(5, 12): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
75 |
ensure( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
76 |
rm.append(genhsh(i), sidebranch=(i & 1), path=paths[i], flush=True) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
77 |
== i |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
78 |
) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
80 |
# re-load and verify |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
81 |
rm = revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
ensure(rm.maxrev == 11) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
83 |
for i in xrange(1, 12): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
84 |
ensure(rm.hsh2rev(genhsh(i)) == i) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
85 |
ensure(rm.rev2hsh(i) == genhsh(i)) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
86 |
ensure(rm.rev2path(i) == paths[i] or paths[i - 1]) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
87 |
ensure(bool(rm.rev2flag(i) & revmap.sidebranchflag) == bool(i & 1)) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
88 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
89 |
os.unlink(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
90 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
91 |
# missing keys |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
92 |
ensure(rm.rev2hsh(12) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
93 |
ensure(rm.rev2hsh(0) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
94 |
ensure(rm.rev2hsh(-1) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
95 |
ensure(rm.rev2flag(12) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
96 |
ensure(rm.rev2path(12) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
97 |
ensure(rm.hsh2rev(b'\1' * 20) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
98 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
99 |
# illformed hash (not 20 bytes) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
100 |
try: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
101 |
rm.append(b'\0') |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
102 |
ensure(False) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
103 |
except Exception: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
104 |
pass |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
105 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
106 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
107 |
def testcorruptformat(): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
108 |
path = gettemppath() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
109 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
110 |
# incorrect header |
41117
0fea133780bf
tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents:
40946
diff
changeset
|
111 |
with open(path, 'wb') as f: |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
112 |
f.write(b'NOT A VALID HEADER') |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
113 |
try: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
114 |
revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 |
ensure(False) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
116 |
except error.CorruptedFileError: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
117 |
pass |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
118 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
119 |
# rewrite the file |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
120 |
os.unlink(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
121 |
rm = revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
122 |
rm.append(genhsh(0), flush=True) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
123 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
124 |
rm = revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
125 |
ensure(rm.maxrev == 1) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
126 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 |
# corrupt the file by appending a byte |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 |
size = os.stat(path).st_size |
41117
0fea133780bf
tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents:
40946
diff
changeset
|
129 |
with open(path, 'ab') as f: |
0fea133780bf
tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents:
40946
diff
changeset
|
130 |
f.write(b'\xff') |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 |
try: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 |
revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 |
ensure(False) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 |
except error.CorruptedFileError: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 |
pass |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
136 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
137 |
# corrupt the file by removing the last byte |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
138 |
ensure(size > 0) |
41117
0fea133780bf
tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents:
40946
diff
changeset
|
139 |
with open(path, 'wb') as f: |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 |
f.truncate(size - 1) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 |
try: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
142 |
revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
143 |
ensure(False) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
144 |
except error.CorruptedFileError: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
145 |
pass |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
146 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
147 |
os.unlink(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
148 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
149 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 |
def testcopyfrom(): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
151 |
path = gettemppath() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
152 |
rm = revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
153 |
for i in xrange(1, 10): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
154 |
ensure( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
155 |
rm.append(genhsh(i), sidebranch=(i & 1), path=(b'%d' % (i // 3))) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
156 |
== i |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
157 |
) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
158 |
rm.flush() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
159 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
160 |
# copy rm to rm2 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
161 |
rm2 = revmap.revmap() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
162 |
rm2.copyfrom(rm) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
163 |
path2 = gettemppath() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
164 |
rm2.path = path2 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
165 |
rm2.flush() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
166 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
167 |
# two files should be the same |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
168 |
ensure(len({util.readfile(p) for p in [path, path2]}) == 1) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
169 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
170 |
os.unlink(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
171 |
os.unlink(path2) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
172 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
173 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
174 |
class fakefctx(object): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
175 |
def __init__(self, node, path=None): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
176 |
self._node = node |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
177 |
self._path = path |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
178 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
179 |
def node(self): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
180 |
return self._node |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
181 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
182 |
def path(self): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
183 |
return self._path |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
184 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
185 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
186 |
def testcontains(): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
187 |
path = gettemppath() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
188 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
189 |
rm = revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
190 |
for i in xrange(1, 5): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
191 |
ensure(rm.append(genhsh(i), sidebranch=(i & 1)) == i) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
192 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
193 |
for i in xrange(1, 5): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
194 |
ensure(((genhsh(i), None) in rm) == ((i & 1) == 0)) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
195 |
ensure((fakefctx(genhsh(i)) in rm) == ((i & 1) == 0)) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
196 |
for i in xrange(5, 10): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
197 |
ensure(fakefctx(genhsh(i)) not in rm) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
198 |
ensure((genhsh(i), None) not in rm) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
199 |
|
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
200 |
# "contains" checks paths |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
201 |
rm = revmap.revmap() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
202 |
for i in xrange(1, 5): |
41117
0fea133780bf
tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents:
40946
diff
changeset
|
203 |
ensure(rm.append(genhsh(i), path=(b'%d' % (i // 2))) == i) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
204 |
for i in xrange(1, 5): |
41117
0fea133780bf
tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents:
40946
diff
changeset
|
205 |
ensure(fakefctx(genhsh(i), path=(b'%d' % (i // 2))) in rm) |
0fea133780bf
tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents:
40946
diff
changeset
|
206 |
ensure(fakefctx(genhsh(i), path=b'a') not in rm) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
207 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
208 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
209 |
def testlastnode(): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
210 |
path = gettemppath() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
211 |
ensure(revmap.getlastnode(path) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
212 |
rm = revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
213 |
ensure(revmap.getlastnode(path) is None) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
214 |
for i in xrange(1, 10): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
215 |
hsh = genhsh(i) |
41117
0fea133780bf
tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents:
40946
diff
changeset
|
216 |
rm.append(hsh, path=(b'%d' % (i // 2)), flush=True) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
217 |
ensure(revmap.getlastnode(path) == hsh) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
218 |
rm2 = revmap.revmap(path) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
219 |
ensure(rm2.rev2hsh(rm2.maxrev) == hsh) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
220 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41117
diff
changeset
|
221 |
|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
222 |
testbasicreadwrite() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
223 |
testcorruptformat() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
224 |
testcopyfrom() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
225 |
testcontains() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
226 |
testlastnode() |