Show More
@@ -8,6 +8,7 b'' | |||||
8 | from i18n import _ |
|
8 | from i18n import _ | |
9 | import mdiff, parsers, error, revlog, util, scmutil |
|
9 | import mdiff, parsers, error, revlog, util, scmutil | |
10 | import array, struct |
|
10 | import array, struct | |
|
11 | import os | |||
11 |
|
12 | |||
12 | propertycache = util.propertycache |
|
13 | propertycache = util.propertycache | |
13 |
|
14 | |||
@@ -58,9 +59,15 b' def _parse(data):' | |||||
58 | else: |
|
59 | else: | |
59 | return iter(_parsev1(data)) |
|
60 | return iter(_parsev1(data)) | |
60 |
|
61 | |||
61 | def _text(it): |
|
62 | def _text(it, usemanifestv2): | |
62 | """Given an iterator over (path, node, flags) tuples, returns a manifest |
|
63 | """Given an iterator over (path, node, flags) tuples, returns a manifest | |
63 | text""" |
|
64 | text""" | |
|
65 | if usemanifestv2: | |||
|
66 | return _textv2(it) | |||
|
67 | else: | |||
|
68 | return _textv1(it) | |||
|
69 | ||||
|
70 | def _textv1(it): | |||
64 | files = [] |
|
71 | files = [] | |
65 | lines = [] |
|
72 | lines = [] | |
66 | _hex = revlog.hex |
|
73 | _hex = revlog.hex | |
@@ -73,6 +80,19 b' def _text(it):' | |||||
73 | _checkforbidden(files) |
|
80 | _checkforbidden(files) | |
74 | return ''.join(lines) |
|
81 | return ''.join(lines) | |
75 |
|
82 | |||
|
83 | def _textv2(it): | |||
|
84 | files = [] | |||
|
85 | lines = ['\0\n'] | |||
|
86 | prevf = '' | |||
|
87 | for f, n, fl in it: | |||
|
88 | files.append(f) | |||
|
89 | stem = os.path.commonprefix([prevf, f]) | |||
|
90 | stemlen = min(len(stem), 255) | |||
|
91 | lines.append("%c%s\0%s\n%s\n" % (stemlen, f[stemlen:], fl, n)) | |||
|
92 | prevf = f | |||
|
93 | _checkforbidden(files) | |||
|
94 | return ''.join(lines) | |||
|
95 | ||||
76 | class _lazymanifest(dict): |
|
96 | class _lazymanifest(dict): | |
77 | """This is the pure implementation of lazymanifest. |
|
97 | """This is the pure implementation of lazymanifest. | |
78 |
|
98 | |||
@@ -134,7 +154,7 b' class _lazymanifest(dict):' | |||||
134 |
|
154 | |||
135 | def text(self): |
|
155 | def text(self): | |
136 | """Get the full data of this manifest as a bytestring.""" |
|
156 | """Get the full data of this manifest as a bytestring.""" | |
137 | return _text(self.iterentries()) |
|
157 | return _textv1(self.iterentries()) | |
138 |
|
158 | |||
139 | try: |
|
159 | try: | |
140 | _lazymanifest = parsers.lazymanifest |
|
160 | _lazymanifest = parsers.lazymanifest | |
@@ -259,8 +279,12 b' class manifestdict(object):' | |||||
259 | def iteritems(self): |
|
279 | def iteritems(self): | |
260 | return (x[:2] for x in self._lm.iterentries()) |
|
280 | return (x[:2] for x in self._lm.iterentries()) | |
261 |
|
281 | |||
262 | def text(self): |
|
282 | def text(self, usemanifestv2=False): | |
263 | return self._lm.text() |
|
283 | if usemanifestv2: | |
|
284 | return _textv2(self._lm.iterentries()) | |||
|
285 | else: | |||
|
286 | # use (probably) native version for v1 | |||
|
287 | return self._lm.text() | |||
264 |
|
288 | |||
265 | def fastdelta(self, base, changes): |
|
289 | def fastdelta(self, base, changes): | |
266 | """Given a base manifest text as an array.array and a list of changes |
|
290 | """Given a base manifest text as an array.array and a list of changes | |
@@ -621,10 +645,11 b' class treemanifest(object):' | |||||
621 | _diff(self, m2) |
|
645 | _diff(self, m2) | |
622 | return result |
|
646 | return result | |
623 |
|
647 | |||
624 | def text(self): |
|
648 | def text(self, usemanifestv2=False): | |
625 | """Get the full data of this manifest as a bytestring.""" |
|
649 | """Get the full data of this manifest as a bytestring.""" | |
626 | flags = self.flags |
|
650 | flags = self.flags | |
627 | return _text((f, self[f], flags(f)) for f in self.keys()) |
|
651 | return _text(((f, self[f], flags(f)) for f in self.keys()), | |
|
652 | usemanifestv2) | |||
628 |
|
653 | |||
629 | class manifest(revlog.revlog): |
|
654 | class manifest(revlog.revlog): | |
630 | def __init__(self, opener): |
|
655 | def __init__(self, opener): | |
@@ -720,7 +745,7 b' class manifest(revlog.revlog):' | |||||
720 | # just encode a fulltext of the manifest and pass that |
|
745 | # just encode a fulltext of the manifest and pass that | |
721 | # through to the revlog layer, and let it handle the delta |
|
746 | # through to the revlog layer, and let it handle the delta | |
722 | # process. |
|
747 | # process. | |
723 | text = m.text() |
|
748 | text = m.text(self._usemanifestv2) | |
724 | arraytext = array.array('c', text) |
|
749 | arraytext = array.array('c', text) | |
725 | cachedelta = None |
|
750 | cachedelta = None | |
726 |
|
751 |
@@ -146,6 +146,12 b' class testmanifest(unittest.TestCase):' | |||||
146 | self.assertIn('bar/qux/foz.py', m) |
|
146 | self.assertIn('bar/qux/foz.py', m) | |
147 | self.assertIn(256 * 'x' + '/x', m) |
|
147 | self.assertIn(256 * 'x' + '/x', m) | |
148 | self.assertIn(256 * 'x' + '/y', m) |
|
148 | self.assertIn(256 * 'x' + '/y', m) | |
|
149 | self.assertEqual(A_STEM_COMPRESSED_MANIFEST, m.text(usemanifestv2=True)) | |||
|
150 | ||||
|
151 | def testTextV2(self): | |||
|
152 | m1 = parsemanifest(A_SHORT_MANIFEST) | |||
|
153 | v2text = m1.text(usemanifestv2=True) | |||
|
154 | self.assertEqual(A_SHORT_MANIFEST_V2, v2text) | |||
149 |
|
155 | |||
150 | def testSetItem(self): |
|
156 | def testSetItem(self): | |
151 | want = BIN_HASH_1 |
|
157 | want = BIN_HASH_1 |
@@ -23,9 +23,9 b" Check that 'hg verify', which uses manif" | |||||
23 | checking files |
|
23 | checking files | |
24 | 3 files, 2 changesets, 4 total revisions |
|
24 | 3 files, 2 changesets, 4 total revisions | |
25 |
|
25 | |||
26 |
|
|
26 | Check that manifest revlog is smaller than for v1 | |
27 |
|
27 | |||
28 | $ hg debugindex -m |
|
28 | $ hg debugindex -m | |
29 | rev offset length base linkrev nodeid p1 p2 |
|
29 | rev offset length base linkrev nodeid p1 p2 | |
30 |
0 0 1 |
|
30 | 0 0 81 0 0 57361477c778 000000000000 000000000000 | |
31 |
1 1 |
|
31 | 1 81 33 0 1 aeaab5a2ef74 57361477c778 000000000000 |
General Comments 0
You need to be logged in to leave comments.
Login now