Mercurial > hg
annotate mercurial/manifest.py @ 2689:489c3bacce96
MANIFEST.in fixes
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Thu, 27 Jul 2006 12:33:33 +0200 |
parents | fe1689273f84 |
children | 0b50a580be36 |
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 # |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> |
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 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
13 class manifest(revlog): |
2142
8a1e2a9c7013
Replaced 0 with REVLOGV0 where this meaning is used.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2072
diff
changeset
|
14 def __init__(self, opener, defversion=REVLOGV0): |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
15 self.mapcache = None |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
16 self.listcache = None |
2072 | 17 revlog.__init__(self, opener, "00manifest.i", "00manifest.d", |
18 defversion) | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
19 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
20 def read(self, node): |
313 | 21 if node == nullid: return {} # don't upset local cache |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
22 if self.mapcache and self.mapcache[0] == node: |
561 | 23 return self.mapcache[1] |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
24 text = self.revision(node) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
25 map = {} |
276 | 26 flag = {} |
1534 | 27 self.listcache = array.array('c', text) |
28 lines = text.splitlines(1) | |
29 for l in lines: | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
30 (f, n) = l.split('\0') |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
31 map[f] = bin(n[:40]) |
276 | 32 flag[f] = (n[40:-1] == "x") |
33 self.mapcache = (node, map, flag) | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
34 return map |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
35 |
276 | 36 def readflags(self, node): |
313 | 37 if node == nullid: return {} # don't upset local cache |
358
9f4077d7ef6f
[PATCH] manifest.readflags performance buglet
mpm@selenic.com
parents:
350
diff
changeset
|
38 if not self.mapcache or self.mapcache[0] != node: |
276 | 39 self.read(node) |
40 return self.mapcache[2] | |
41 | |
1534 | 42 def diff(self, a, b): |
43 return mdiff.textdiff(str(a), str(b)) | |
44 | |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
45 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
|
46 '''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
|
47 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 # 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
|
71 # 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
|
72 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
|
73 else: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
74 # 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 # 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
|
80 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
|
81 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
|
82 else: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
83 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
|
84 |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
85 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
|
86 '''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
|
87 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
|
88 if self.mapcache and node == self.mapcache[0]: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
89 return self.mapcache[1].get(f), self.mapcache[2].get(f) |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 |
741 | 98 def add(self, map, flags, transaction, link, p1=None, p2=None, |
99 changed=None): | |
644 | 100 # apply the changes collected during the bisect loop to our addlist |
1534 | 101 # return a delta suitable for addrevision |
102 def addlistdelta(addlist, x): | |
103 # start from the bottom up | |
644 | 104 # so changes to the offsets don't mess things up. |
1534 | 105 i = len(x) |
644 | 106 while i > 0: |
107 i -= 1 | |
1534 | 108 start = x[i][0] |
109 end = x[i][1] | |
110 if x[i][2]: | |
111 addlist[start:end] = array.array('c', x[i][2]) | |
644 | 112 else: |
113 del addlist[start:end] | |
1534 | 114 return "".join([struct.pack(">lll", d[0], d[1], len(d[2])) + d[2] \ |
115 for d in x ]) | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
116 |
644 | 117 # if we're using the listcache, make sure it is valid and |
118 # parented by the same node we're diffing against | |
741 | 119 if not changed or not self.listcache or not p1 or \ |
120 self.mapcache[0] != p1: | |
644 | 121 files = map.keys() |
122 files.sort() | |
123 | |
1651 | 124 # if this is changed to support newlines in filenames, |
125 # be sure to check the templates/ dir again (especially *-raw.tmpl) | |
1534 | 126 text = ["%s\000%s%s\n" % |
644 | 127 (f, hex(map[f]), flags[f] and "x" or '') |
128 for f in files] | |
1534 | 129 self.listcache = array.array('c', "".join(text)) |
644 | 130 cachedelta = None |
131 else: | |
1534 | 132 addlist = self.listcache |
644 | 133 |
134 # combine the changed lists into one list for sorting | |
135 work = [[x, 0] for x in changed[0]] | |
136 work[len(work):] = [[x, 1] for x in changed[1]] | |
137 work.sort() | |
138 | |
139 delta = [] | |
1534 | 140 dstart = None |
141 dend = None | |
142 dline = [""] | |
143 start = 0 | |
144 # zero copy representation of addlist as a buffer | |
145 addbuf = buffer(addlist) | |
644 | 146 |
1534 | 147 # start with a readonly loop that finds the offset of |
148 # each line and creates the deltas | |
644 | 149 for w in work: |
150 f = w[0] | |
741 | 151 # 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
|
152 start, end = self._search(addbuf, f, start) |
644 | 153 if w[1] == 0: |
741 | 154 l = "%s\000%s%s\n" % (f, hex(map[f]), |
155 flags[f] and "x" or '') | |
644 | 156 else: |
1534 | 157 l = "" |
158 if start == end and w[1] == 1: | |
159 # item we want to delete was not found, error out | |
160 raise AssertionError( | |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
161 _("failed to remove %s from manifest\n") % f) |
1534 | 162 if dstart != None and dstart <= start and dend >= start: |
163 if dend < end: | |
164 dend = end | |
165 if l: | |
166 dline.append(l) | |
644 | 167 else: |
1534 | 168 if dstart != None: |
169 delta.append([dstart, dend, "".join(dline)]) | |
170 dstart = start | |
171 dend = end | |
172 dline = [l] | |
644 | 173 |
1534 | 174 if dstart != None: |
175 delta.append([dstart, dend, "".join(dline)]) | |
176 # apply the delta to the addlist, and get a delta for addrevision | |
177 cachedelta = addlistdelta(addlist, delta) | |
644 | 178 |
1534 | 179 # the delta is only valid if we've been processing the tip revision |
180 if self.mapcache[0] != self.tip(): | |
181 cachedelta = None | |
182 self.listcache = addlist | |
183 | |
184 n = self.addrevision(buffer(self.listcache), transaction, link, p1, \ | |
185 p2, cachedelta) | |
302 | 186 self.mapcache = (n, map, flags) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
187 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
188 return n |