annotate tests/test-fastannotate-revmap.py @ 52293:77b38c86915d

ci: add a small script one can run to purge older pipeline We have over ten thousands old pipeline that take a huge space and that I suspect to be the source of some slowdown in merge request. However it seems that the only way to clear them is manually and through the API, so lets do it. The script was run today.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 12 Nov 2024 12:45:23 +0100
parents 56f98406831b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
1 import os
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
2 import tempfile
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
3
39407
aa95fd0257df py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39250
diff changeset
4 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
5 pycompat,
aa95fd0257df py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39250
diff changeset
6 util,
aa95fd0257df py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39250
diff changeset
7 )
aa95fd0257df py3: alias xrange to range in tests/test-fastannotate-revmap.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39250
diff changeset
8
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
9 from hgext.fastannotate import error, revmap
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
10
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
11
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
12 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
13 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
14
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
15
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
16 def gettemppath():
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
17 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
18 os.close(fd)
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
19 os.unlink(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
20 return path
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
21
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
22
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
23 def ensure(condition):
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
24 if not condition:
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
25 raise RuntimeError('Unexpected')
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 testbasicreadwrite():
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
29 path = gettemppath()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
30
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
31 rm = revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
32 ensure(rm.maxrev == 0)
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
33 for i in range(5):
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
34 ensure(rm.rev2hsh(i) is None)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
35 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
36
41117
0fea133780bf tests: add lots of b prefix goo to test-fastannotate-revmap.py
Augie Fackler <raf@durin42.com>
parents: 40946
diff changeset
37 paths = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
38 b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
39 b'a',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
40 None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
41 b'b',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
42 b'b',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
43 b'c',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
44 b'c',
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'a',
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'a',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
49 b'a',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
50 ]
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
51 for i in range(1, 5):
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
52 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
53
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
54 ensure(rm.maxrev == 4)
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
55 for i in range(1, 5):
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
56 ensure(rm.hsh2rev(genhsh(i)) == i)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
57 ensure(rm.rev2hsh(i) == genhsh(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 # re-load and verify
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
60 rm.flush()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
61 rm = revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
62 ensure(rm.maxrev == 4)
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
63 for i in range(1, 5):
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
64 ensure(rm.hsh2rev(genhsh(i)) == i)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
65 ensure(rm.rev2hsh(i) == genhsh(i))
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
66 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
67
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
68 # append without calling save() explicitly
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
69 for i in range(5, 12):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
70 ensure(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
71 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
72 == i
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
73 )
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
74
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
75 # re-load and verify
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
76 rm = revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
77 ensure(rm.maxrev == 11)
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
78 for i in range(1, 12):
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
79 ensure(rm.hsh2rev(genhsh(i)) == i)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
80 ensure(rm.rev2hsh(i) == genhsh(i))
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
81 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
82 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
83
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
84 os.unlink(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
85
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
86 # missing keys
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
87 ensure(rm.rev2hsh(12) is None)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
88 ensure(rm.rev2hsh(0) is None)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
89 ensure(rm.rev2hsh(-1) is None)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
90 ensure(rm.rev2flag(12) is None)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
91 ensure(rm.rev2path(12) is None)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
92 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
93
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
94 # illformed hash (not 20 bytes)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
95 try:
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
96 rm.append(b'\0')
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
97 ensure(False)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
98 except Exception:
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
99 pass
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
100
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
101
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
102 def testcorruptformat():
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
103 path = gettemppath()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
104
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
105 # 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
106 with open(path, 'wb') as f:
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
107 f.write(b'NOT A VALID HEADER')
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
108 try:
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
109 revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
110 ensure(False)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
111 except error.CorruptedFileError:
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
112 pass
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
113
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
114 # rewrite the file
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
115 os.unlink(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
116 rm = revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
117 rm.append(genhsh(0), flush=True)
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 rm = revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
120 ensure(rm.maxrev == 1)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
121
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
122 # corrupt the file by appending a byte
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
123 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
124 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
125 f.write(b'\xff')
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
126 try:
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
127 revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
128 ensure(False)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
129 except error.CorruptedFileError:
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
130 pass
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
131
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
132 # 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
133 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
134 with open(path, 'wb') as f:
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
135 f.truncate(size - 1)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
136 try:
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
137 revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
138 ensure(False)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
139 except error.CorruptedFileError:
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
140 pass
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
141
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
142 os.unlink(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
143
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
144
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
145 def testcopyfrom():
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
146 path = gettemppath()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
147 rm = revmap.revmap(path)
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
148 for i in range(1, 10):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
149 ensure(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
150 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
151 == i
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
152 )
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
153 rm.flush()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
154
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
155 # copy rm to rm2
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
156 rm2 = revmap.revmap()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
157 rm2.copyfrom(rm)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
158 path2 = gettemppath()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
159 rm2.path = path2
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
160 rm2.flush()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
161
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
162 # 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
163 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
164
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
165 os.unlink(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
166 os.unlink(path2)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
167
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
168
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
169 class fakefctx:
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
170 def __init__(self, node, path=None):
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
171 self._node = node
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
172 self._path = path
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
173
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
174 def node(self):
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
175 return self._node
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
176
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
177 def path(self):
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
178 return self._path
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
179
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
180
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
181 def testcontains():
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
182 path = gettemppath()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
183
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
184 rm = revmap.revmap(path)
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
185 for i in range(1, 5):
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
186 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
187
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
188 for i in range(1, 5):
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
189 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
190 ensure((fakefctx(genhsh(i)) in rm) == ((i & 1) == 0))
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
191 for i in range(5, 10):
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
192 ensure(fakefctx(genhsh(i)) not in rm)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
193 ensure((genhsh(i), None) not in rm)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
194
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
195 # "contains" checks paths
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
196 rm = revmap.revmap()
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
197 for i in range(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
198 ensure(rm.append(genhsh(i), path=(b'%d' % (i // 2))) == i)
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
199 for i in range(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
200 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
201 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
202
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
203
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
204 def testlastnode():
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
205 path = gettemppath()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
206 ensure(revmap.getlastnode(path) is None)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
207 rm = revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
208 ensure(revmap.getlastnode(path) is None)
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
209 for i in range(1, 10):
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
210 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
211 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
212 ensure(revmap.getlastnode(path) == hsh)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
213 rm2 = revmap.revmap(path)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
214 ensure(rm2.rev2hsh(rm2.maxrev) == hsh)
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
215
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41117
diff changeset
216
39210
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
217 testbasicreadwrite()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
218 testcorruptformat()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
219 testcopyfrom()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
220 testcontains()
1ddb296e0dee fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
221 testlastnode()