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 |
11 |
12 propertycache = util.propertycache |
12 propertycache = util.propertycache |
13 |
13 |
|
14 def _parse(data): |
|
15 """Generates (path, node, flags) tuples from a manifest text""" |
|
16 # This method does a little bit of excessive-looking |
|
17 # precondition checking. This is so that the behavior of this |
|
18 # class exactly matches its C counterpart to try and help |
|
19 # prevent surprise breakage for anyone that develops against |
|
20 # the pure version. |
|
21 if data and data[-1] != '\n': |
|
22 raise ValueError('Manifest did not end in a newline.') |
|
23 prev = None |
|
24 for l in data.splitlines(): |
|
25 if prev is not None and prev > l: |
|
26 raise ValueError('Manifest lines not in sorted order.') |
|
27 prev = l |
|
28 f, n = l.split('\0') |
|
29 if len(n) > 40: |
|
30 yield f, revlog.bin(n[:40]), n[40:] |
|
31 else: |
|
32 yield f, revlog.bin(n), '' |
|
33 |
14 class _lazymanifest(dict): |
34 class _lazymanifest(dict): |
15 """This is the pure implementation of lazymanifest. |
35 """This is the pure implementation of lazymanifest. |
16 |
36 |
17 It has not been optimized *at all* and is not lazy. |
37 It has not been optimized *at all* and is not lazy. |
18 """ |
38 """ |
19 |
39 |
20 def __init__(self, data): |
40 def __init__(self, data): |
21 # This init method does a little bit of excessive-looking |
|
22 # precondition checking. This is so that the behavior of this |
|
23 # class exactly matches its C counterpart to try and help |
|
24 # prevent surprise breakage for anyone that develops against |
|
25 # the pure version. |
|
26 if data and data[-1] != '\n': |
|
27 raise ValueError('Manifest did not end in a newline.') |
|
28 dict.__init__(self) |
41 dict.__init__(self) |
29 prev = None |
42 for f, n, fl in _parse(data): |
30 for l in data.splitlines(): |
43 self[f] = n, fl |
31 if prev is not None and prev > l: |
|
32 raise ValueError('Manifest lines not in sorted order.') |
|
33 prev = l |
|
34 f, n = l.split('\0') |
|
35 if len(n) > 40: |
|
36 self[f] = revlog.bin(n[:40]), n[40:] |
|
37 else: |
|
38 self[f] = revlog.bin(n), '' |
|
39 |
44 |
40 def __setitem__(self, k, v): |
45 def __setitem__(self, k, v): |
41 node, flag = v |
46 node, flag = v |
42 assert node is not None |
47 assert node is not None |
43 if len(node) > 21: |
48 if len(node) > 21: |