Mercurial > hg
comparison tests/test-manifest.py @ 45118:d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
In the manifest line, flags are put directly after the hash, so the
parser has been guessing the presence of flags based on the length of
the hash. Replace this assumption by an enumeration of the valid flags
and removing them from the hash first as they are distinct input values.
Consistently handle the expected 256bit length of the SHA1-replacement
in the pure Python parser. Check that setting flags will use one of the
blessed values.
Extend write logic in the C version to handle 256bit hashes as well.
Verify that hashes always have exactly the expected length. Since
1070df141718 we should no longer depend on the old extra-byte hack.
Differential Revision: https://phab.mercurial-scm.org/D8679
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Mon, 06 Jul 2020 03:43:32 +0200 |
parents | 9d569983668b |
children | 89a2afe31e82 |
comparison
equal
deleted
inserted
replaced
45117:b1e51ef4e536 | 45118:d0ef8c1dddd4 |
---|---|
154 self.assertEqual(b'l', m.flags(b'bar/baz/qux.py')) | 154 self.assertEqual(b'l', m.flags(b'bar/baz/qux.py')) |
155 self.assertEqual(b'', m.flags(b'beta')) | 155 self.assertEqual(b'', m.flags(b'beta')) |
156 with self.assertRaises(KeyError): | 156 with self.assertRaises(KeyError): |
157 m[b'foo'] | 157 m[b'foo'] |
158 | 158 |
159 def testSetGetNodeSuffix(self): | |
160 clean = self.parsemanifest(A_SHORT_MANIFEST) | |
161 m = self.parsemanifest(A_SHORT_MANIFEST) | |
162 h = m[b'foo'] | |
163 f = m.flags(b'foo') | |
164 want = h + b'a' | |
165 # Merge code wants to set 21-byte fake hashes at times | |
166 m[b'foo'] = want | |
167 self.assertEqual(want, m[b'foo']) | |
168 self.assertEqual( | |
169 [(b'bar/baz/qux.py', BIN_HASH_2), (b'foo', BIN_HASH_1 + b'a')], | |
170 list(m.items()), | |
171 ) | |
172 # Sometimes it even tries a 22-byte fake hash, but we can | |
173 # return 21 and it'll work out | |
174 m[b'foo'] = want + b'+' | |
175 self.assertEqual(want, m[b'foo']) | |
176 # make sure the suffix survives a copy | |
177 match = matchmod.match(util.localpath(b'/repo'), b'', [b're:foo']) | |
178 m2 = m._matches(match) | |
179 self.assertEqual(want, m2[b'foo']) | |
180 self.assertEqual(1, len(m2)) | |
181 m2 = m.copy() | |
182 self.assertEqual(want, m2[b'foo']) | |
183 # suffix with iteration | |
184 self.assertEqual( | |
185 [(b'bar/baz/qux.py', BIN_HASH_2), (b'foo', want)], list(m.items()) | |
186 ) | |
187 | |
188 # shows up in diff | |
189 self.assertEqual({b'foo': ((want, f), (h, b''))}, m.diff(clean)) | |
190 self.assertEqual({b'foo': ((h, b''), (want, f))}, clean.diff(m)) | |
191 | |
192 def testMatchException(self): | 159 def testMatchException(self): |
193 m = self.parsemanifest(A_SHORT_MANIFEST) | 160 m = self.parsemanifest(A_SHORT_MANIFEST) |
194 match = matchmod.match(util.localpath(b'/repo'), b'', [b're:.*']) | 161 match = matchmod.match(util.localpath(b'/repo'), b'', [b're:.*']) |
195 | 162 |
196 def filt(path): | 163 def filt(path): |