author | Simon Sapin <simon.sapin@octobus.net> |
Thu, 04 Mar 2021 13:26:53 +0100 | |
changeset 46708 | e8cd519a0a34 |
parent 45957 | 89a2afe31e82 |
child 47055 | d55b71393907 |
permissions | -rwxr-xr-x |
45849
c102b704edb5
global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43995
diff
changeset
|
1 |
#!/usr/bin/env python3 |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 |
from __future__ import absolute_import |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 |
import hashlib |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 |
import os |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 |
import random |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 |
import shutil |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 |
import stat |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
import struct |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 |
import sys |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 |
import tempfile |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 |
import unittest |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 |
import silenttestrunner |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 |
from mercurial.node import nullid |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 |
from mercurial import ( |
40767
9446d5aa0f32
py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40556
diff
changeset
|
18 |
pycompat, |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 |
ui as uimod, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
21 |
|
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 |
# Load the local remotefilelog, not the system one |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 |
sys.path[0:0] = [os.path.join(os.path.dirname(__file__), '..')] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 |
from hgext.remotefilelog import ( |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 |
basepack, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 |
historypack, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
29 |
|
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 |
class histpacktests(unittest.TestCase): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 |
def setUp(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 |
self.tempdirs = [] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 |
def tearDown(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 |
for d in self.tempdirs: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 |
shutil.rmtree(d) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 |
def makeTempDir(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 |
tempdir = tempfile.mkdtemp() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 |
self.tempdirs.append(tempdir) |
40767
9446d5aa0f32
py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40556
diff
changeset
|
41 |
return pycompat.fsencode(tempdir) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 |
def getHash(self, content): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 |
return hashlib.sha1(content).digest() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 |
def getFakeHash(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
47 |
return b''.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
48 |
pycompat.bytechr(random.randint(0, 255)) for _ in range(20) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
49 |
) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 |
def createPack(self, revisions=None): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 |
"""Creates and returns a historypack containing the specified revisions. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
53 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 |
`revisions` is a list of tuples, where each tuple contains a filanem, |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
55 |
node, p1node, p2node, and linknode. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 |
""" |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
57 |
if revisions is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
58 |
revisions = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
59 |
( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
60 |
b"filename", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
61 |
self.getFakeHash(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
62 |
nullid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
63 |
nullid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
64 |
self.getFakeHash(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
65 |
None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
66 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
67 |
] |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
68 |
|
40767
9446d5aa0f32
py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40556
diff
changeset
|
69 |
packdir = pycompat.fsencode(self.makeTempDir()) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
70 |
packer = historypack.mutablehistorypack(uimod.ui(), packdir, version=2) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
71 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
72 |
for filename, node, p1, p2, linknode, copyfrom in revisions: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
73 |
packer.add(filename, node, p1, p2, linknode, copyfrom) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
74 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 |
path = packer.close() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
76 |
return historypack.historypack(path) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
77 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
78 |
def testAddSingle(self): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45849
diff
changeset
|
79 |
"""Test putting a single entry into a pack and reading it out.""" |
41347
4ef28d7e22ae
tests: make filenames bytes for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41346
diff
changeset
|
80 |
filename = b"foo" |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
81 |
node = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
p1 = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
83 |
p2 = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
84 |
linknode = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
85 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
86 |
revisions = [(filename, node, p1, p2, linknode, None)] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
87 |
pack = self.createPack(revisions) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
88 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
89 |
actual = pack.getancestors(filename, node)[node] |
41346
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
90 |
self.assertEqual(p1, actual[0]) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
91 |
self.assertEqual(p2, actual[1]) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
92 |
self.assertEqual(linknode, actual[2]) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
93 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
94 |
def testAddMultiple(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
95 |
"""Test putting multiple unrelated revisions into a pack and reading |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
96 |
them out. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
97 |
""" |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
98 |
revisions = [] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
99 |
for i in range(10): |
41347
4ef28d7e22ae
tests: make filenames bytes for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41346
diff
changeset
|
100 |
filename = b"foo-%d" % i |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
101 |
node = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
102 |
p1 = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
103 |
p2 = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
104 |
linknode = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
105 |
revisions.append((filename, node, p1, p2, linknode, None)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
106 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
107 |
pack = self.createPack(revisions) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
108 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
109 |
for filename, node, p1, p2, linknode, copyfrom in revisions: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
110 |
actual = pack.getancestors(filename, node)[node] |
41346
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
111 |
self.assertEqual(p1, actual[0]) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
112 |
self.assertEqual(p2, actual[1]) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
113 |
self.assertEqual(linknode, actual[2]) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
114 |
self.assertEqual(copyfrom, actual[3]) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
116 |
def testAddAncestorChain(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
117 |
"""Test putting multiple revisions in into a pack and read the ancestor |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
118 |
chain. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
119 |
""" |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
120 |
revisions = [] |
40767
9446d5aa0f32
py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40556
diff
changeset
|
121 |
filename = b"foo" |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
122 |
lastnode = nullid |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
123 |
for i in range(10): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
124 |
node = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
125 |
revisions.append((filename, node, lastnode, nullid, nullid, None)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
126 |
lastnode = node |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 |
# revisions must be added in topological order, newest first |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
129 |
revisions = list(reversed(revisions)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 |
pack = self.createPack(revisions) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 |
# Test that the chain has all the entries |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 |
ancestors = pack.getancestors(revisions[0][0], revisions[0][1]) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 |
for filename, node, p1, p2, linknode, copyfrom in revisions: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 |
ap1, ap2, alinknode, acopyfrom = ancestors[node] |
41346
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
136 |
self.assertEqual(ap1, p1) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
137 |
self.assertEqual(ap2, p2) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
138 |
self.assertEqual(alinknode, linknode) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
139 |
self.assertEqual(acopyfrom, copyfrom) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 |
def testPackMany(self): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45849
diff
changeset
|
142 |
"""Pack many related and unrelated ancestors.""" |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
143 |
# Build a random pack file |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
144 |
allentries = {} |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
145 |
ancestorcounts = {} |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
146 |
revisions = [] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
147 |
random.seed(0) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
148 |
for i in range(100): |
40767
9446d5aa0f32
py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40556
diff
changeset
|
149 |
filename = b"filename-%d" % i |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 |
entries = [] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
151 |
p2 = nullid |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
152 |
linknode = nullid |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
153 |
for j in range(random.randint(1, 100)): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
154 |
node = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
155 |
p1 = nullid |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
156 |
if len(entries) > 0: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
157 |
p1 = entries[random.randint(0, len(entries) - 1)] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
158 |
entries.append(node) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
159 |
revisions.append((filename, node, p1, p2, linknode, None)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
160 |
allentries[(filename, node)] = (p1, p2, linknode) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
161 |
if p1 == nullid: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
162 |
ancestorcounts[(filename, node)] = 1 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
163 |
else: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
164 |
newcount = ancestorcounts[(filename, p1)] + 1 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
165 |
ancestorcounts[(filename, node)] = newcount |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
166 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
167 |
# Must add file entries in reverse topological order |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
168 |
revisions = list(reversed(revisions)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
169 |
pack = self.createPack(revisions) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
170 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
171 |
# Verify the pack contents |
41387
876494fd967d
cleanup: delete lots of unused local variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41348
diff
changeset
|
172 |
for (filename, node) in allentries: |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
173 |
ancestors = pack.getancestors(filename, node) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
174 |
self.assertEqual(ancestorcounts[(filename, node)], len(ancestors)) |
40768
5d1550b9a533
py3: use dict.items() instead of dict.iteritems()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40767
diff
changeset
|
175 |
for anode, (ap1, ap2, alinknode, copyfrom) in ancestors.items(): |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
176 |
ep1, ep2, elinknode = allentries[(filename, anode)] |
41346
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
177 |
self.assertEqual(ap1, ep1) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
178 |
self.assertEqual(ap2, ep2) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
179 |
self.assertEqual(alinknode, elinknode) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
180 |
self.assertEqual(copyfrom, None) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
181 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
182 |
def testGetNodeInfo(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
183 |
revisions = [] |
40767
9446d5aa0f32
py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40556
diff
changeset
|
184 |
filename = b"foo" |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
185 |
lastnode = nullid |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
186 |
for i in range(10): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
187 |
node = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
188 |
revisions.append((filename, node, lastnode, nullid, nullid, None)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
189 |
lastnode = node |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
190 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
191 |
pack = self.createPack(revisions) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
192 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
193 |
# Test that getnodeinfo returns the expected results |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
194 |
for filename, node, p1, p2, linknode, copyfrom in revisions: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
195 |
ap1, ap2, alinknode, acopyfrom = pack.getnodeinfo(filename, node) |
41346
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
196 |
self.assertEqual(ap1, p1) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
197 |
self.assertEqual(ap2, p2) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
198 |
self.assertEqual(alinknode, linknode) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
199 |
self.assertEqual(acopyfrom, copyfrom) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
200 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
201 |
def testGetMissing(self): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45849
diff
changeset
|
202 |
"""Test the getmissing() api.""" |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
203 |
revisions = [] |
40767
9446d5aa0f32
py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40556
diff
changeset
|
204 |
filename = b"foo" |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
205 |
for i in range(10): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
206 |
node = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
207 |
p1 = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
208 |
p2 = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
209 |
linknode = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
210 |
revisions.append((filename, node, p1, p2, linknode, None)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
211 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
212 |
pack = self.createPack(revisions) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
213 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
214 |
missing = pack.getmissing([(filename, revisions[0][1])]) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
215 |
self.assertFalse(missing) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
216 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
217 |
missing = pack.getmissing( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
218 |
[(filename, revisions[0][1]), (filename, revisions[1][1])] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
219 |
) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
220 |
self.assertFalse(missing) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
221 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
222 |
fakenode = self.getFakeHash() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
223 |
missing = pack.getmissing( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
224 |
[(filename, revisions[0][1]), (filename, fakenode)] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
225 |
) |
41346
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
226 |
self.assertEqual(missing, [(filename, fakenode)]) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
227 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
228 |
# Test getmissing on a non-existant filename |
41347
4ef28d7e22ae
tests: make filenames bytes for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41346
diff
changeset
|
229 |
missing = pack.getmissing([(b"bar", fakenode)]) |
4ef28d7e22ae
tests: make filenames bytes for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41346
diff
changeset
|
230 |
self.assertEqual(missing, [(b"bar", fakenode)]) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
231 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
232 |
def testAddThrows(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
233 |
pack = self.createPack() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
234 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
235 |
try: |
40767
9446d5aa0f32
py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40556
diff
changeset
|
236 |
pack.add(b'filename', nullid, nullid, nullid, nullid, None) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
237 |
self.assertTrue(False, "historypack.add should throw") |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
238 |
except RuntimeError: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
239 |
pass |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
240 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
241 |
def testBadVersionThrows(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
242 |
pack = self.createPack() |
41348
abac73eedd4d
tests: use bytes for file I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41347
diff
changeset
|
243 |
path = pack.path + b'.histpack' |
abac73eedd4d
tests: use bytes for file I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41347
diff
changeset
|
244 |
with open(path, 'rb') as f: |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
245 |
raw = f.read() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
246 |
raw = struct.pack('!B', 255) + raw[1:] |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
247 |
os.chmod(path, os.stat(path).st_mode | stat.S_IWRITE) |
41348
abac73eedd4d
tests: use bytes for file I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41347
diff
changeset
|
248 |
with open(path, 'wb+') as f: |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
249 |
f.write(raw) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
250 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
251 |
try: |
43995
37458d8b0c1e
tests: drop unused local variable assignments in remotefilelog
Matt Harbison <matt_harbison@yahoo.com>
parents:
43076
diff
changeset
|
252 |
historypack.historypack(pack.path) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
253 |
self.assertTrue(False, "bad version number should have thrown") |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
254 |
except RuntimeError: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
255 |
pass |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
256 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
257 |
def testLargePack(self): |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
258 |
"""Test creating and reading from a large pack with over X entries. |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
259 |
This causes it to use a 2^16 fanout table instead.""" |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
260 |
total = basepack.SMALLFANOUTCUTOFF + 1 |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
261 |
revisions = [] |
40783
ba706e3082bd
py3: use pycompat.xrange instead of xrange
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40768
diff
changeset
|
262 |
for i in pycompat.xrange(total): |
40767
9446d5aa0f32
py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40556
diff
changeset
|
263 |
filename = b"foo-%d" % i |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
264 |
node = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
265 |
p1 = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
266 |
p2 = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
267 |
linknode = self.getFakeHash() |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
268 |
revisions.append((filename, node, p1, p2, linknode, None)) |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
269 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
270 |
pack = self.createPack(revisions) |
41346
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
271 |
self.assertEqual(pack.params.fanoutprefix, basepack.LARGEFANOUTPREFIX) |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
272 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
273 |
for filename, node, p1, p2, linknode, copyfrom in revisions: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
274 |
actual = pack.getancestors(filename, node)[node] |
41346
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
275 |
self.assertEqual(p1, actual[0]) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
276 |
self.assertEqual(p2, actual[1]) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
277 |
self.assertEqual(linknode, actual[2]) |
724b4606528e
tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41268
diff
changeset
|
278 |
self.assertEqual(copyfrom, actual[3]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
279 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
280 |
|
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
281 |
# TODO: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
282 |
# histpack store: |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
283 |
# - repack two packs into one |
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
284 |
|
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
285 |
if __name__ == '__main__': |
41268
878084a495ef
tests: also skip remotefilelog *.py tests on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40783
diff
changeset
|
286 |
if pycompat.iswindows: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41387
diff
changeset
|
287 |
sys.exit(80) # Skip on Windows |
40545
3a333a582d7b
remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
288 |
silenttestrunner.main(__name__) |