Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/manifest.py @ 3163:a9e75b371315
merge: move partial filtering out of manifest merge
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 26 Sep 2006 16:21:52 -0500 |
parents | adb246ce6736 |
children | f3b939444c72 |
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 # |
2858 | 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
4 # |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
262 | 8 from revlog import * |
1400
cf9a1233738a
i18n first part: make '_' available for files who need it
Benoit Boissinot <benoit.boissinot@ens-lyon.org
parents:
1098
diff
changeset
|
9 from i18n import gettext as _ |
262 | 10 from demandload import * |
2470
fe1689273f84
use demandload more.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2320
diff
changeset
|
11 demandload(globals(), "array bisect struct") |
79 | 12 |
2847
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2846
diff
changeset
|
13 class manifestdict(dict): |
2856
18cf5349a361
Fix some bugs introduced during the manifest refactoring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2853
diff
changeset
|
14 def __init__(self, mapping=None, flags=None): |
18cf5349a361
Fix some bugs introduced during the manifest refactoring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2853
diff
changeset
|
15 if mapping is None: mapping = {} |
18cf5349a361
Fix some bugs introduced during the manifest refactoring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2853
diff
changeset
|
16 if flags is None: flags = {} |
2843 | 17 dict.__init__(self, mapping) |
2851
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2847
diff
changeset
|
18 self._flags = flags |
2846
35af2e56f15a
manifestflags: eliminate remaining users of direct dict access
Matt Mackall <mpm@selenic.com>
parents:
2845
diff
changeset
|
19 def flags(self, f): |
2851
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2847
diff
changeset
|
20 return self._flags.get(f, "") |
2843 | 21 def execf(self, f): |
22 "test for executable in manifest flags" | |
2847
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2846
diff
changeset
|
23 return "x" in self.flags(f) |
2843 | 24 def linkf(self, f): |
25 "test for symlink in manifest flags" | |
2847
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2846
diff
changeset
|
26 return "l" in self.flags(f) |
2851
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2847
diff
changeset
|
27 def rawset(self, f, entry): |
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2847
diff
changeset
|
28 self[f] = bin(entry[:40]) |
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2847
diff
changeset
|
29 fl = entry[40:-1] |
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2847
diff
changeset
|
30 if fl: self._flags[f] = fl |
2843 | 31 def set(self, f, execf=False, linkf=False): |
2856
18cf5349a361
Fix some bugs introduced during the manifest refactoring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2853
diff
changeset
|
32 if linkf: self._flags[f] = "l" |
18cf5349a361
Fix some bugs introduced during the manifest refactoring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2853
diff
changeset
|
33 elif execf: self._flags[f] = "x" |
18cf5349a361
Fix some bugs introduced during the manifest refactoring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2853
diff
changeset
|
34 else: self._flags[f] = "" |
2843 | 35 def copy(self): |
2851
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2847
diff
changeset
|
36 return manifestdict(dict.copy(self), dict.copy(self._flags)) |
2843 | 37 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
38 class manifest(revlog): |
2142
8a1e2a9c7013
Replaced 0 with REVLOGV0 where this meaning is used.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2072
diff
changeset
|
39 def __init__(self, opener, defversion=REVLOGV0): |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
40 self.mapcache = None |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
41 self.listcache = None |
2072 | 42 revlog.__init__(self, opener, "00manifest.i", "00manifest.d", |
43 defversion) | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
44 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
45 def read(self, node): |
2847
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2846
diff
changeset
|
46 if node == nullid: return manifestdict() # don't upset local cache |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
47 if self.mapcache and self.mapcache[0] == node: |
561 | 48 return self.mapcache[1] |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
49 text = self.revision(node) |
1534 | 50 self.listcache = array.array('c', text) |
51 lines = text.splitlines(1) | |
2847
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2846
diff
changeset
|
52 mapping = manifestdict() |
1534 | 53 for l in lines: |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
54 (f, n) = l.split('\0') |
2851
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2847
diff
changeset
|
55 mapping.rawset(f, n) |
2847
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2846
diff
changeset
|
56 self.mapcache = (node, mapping) |
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2846
diff
changeset
|
57 return mapping |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
58 |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
59 def _search(self, m, s, lo=0, hi=None): |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
60 '''return a tuple (start, end) that says where to find s within m. |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
61 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
62 If the string is found m[start:end] are the line containing |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
63 that string. If start == end the string was not found and |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
64 they indicate the proper sorted insertion point. This was |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
65 taken from bisect_left, and modified to find line start/end as |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
66 it goes along. |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
67 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
68 m should be a buffer or a string |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
69 s is a string''' |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
70 def advance(i, c): |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
71 while i < lenm and m[i] != c: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
72 i += 1 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
73 return i |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
74 lenm = len(m) |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
75 if not hi: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
76 hi = lenm |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
77 while lo < hi: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
78 mid = (lo + hi) // 2 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
79 start = mid |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
80 while start > 0 and m[start-1] != '\n': |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
81 start -= 1 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
82 end = advance(start, '\0') |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
83 if m[start:end] < s: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
84 # we know that after the null there are 40 bytes of sha1 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
85 # this translates to the bisect lo = mid + 1 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
86 lo = advance(end + 40, '\n') + 1 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
87 else: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
88 # this translates to the bisect hi = mid |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
89 hi = start |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
90 end = advance(lo, '\0') |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
91 found = m[lo:end] |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
92 if cmp(s, found) == 0: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
93 # we know that after the null there are 40 bytes of sha1 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
94 end = advance(end + 40, '\n') |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
95 return (lo, end+1) |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
96 else: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
97 return (lo, lo) |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
98 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
99 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
|
100 '''look up entry for a single file efficiently. |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
101 return (node, flag) pair if found, (None, None) if not.''' |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
102 if self.mapcache and node == self.mapcache[0]: |
2847
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2846
diff
changeset
|
103 return self.mapcache[1].get(f), self.mapcache[1].flags(f) |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
104 text = self.revision(node) |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
105 start, end = self._search(text, f) |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
106 if start == end: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
107 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
|
108 l = text[start:end] |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
109 f, n = l.split('\0') |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
110 return bin(n[:40]), n[40:-1] == 'x' |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
111 |
2853 | 112 def add(self, map, transaction, link, p1=None, p2=None, |
741 | 113 changed=None): |
644 | 114 # apply the changes collected during the bisect loop to our addlist |
1534 | 115 # return a delta suitable for addrevision |
116 def addlistdelta(addlist, x): | |
117 # start from the bottom up | |
644 | 118 # so changes to the offsets don't mess things up. |
1534 | 119 i = len(x) |
644 | 120 while i > 0: |
121 i -= 1 | |
1534 | 122 start = x[i][0] |
123 end = x[i][1] | |
124 if x[i][2]: | |
125 addlist[start:end] = array.array('c', x[i][2]) | |
644 | 126 else: |
127 del addlist[start:end] | |
1534 | 128 return "".join([struct.pack(">lll", d[0], d[1], len(d[2])) + d[2] \ |
129 for d in x ]) | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
130 |
644 | 131 # if we're using the listcache, make sure it is valid and |
132 # parented by the same node we're diffing against | |
741 | 133 if not changed or not self.listcache or not p1 or \ |
134 self.mapcache[0] != p1: | |
644 | 135 files = map.keys() |
136 files.sort() | |
137 | |
1651 | 138 # if this is changed to support newlines in filenames, |
139 # be sure to check the templates/ dir again (especially *-raw.tmpl) | |
2853 | 140 text = ["%s\000%s%s\n" % (f, hex(map[f]), map.flags(f)) for f in files] |
1534 | 141 self.listcache = array.array('c', "".join(text)) |
644 | 142 cachedelta = None |
143 else: | |
1534 | 144 addlist = self.listcache |
644 | 145 |
146 # combine the changed lists into one list for sorting | |
147 work = [[x, 0] for x in changed[0]] | |
148 work[len(work):] = [[x, 1] for x in changed[1]] | |
149 work.sort() | |
150 | |
151 delta = [] | |
1534 | 152 dstart = None |
153 dend = None | |
154 dline = [""] | |
155 start = 0 | |
156 # zero copy representation of addlist as a buffer | |
157 addbuf = buffer(addlist) | |
644 | 158 |
1534 | 159 # start with a readonly loop that finds the offset of |
160 # each line and creates the deltas | |
644 | 161 for w in work: |
162 f = w[0] | |
741 | 163 # bs will either be the index of the item or the insert point |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
164 start, end = self._search(addbuf, f, start) |
644 | 165 if w[1] == 0: |
2853 | 166 l = "%s\000%s%s\n" % (f, hex(map[f]), map.flags(f)) |
644 | 167 else: |
1534 | 168 l = "" |
169 if start == end and w[1] == 1: | |
170 # item we want to delete was not found, error out | |
171 raise AssertionError( | |
3148
adb246ce6736
fix newline in error message
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3140
diff
changeset
|
172 _("failed to remove %s from manifest") % f) |
1534 | 173 if dstart != None and dstart <= start and dend >= start: |
174 if dend < end: | |
175 dend = end | |
176 if l: | |
177 dline.append(l) | |
644 | 178 else: |
1534 | 179 if dstart != None: |
180 delta.append([dstart, dend, "".join(dline)]) | |
181 dstart = start | |
182 dend = end | |
183 dline = [l] | |
644 | 184 |
1534 | 185 if dstart != None: |
186 delta.append([dstart, dend, "".join(dline)]) | |
187 # apply the delta to the addlist, and get a delta for addrevision | |
188 cachedelta = addlistdelta(addlist, delta) | |
644 | 189 |
1534 | 190 # the delta is only valid if we've been processing the tip revision |
191 if self.mapcache[0] != self.tip(): | |
192 cachedelta = None | |
193 self.listcache = addlist | |
194 | |
195 n = self.addrevision(buffer(self.listcache), transaction, link, p1, \ | |
196 p2, cachedelta) | |
2847
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2846
diff
changeset
|
197 self.mapcache = (n, map) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
198 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
199 return n |