Mercurial > hg
annotate mercurial/manifest.py @ 24298:49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
The _lazymanifest type(s) behave very much like a sorted dict with
filenames as keys and (nodeid, flags) as values. It therefore seems
surprising that its __iter__ generates 3-tuples of (path, nodeid,
flags). Let's make it match dict's behavior of generating the keys
instead, and add a new iterentries method for the 3-tuples. With this
change, the "x" in "if x in lm" and "for x in lm" now have the same
type (a filename string).
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 12 Mar 2015 18:18:29 -0700 |
parents | 0178f500d61e |
children | f263814c72ac |
rev | line source |
---|---|
1089 | 1 # manifest.py - manifest revision class for mercurial |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 # |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
3891 | 8 from i18n import _ |
22965
b697fa74b475
manifest: for diff(), only iterate over files, not flags
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22964
diff
changeset
|
9 import mdiff, parsers, error, revlog, util |
8312
b87a50b7125c
separate import lines from mercurial and general python modules
Simon Heimberg <simohe@besonet.ch>
parents:
8225
diff
changeset
|
10 import array, struct |
79 | 11 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
12 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
13 class _lazymanifest(dict): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
14 """This is the pure implementation of lazymanifest. |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
15 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
16 It has not been optimized *at all* and is not lazy. |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
17 """ |
24223
b4df0d0c49e7
manifest: move parsing functions up in file
Augie Fackler <augie@google.com>
parents:
24215
diff
changeset
|
18 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
19 def __init__(self, data): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
20 # This init method does a little bit of excessive-looking |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
21 # precondition checking. This is so that the behavior of this |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
22 # class exactly matches its C counterpart to try and help |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
23 # prevent surprise breakage for anyone that develops against |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
24 # the pure version. |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
25 if data and data[-1] != '\n': |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
26 raise ValueError('Manifest did not end in a newline.') |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
27 dict.__init__(self) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
28 prev = None |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
29 for l in data.splitlines(): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
30 if prev is not None and prev > l: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
31 raise ValueError('Manifest lines not in sorted order.') |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
32 prev = l |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
33 f, n = l.split('\0') |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
34 if len(n) > 40: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
35 self[f] = revlog.bin(n[:40]), n[40:] |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
36 else: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
37 self[f] = revlog.bin(n), '' |
24224
d71837d06597
manifest: do parsing inside manifestdict contstructor
Augie Fackler <augie@google.com>
parents:
24223
diff
changeset
|
38 |
23594
6f53629ad273
manifest: disallow setting the node id of an entry to None
Augie Fackler <augie@google.com>
parents:
22966
diff
changeset
|
39 def __setitem__(self, k, v): |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
40 node, flag = v |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
41 assert node is not None |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
42 if len(node) > 21: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
43 node = node[:21] # match c implementation behavior |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
44 dict.__setitem__(self, k, (node, flag)) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
45 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
46 def __iter__(self): |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
47 return iter(sorted(dict.keys(self))) |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
48 |
24297
0178f500d61e
lazymanifest: fix pure hg iterkeys()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
49 def iterkeys(self): |
0178f500d61e
lazymanifest: fix pure hg iterkeys()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
50 return iter(sorted(dict.keys(self))) |
0178f500d61e
lazymanifest: fix pure hg iterkeys()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
51 |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
52 def iterentries(self): |
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
53 return ((f, e[0], e[1]) for f, e in sorted(self.iteritems())) |
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
54 |
2831 | 55 def copy(self): |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
56 c = _lazymanifest('') |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
57 c.update(self) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
58 return c |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
59 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
60 def diff(self, m2, clean=False): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
61 '''Finds changes between the current manifest and m2.''' |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
62 diff = {} |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
63 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
64 for fn, e1 in self.iteritems(): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
65 if fn not in m2: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
66 diff[fn] = e1, (None, '') |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
67 else: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
68 e2 = m2[fn] |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
69 if e1 != e2: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
70 diff[fn] = e1, e2 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
71 elif clean: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
72 diff[fn] = None |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
73 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
74 for fn, e2 in m2.iteritems(): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
75 if fn not in self: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
76 diff[fn] = (None, ''), e2 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
77 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
78 return diff |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
79 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
80 def filtercopy(self, filterfn): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
81 c = _lazymanifest('') |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
82 for f, n, fl in self.iterentries(): |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
83 if filterfn(f): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
84 c[f] = n, fl |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
85 return c |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
86 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
87 def text(self): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
88 """Get the full data of this manifest as a bytestring.""" |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
89 fl = sorted(self.iterentries()) |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
90 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
91 _hex = revlog.hex |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
92 # if this is changed to support newlines in filenames, |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
93 # be sure to check the templates/ dir again (especially *-raw.tmpl) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
94 return ''.join("%s\0%s%s\n" % ( |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
95 f, _hex(n[:20]), flag) for f, n, flag in fl) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
96 |
24226
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
97 try: |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
98 _lazymanifest = parsers.lazymanifest |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
99 except AttributeError: |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
100 pass |
b992769dd1be
manifest: use custom C implementation of lazymanifest
Augie Fackler <augie@google.com>
parents:
24225
diff
changeset
|
101 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
102 class manifestdict(object): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
103 def __init__(self, data=''): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
104 self._lm = _lazymanifest(data) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
105 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
106 def __getitem__(self, key): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
107 return self._lm[key][0] |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
108 |
24277
22d560fe1516
manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24226
diff
changeset
|
109 def find(self, key): |
22d560fe1516
manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24226
diff
changeset
|
110 return self._lm[key] |
22d560fe1516
manifest: don't let find() look inside manifestdict
Martin von Zweigbergk <martinvonz@google.com>
parents:
24226
diff
changeset
|
111 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
112 def __len__(self): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
113 return len(self._lm) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
114 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
115 def __setitem__(self, key, node): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
116 self._lm[key] = node, self.flags(key, '') |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
117 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
118 def __contains__(self, key): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
119 return key in self._lm |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
120 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
121 def __delitem__(self, key): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
122 del self._lm[key] |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
123 |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
124 def __iter__(self): |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
125 return self._lm.__iter__() |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
126 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
127 def iterkeys(self): |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
128 return self._lm.iterkeys() |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
129 |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
130 def keys(self): |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24292
diff
changeset
|
131 return list(self.iterkeys()) |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
132 |
21879
090dcaaf3fff
manifestdict: add a new method to intersect with a set of files
Siddharth Agarwal <sid0@fb.com>
parents:
20075
diff
changeset
|
133 def intersectfiles(self, files): |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
134 '''make a new lazymanifest with the intersection of self with files |
21879
090dcaaf3fff
manifestdict: add a new method to intersect with a set of files
Siddharth Agarwal <sid0@fb.com>
parents:
20075
diff
changeset
|
135 |
090dcaaf3fff
manifestdict: add a new method to intersect with a set of files
Siddharth Agarwal <sid0@fb.com>
parents:
20075
diff
changeset
|
136 The algorithm assumes that files is much smaller than self.''' |
090dcaaf3fff
manifestdict: add a new method to intersect with a set of files
Siddharth Agarwal <sid0@fb.com>
parents:
20075
diff
changeset
|
137 ret = manifestdict() |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
138 lm = self._lm |
21879
090dcaaf3fff
manifestdict: add a new method to intersect with a set of files
Siddharth Agarwal <sid0@fb.com>
parents:
20075
diff
changeset
|
139 for fn in files: |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
140 if fn in lm: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
141 ret._lm[fn] = self._lm[fn] |
21879
090dcaaf3fff
manifestdict: add a new method to intersect with a set of files
Siddharth Agarwal <sid0@fb.com>
parents:
20075
diff
changeset
|
142 return ret |
22964
2793ecb1522d
manifest: repurpose flagsdiff() into (node-and-flag)diff()
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22943
diff
changeset
|
143 |
24184
cd66080ef6d4
copies: move code into new manifestdict.filesnotin() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24147
diff
changeset
|
144 def filesnotin(self, m2): |
cd66080ef6d4
copies: move code into new manifestdict.filesnotin() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24147
diff
changeset
|
145 '''Set of files in this manifest that are not in the other''' |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
146 files = set(self) |
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
147 files.difference_update(m2) |
24184
cd66080ef6d4
copies: move code into new manifestdict.filesnotin() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24147
diff
changeset
|
148 return files |
cd66080ef6d4
copies: move code into new manifestdict.filesnotin() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24147
diff
changeset
|
149 |
23305
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
150 def matches(self, match): |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
151 '''generate a new manifest filtered by the match argument''' |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
152 if match.always(): |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
153 return self.copy() |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
154 |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
155 files = match.files() |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
156 if (match.matchfn == match.exact or |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
157 (not match.anypats() and util.all(fn in self for fn in files))): |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
158 return self.intersectfiles(files) |
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
159 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
160 lm = manifestdict('') |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
161 lm._lm = self._lm.filtercopy(match) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
162 return lm |
23305
0cc283f44655
manifest: add matches() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
22966
diff
changeset
|
163 |
23756
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
164 def diff(self, m2, clean=False): |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
165 '''Finds changes between the current manifest and m2. |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
166 |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
167 Args: |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
168 m2: the manifest to which this manifest should be compared. |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
169 clean: if true, include files unchanged between these manifests |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
170 with a None value in the returned dictionary. |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
171 |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
172 The result is returned as a dict with filename as key and |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
173 values of the form ((n1,fl1),(n2,fl2)), where n1/n2 is the |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
174 nodeid in the current/other manifest and fl1/fl2 is the flag |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
175 in the current/other manifest. Where the file does not exist, |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
176 the nodeid will be None and the flags will be the empty |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
177 string. |
829f640b5540
manifest: add optional recording of clean entries to diff
Augie Fackler <augie@google.com>
parents:
23602
diff
changeset
|
178 ''' |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
179 return self._lm.diff(m2._lm, clean) |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
180 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
181 def setflag(self, key, flag): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
182 self._lm[key] = self[key], flag |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
183 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
184 def get(self, key, default=None): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
185 try: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
186 return self._lm[key][0] |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
187 except KeyError: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
188 return default |
22965
b697fa74b475
manifest: for diff(), only iterate over files, not flags
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22964
diff
changeset
|
189 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
190 def flags(self, key, default=''): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
191 try: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
192 return self._lm[key][1] |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
193 except KeyError: |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
194 return default |
22965
b697fa74b475
manifest: for diff(), only iterate over files, not flags
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22964
diff
changeset
|
195 |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
196 def copy(self): |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
197 c = manifestdict('') |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
198 c._lm = self._lm.copy() |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
199 return c |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
200 |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
201 def iteritems(self): |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24297
diff
changeset
|
202 return (x[:2] for x in self._lm.iterentries()) |
2831 | 203 |
22929
bf69cb09a6c9
manifest: move manifestdict-to-text encoding to manifest class
Augie Fackler <raf@durin42.com>
parents:
22788
diff
changeset
|
204 def text(self): |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
205 return self._lm.text() |
22408
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
206 |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
207 def fastdelta(self, base, changes): |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
208 """Given a base manifest text as an array.array and a list of changes |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
209 relative to that text, compute a delta that can be used by revlog. |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
210 """ |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
211 delta = [] |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
212 dstart = None |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
213 dend = None |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
214 dline = [""] |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
215 start = 0 |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
216 # zero copy representation of base as a buffer |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
217 addbuf = util.buffer(base) |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
218 |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
219 # start with a readonly loop that finds the offset of |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
220 # each line and creates the deltas |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
221 for f, todelete in changes: |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
222 # bs will either be the index of the item or the insert point |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
223 start, end = _msearch(addbuf, f, start) |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
224 if not todelete: |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
225 h, fl = self._lm[f] |
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
226 l = "%s\0%s%s\n" % (f, revlog.hex(h), fl) |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
227 else: |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
228 if start == end: |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
229 # item we want to delete was not found, error out |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
230 raise AssertionError( |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
231 _("failed to remove %s from manifest") % f) |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
232 l = "" |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
233 if dstart is not None and dstart <= start and dend >= start: |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
234 if dend < end: |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
235 dend = end |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
236 if l: |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
237 dline.append(l) |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
238 else: |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
239 if dstart is not None: |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
240 delta.append([dstart, dend, "".join(dline)]) |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
241 dstart = start |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
242 dend = end |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
243 dline = [l] |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
244 |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
245 if dstart is not None: |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
246 delta.append([dstart, dend, "".join(dline)]) |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
247 # apply the delta to the base, and get a delta for addrevision |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
248 deltatext, arraytext = _addlistdelta(base, delta) |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
249 return arraytext, deltatext |
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
250 |
22930
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
251 def _msearch(m, s, lo=0, hi=None): |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
252 '''return a tuple (start, end) that says where to find s within m. |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
253 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
254 If the string is found m[start:end] are the line containing |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
255 that string. If start == end the string was not found and |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
256 they indicate the proper sorted insertion point. |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
257 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
258 m should be a buffer or a string |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
259 s is a string''' |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
260 def advance(i, c): |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
261 while i < lenm and m[i] != c: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
262 i += 1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
263 return i |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
264 if not s: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
265 return (lo, lo) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
266 lenm = len(m) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
267 if not hi: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
268 hi = lenm |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
269 while lo < hi: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
270 mid = (lo + hi) // 2 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
271 start = mid |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
272 while start > 0 and m[start - 1] != '\n': |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
273 start -= 1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
274 end = advance(start, '\0') |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
275 if m[start:end] < s: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
276 # we know that after the null there are 40 bytes of sha1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
277 # this translates to the bisect lo = mid + 1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
278 lo = advance(end + 40, '\n') + 1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
279 else: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
280 # this translates to the bisect hi = mid |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
281 hi = start |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
282 end = advance(lo, '\0') |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
283 found = m[lo:end] |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
284 if s == found: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
285 # we know that after the null there are 40 bytes of sha1 |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
286 end = advance(end + 40, '\n') |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
287 return (lo, end + 1) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
288 else: |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
289 return (lo, lo) |
1acb81d10eaf
manifest: move _search to module level and rename to _msearch
Augie Fackler <raf@durin42.com>
parents:
22929
diff
changeset
|
290 |
22415
65ec6c5c0fb3
manifest: mark addlistdelta and checkforbidden as module-private
Augie Fackler <raf@durin42.com>
parents:
22409
diff
changeset
|
291 def _checkforbidden(l): |
22408
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
292 """Check filenames for illegal characters.""" |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
293 for f in l: |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
294 if '\n' in f or '\r' in f: |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
295 raise error.RevlogError( |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
296 _("'\\n' and '\\r' disallowed in filenames: %r") % f) |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
297 |
dc97e04c12ad
manifest: move checkforbidden to module-level
Augie Fackler <raf@durin42.com>
parents:
21879
diff
changeset
|
298 |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
299 # apply the changes collected during the bisect loop to our addlist |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
300 # return a delta suitable for addrevision |
22415
65ec6c5c0fb3
manifest: mark addlistdelta and checkforbidden as module-private
Augie Fackler <raf@durin42.com>
parents:
22409
diff
changeset
|
301 def _addlistdelta(addlist, x): |
22409
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
302 # for large addlist arrays, building a new array is cheaper |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
303 # than repeatedly modifying the existing one |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
304 currentposition = 0 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
305 newaddlist = array.array('c') |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
306 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
307 for start, end, content in x: |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
308 newaddlist += addlist[currentposition:start] |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
309 if content: |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
310 newaddlist += array.array('c', content) |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
311 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
312 currentposition = end |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
313 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
314 newaddlist += addlist[currentposition:] |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
315 |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
316 deltatext = "".join(struct.pack(">lll", start, end, len(content)) |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
317 + content for start, end, content in x) |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
318 return deltatext, newaddlist |
8f09b785b59b
manifest: move addlistdelta to module-level
Augie Fackler <raf@durin42.com>
parents:
22408
diff
changeset
|
319 |
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
320 class manifest(revlog.revlog): |
4258
b11a2fb59cf5
revlog: simplify revlog version handling
Matt Mackall <mpm@selenic.com>
parents:
4257
diff
changeset
|
321 def __init__(self, opener): |
24033
ed5e8a9598ce
manifest: make lru size configurable
Durham Goode <durham@fb.com>
parents:
23758
diff
changeset
|
322 # During normal operations, we expect to deal with not more than four |
ed5e8a9598ce
manifest: make lru size configurable
Durham Goode <durham@fb.com>
parents:
23758
diff
changeset
|
323 # revs at a time (such as during commit --amend). When rebasing large |
ed5e8a9598ce
manifest: make lru size configurable
Durham Goode <durham@fb.com>
parents:
23758
diff
changeset
|
324 # stacks of commits, the number can go up, hence the config knob below. |
ed5e8a9598ce
manifest: make lru size configurable
Durham Goode <durham@fb.com>
parents:
23758
diff
changeset
|
325 cachesize = 4 |
ed5e8a9598ce
manifest: make lru size configurable
Durham Goode <durham@fb.com>
parents:
23758
diff
changeset
|
326 opts = getattr(opener, 'options', None) |
ed5e8a9598ce
manifest: make lru size configurable
Durham Goode <durham@fb.com>
parents:
23758
diff
changeset
|
327 if opts is not None: |
ed5e8a9598ce
manifest: make lru size configurable
Durham Goode <durham@fb.com>
parents:
23758
diff
changeset
|
328 cachesize = opts.get('manifestcachesize', cachesize) |
ed5e8a9598ce
manifest: make lru size configurable
Durham Goode <durham@fb.com>
parents:
23758
diff
changeset
|
329 self._mancache = util.lrucachedict(cachesize) |
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
330 revlog.revlog.__init__(self, opener, "00manifest.i") |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
331 |
3196
f3b939444c72
Abstract manifest block parsing.
Brendan Cully <brendan@kublai.com>
parents:
3148
diff
changeset
|
332 def readdelta(self, node): |
7362
6db4a2ccef3a
revlog: remove delta function
Matt Mackall <mpm@selenic.com>
parents:
6765
diff
changeset
|
333 r = self.rev(node) |
24224
d71837d06597
manifest: do parsing inside manifestdict contstructor
Augie Fackler <augie@google.com>
parents:
24223
diff
changeset
|
334 d = mdiff.patchtext(self.revdiff(self.deltaparent(r), r)) |
d71837d06597
manifest: do parsing inside manifestdict contstructor
Augie Fackler <augie@google.com>
parents:
24223
diff
changeset
|
335 return manifestdict(d) |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3196
diff
changeset
|
336 |
13711
ed913fd7837b
manifest: add readfast method
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
337 def readfast(self, node): |
ed913fd7837b
manifest: add readfast method
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
338 '''use the faster of readdelta or read''' |
ed913fd7837b
manifest: add readfast method
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
339 r = self.rev(node) |
14208
d62d597b8974
revlog: compute correct deltaparent in the deltaparent function
Sune Foldager <cryo@cyanite.org>
parents:
13711
diff
changeset
|
340 deltaparent = self.deltaparent(r) |
d62d597b8974
revlog: compute correct deltaparent in the deltaparent function
Sune Foldager <cryo@cyanite.org>
parents:
13711
diff
changeset
|
341 if deltaparent != revlog.nullrev and deltaparent in self.parentrevs(r): |
13711
ed913fd7837b
manifest: add readfast method
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
342 return self.readdelta(node) |
ed913fd7837b
manifest: add readfast method
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
343 return self.read(node) |
ed913fd7837b
manifest: add readfast method
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
344 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
345 def read(self, node): |
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
346 if node == revlog.nullid: |
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
347 return manifestdict() # don't upset local cache |
18604
a1141f04e368
manifest: use a size 3 LRU cache to store parsed manifests
Siddharth Agarwal <sid0@fb.com>
parents:
17983
diff
changeset
|
348 if node in self._mancache: |
a1141f04e368
manifest: use a size 3 LRU cache to store parsed manifests
Siddharth Agarwal <sid0@fb.com>
parents:
17983
diff
changeset
|
349 return self._mancache[node][0] |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
350 text = self.revision(node) |
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
351 arraytext = array.array('c', text) |
24224
d71837d06597
manifest: do parsing inside manifestdict contstructor
Augie Fackler <augie@google.com>
parents:
24223
diff
changeset
|
352 m = manifestdict(text) |
24147
ba4fcd80079d
manifest: rename 'mf', 'map', and 'mapping' to 'm'
Martin von Zweigbergk <martinvonz@google.com>
parents:
24146
diff
changeset
|
353 self._mancache[node] = (m, arraytext) |
ba4fcd80079d
manifest: rename 'mf', 'map', and 'mapping' to 'm'
Martin von Zweigbergk <martinvonz@google.com>
parents:
24146
diff
changeset
|
354 return m |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
355 |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
356 def find(self, node, f): |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
357 '''look up entry for a single file efficiently. |
4159
a896607d3ec3
fix manifest.find
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3891
diff
changeset
|
358 return (node, flags) pair if found, (None, None) if not.''' |
24292
b7add2ebef9e
manifest: rewrite find(node, f) in terms of read(node)
Martin von Zweigbergk <martinvonz@google.com>
parents:
24277
diff
changeset
|
359 m = self.read(node) |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
360 try: |
24292
b7add2ebef9e
manifest: rewrite find(node, f) in terms of read(node)
Martin von Zweigbergk <martinvonz@google.com>
parents:
24277
diff
changeset
|
361 return m.find(f) |
24225
3e5c4af69808
manifest: split manifestdict into high-level and low-level logic
Augie Fackler <augie@google.com>
parents:
24224
diff
changeset
|
362 except KeyError: |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
363 return None, None |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
364 |
24147
ba4fcd80079d
manifest: rename 'mf', 'map', and 'mapping' to 'm'
Martin von Zweigbergk <martinvonz@google.com>
parents:
24146
diff
changeset
|
365 def add(self, m, transaction, link, p1, p2, added, removed): |
22788
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
366 if p1 in self._mancache: |
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
367 # If our first parent is in the manifest cache, we can |
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
368 # compute a delta here using properties we know about the |
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
369 # manifest up-front, which may save time later for the |
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
370 # revlog layer. |
644 | 371 |
22415
65ec6c5c0fb3
manifest: mark addlistdelta and checkforbidden as module-private
Augie Fackler <raf@durin42.com>
parents:
22409
diff
changeset
|
372 _checkforbidden(added) |
644 | 373 # combine the changed lists into one list for sorting |
9415
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
374 work = [(x, False) for x in added] |
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
375 work.extend((x, True) for x in removed) |
17428
72803c8edaa4
avoid using abbreviations that look like spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17426
diff
changeset
|
376 # this could use heapq.merge() (from Python 2.6+) or equivalent |
9415
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
377 # since the lists are already sorted |
644 | 378 work.sort() |
379 | |
24147
ba4fcd80079d
manifest: rename 'mf', 'map', and 'mapping' to 'm'
Martin von Zweigbergk <martinvonz@google.com>
parents:
24146
diff
changeset
|
380 arraytext, deltatext = m.fastdelta(self._mancache[p1][1], work) |
22931
48c0b101a9de
manifest: add fastdelta method to manifestdict
Augie Fackler <raf@durin42.com>
parents:
22930
diff
changeset
|
381 cachedelta = self.rev(p1), deltatext |
15657
d976b1ef6760
util: don't mess with builtins to emulate buffer()
Matt Mackall <mpm@selenic.com>
parents:
14632
diff
changeset
|
382 text = util.buffer(arraytext) |
22788
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
383 else: |
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
384 # The first parent manifest isn't already loaded, so we'll |
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
385 # just encode a fulltext of the manifest and pass that |
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
386 # through to the revlog layer, and let it handle the delta |
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
387 # process. |
24147
ba4fcd80079d
manifest: rename 'mf', 'map', and 'mapping' to 'm'
Martin von Zweigbergk <martinvonz@google.com>
parents:
24146
diff
changeset
|
388 text = m.text() |
22788
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
389 arraytext = array.array('c', text) |
160efd225b24
manifest: rearrange add() method and add comments for clarity
Augie Fackler <raf@durin42.com>
parents:
22787
diff
changeset
|
390 cachedelta = None |
1534 | 391 |
9420
d0db168136dc
manifest/revlog: do not let the revlog cache mutable objects
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9416
diff
changeset
|
392 n = self.addrevision(text, transaction, link, p1, p2, cachedelta) |
24147
ba4fcd80079d
manifest: rename 'mf', 'map', and 'mapping' to 'm'
Martin von Zweigbergk <martinvonz@google.com>
parents:
24146
diff
changeset
|
393 self._mancache[n] = (m, arraytext) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
394 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
395 return n |