Show More
@@ -10,8 +10,11 b' from mercurial import match as matchmod' | |||||
10 | EMTPY_MANIFEST = '' |
|
10 | EMTPY_MANIFEST = '' | |
11 |
|
11 | |||
12 | HASH_1 = '1' * 40 |
|
12 | HASH_1 = '1' * 40 | |
|
13 | BIN_HASH_1 = binascii.unhexlify(HASH_1) | |||
13 | HASH_2 = 'f' * 40 |
|
14 | HASH_2 = 'f' * 40 | |
|
15 | BIN_HASH_2 = binascii.unhexlify(HASH_2) | |||
14 | HASH_3 = '1234567890abcdef0987654321deadbeef0fcafe' |
|
16 | HASH_3 = '1234567890abcdef0987654321deadbeef0fcafe' | |
|
17 | BIN_HASH_3 = binascii.unhexlify(HASH_3) | |||
15 | A_SHORT_MANIFEST = ( |
|
18 | A_SHORT_MANIFEST = ( | |
16 | 'bar/baz/qux.py\0%(hash2)s%(flag2)s\n' |
|
19 | 'bar/baz/qux.py\0%(hash2)s%(flag2)s\n' | |
17 | 'foo\0%(hash1)s%(flag1)s\n' |
|
20 | 'foo\0%(hash1)s%(flag1)s\n' | |
@@ -77,14 +80,14 b' class testmanifest(unittest.TestCase):' | |||||
77 | def testManifest(self): |
|
80 | def testManifest(self): | |
78 | m = parsemanifest(A_SHORT_MANIFEST) |
|
81 | m = parsemanifest(A_SHORT_MANIFEST) | |
79 | self.assertEqual(['bar/baz/qux.py', 'foo'], list(m)) |
|
82 | self.assertEqual(['bar/baz/qux.py', 'foo'], list(m)) | |
80 |
self.assertEqual( |
|
83 | self.assertEqual(BIN_HASH_2, m['bar/baz/qux.py']) | |
81 | self.assertEqual('l', m.flags('bar/baz/qux.py')) |
|
84 | self.assertEqual('l', m.flags('bar/baz/qux.py')) | |
82 |
self.assertEqual( |
|
85 | self.assertEqual(BIN_HASH_1, m['foo']) | |
83 | self.assertEqual('', m.flags('foo')) |
|
86 | self.assertEqual('', m.flags('foo')) | |
84 | self.assertRaises(KeyError, lambda : m['wat']) |
|
87 | self.assertRaises(KeyError, lambda : m['wat']) | |
85 |
|
88 | |||
86 | def testSetItem(self): |
|
89 | def testSetItem(self): | |
87 |
want = |
|
90 | want = BIN_HASH_1 | |
88 |
|
91 | |||
89 | m = parsemanifest(EMTPY_MANIFEST) |
|
92 | m = parsemanifest(EMTPY_MANIFEST) | |
90 | m['a'] = want |
|
93 | m['a'] = want | |
@@ -103,14 +106,14 b' class testmanifest(unittest.TestCase):' | |||||
103 |
|
106 | |||
104 | m = parsemanifest(EMTPY_MANIFEST) |
|
107 | m = parsemanifest(EMTPY_MANIFEST) | |
105 | # first add a file; a file-less flag makes no sense |
|
108 | # first add a file; a file-less flag makes no sense | |
106 |
m['a'] = |
|
109 | m['a'] = BIN_HASH_1 | |
107 | m.setflag('a', want) |
|
110 | m.setflag('a', want) | |
108 | self.assertEqual(want, m.flags('a')) |
|
111 | self.assertEqual(want, m.flags('a')) | |
109 | self.assertEqual('a\0' + HASH_1 + want + '\n', m.text()) |
|
112 | self.assertEqual('a\0' + HASH_1 + want + '\n', m.text()) | |
110 |
|
113 | |||
111 | m = parsemanifest(A_SHORT_MANIFEST) |
|
114 | m = parsemanifest(A_SHORT_MANIFEST) | |
112 | # first add a file; a file-less flag makes no sense |
|
115 | # first add a file; a file-less flag makes no sense | |
113 |
m['a'] = |
|
116 | m['a'] = BIN_HASH_1 | |
114 | m.setflag('a', want) |
|
117 | m.setflag('a', want) | |
115 | self.assertEqual(want, m.flags('a')) |
|
118 | self.assertEqual(want, m.flags('a')) | |
116 | self.assertEqual('a\0' + HASH_1 + want + '\n' + A_SHORT_MANIFEST, |
|
119 | self.assertEqual('a\0' + HASH_1 + want + '\n' + A_SHORT_MANIFEST, | |
@@ -118,7 +121,7 b' class testmanifest(unittest.TestCase):' | |||||
118 |
|
121 | |||
119 | def testCopy(self): |
|
122 | def testCopy(self): | |
120 | m = parsemanifest(A_SHORT_MANIFEST) |
|
123 | m = parsemanifest(A_SHORT_MANIFEST) | |
121 |
m['a'] = |
|
124 | m['a'] = BIN_HASH_1 | |
122 | m2 = m.copy() |
|
125 | m2 = m.copy() | |
123 | del m |
|
126 | del m | |
124 | del m2 # make sure we don't double free() anything |
|
127 | del m2 # make sure we don't double free() anything | |
@@ -152,8 +155,8 b' class testmanifest(unittest.TestCase):' | |||||
152 | # Merge code wants to set 21-byte fake hashes at times |
|
155 | # Merge code wants to set 21-byte fake hashes at times | |
153 | m['foo'] = want |
|
156 | m['foo'] = want | |
154 | self.assertEqual(want, m['foo']) |
|
157 | self.assertEqual(want, m['foo']) | |
155 |
self.assertEqual([('bar/baz/qux.py', |
|
158 | self.assertEqual([('bar/baz/qux.py', BIN_HASH_2), | |
156 |
('foo', |
|
159 | ('foo', BIN_HASH_1 + 'a')], | |
157 | list(m.iteritems())) |
|
160 | list(m.iteritems())) | |
158 | # Sometimes it even tries a 22-byte fake hash, but we can |
|
161 | # Sometimes it even tries a 22-byte fake hash, but we can | |
159 | # return 21 and it'll work out |
|
162 | # return 21 and it'll work out | |
@@ -167,7 +170,7 b' class testmanifest(unittest.TestCase):' | |||||
167 | m2 = m.copy() |
|
170 | m2 = m.copy() | |
168 | self.assertEqual(want, m2['foo']) |
|
171 | self.assertEqual(want, m2['foo']) | |
169 | # suffix with iteration |
|
172 | # suffix with iteration | |
170 |
self.assertEqual([('bar/baz/qux.py', |
|
173 | self.assertEqual([('bar/baz/qux.py', BIN_HASH_2), | |
171 | ('foo', want)], |
|
174 | ('foo', want)], | |
172 | list(m.iteritems())) |
|
175 | list(m.iteritems())) | |
173 |
|
176 | |||
@@ -204,32 +207,32 b' class testmanifest(unittest.TestCase):' | |||||
204 | A_SHORT_MANIFEST.replace(HASH_1, HASH_3 + 'x') + addl) |
|
207 | A_SHORT_MANIFEST.replace(HASH_1, HASH_3 + 'x') + addl) | |
205 | right = parsemanifest(A_SHORT_MANIFEST + addr) |
|
208 | right = parsemanifest(A_SHORT_MANIFEST + addr) | |
206 | want = { |
|
209 | want = { | |
207 |
'foo': (( |
|
210 | 'foo': ((BIN_HASH_3, 'x'), | |
208 |
( |
|
211 | (BIN_HASH_1, '')), | |
209 |
'z-only-in-left': (( |
|
212 | 'z-only-in-left': ((BIN_HASH_1, ''), MISSING), | |
210 |
'z-only-in-right': (MISSING, ( |
|
213 | 'z-only-in-right': (MISSING, (BIN_HASH_2, 'x')), | |
211 | } |
|
214 | } | |
212 | self.assertEqual(want, left.diff(right)) |
|
215 | self.assertEqual(want, left.diff(right)) | |
213 |
|
216 | |||
214 | want = { |
|
217 | want = { | |
215 |
'bar/baz/qux.py': (MISSING, ( |
|
218 | 'bar/baz/qux.py': (MISSING, (BIN_HASH_2, 'l')), | |
216 |
'foo': (MISSING, ( |
|
219 | 'foo': (MISSING, (BIN_HASH_3, 'x')), | |
217 |
'z-only-in-left': (MISSING, ( |
|
220 | 'z-only-in-left': (MISSING, (BIN_HASH_1, '')), | |
218 | } |
|
221 | } | |
219 | self.assertEqual(want, parsemanifest(EMTPY_MANIFEST).diff(left)) |
|
222 | self.assertEqual(want, parsemanifest(EMTPY_MANIFEST).diff(left)) | |
220 |
|
223 | |||
221 | want = { |
|
224 | want = { | |
222 |
'bar/baz/qux.py': (( |
|
225 | 'bar/baz/qux.py': ((BIN_HASH_2, 'l'), MISSING), | |
223 |
'foo': (( |
|
226 | 'foo': ((BIN_HASH_3, 'x'), MISSING), | |
224 |
'z-only-in-left': (( |
|
227 | 'z-only-in-left': ((BIN_HASH_1, ''), MISSING), | |
225 | } |
|
228 | } | |
226 | self.assertEqual(want, left.diff(parsemanifest(EMTPY_MANIFEST))) |
|
229 | self.assertEqual(want, left.diff(parsemanifest(EMTPY_MANIFEST))) | |
227 | copy = right.copy() |
|
230 | copy = right.copy() | |
228 | del copy['z-only-in-right'] |
|
231 | del copy['z-only-in-right'] | |
229 | del right['foo'] |
|
232 | del right['foo'] | |
230 | want = { |
|
233 | want = { | |
231 |
'foo': (MISSING, ( |
|
234 | 'foo': (MISSING, (BIN_HASH_1, '')), | |
232 |
'z-only-in-right': (( |
|
235 | 'z-only-in-right': ((BIN_HASH_2, 'x'), MISSING), | |
233 | } |
|
236 | } | |
234 | self.assertEqual(want, right.diff(copy)) |
|
237 | self.assertEqual(want, right.diff(copy)) | |
235 |
|
238 | |||
@@ -237,16 +240,16 b' class testmanifest(unittest.TestCase):' | |||||
237 | pruned = short.copy() |
|
240 | pruned = short.copy() | |
238 | del pruned['foo'] |
|
241 | del pruned['foo'] | |
239 | want = { |
|
242 | want = { | |
240 |
'foo': (( |
|
243 | 'foo': ((BIN_HASH_1, ''), MISSING), | |
241 | } |
|
244 | } | |
242 | self.assertEqual(want, short.diff(pruned)) |
|
245 | self.assertEqual(want, short.diff(pruned)) | |
243 | want = { |
|
246 | want = { | |
244 |
'foo': (MISSING, ( |
|
247 | 'foo': (MISSING, (BIN_HASH_1, '')), | |
245 | } |
|
248 | } | |
246 | self.assertEqual(want, pruned.diff(short)) |
|
249 | self.assertEqual(want, pruned.diff(short)) | |
247 | want = { |
|
250 | want = { | |
248 | 'bar/baz/qux.py': None, |
|
251 | 'bar/baz/qux.py': None, | |
249 |
'foo': (MISSING, ( |
|
252 | 'foo': (MISSING, (BIN_HASH_1, '')), | |
250 | } |
|
253 | } | |
251 | self.assertEqual(want, pruned.diff(short, True)) |
|
254 | self.assertEqual(want, pruned.diff(short, True)) | |
252 |
|
255 |
General Comments 0
You need to be logged in to leave comments.
Login now