Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/manifest.py @ 1450:199bb2b4ed4a
Add Benoit to CONTRIBUTORS
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 25 Oct 2005 16:31:38 -0700 |
parents | 9d2c2e6b32b5 |
children | 54e4b187f69c |
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 |
1089 | 8 import sys, struct |
262 | 9 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
|
10 from i18n import gettext as _ |
262 | 11 from demandload import * |
1089 | 12 demandload(globals(), "bisect") |
79 | 13 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
14 class manifest(revlog): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
15 def __init__(self, opener): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
16 self.mapcache = None |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
17 self.listcache = None |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
18 self.addlist = None |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
19 revlog.__init__(self, opener, "00manifest.i", "00manifest.d") |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
20 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
21 def read(self, node): |
313 | 22 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
|
23 if self.mapcache and self.mapcache[0] == node: |
561 | 24 return self.mapcache[1] |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
25 text = self.revision(node) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
26 map = {} |
276 | 27 flag = {} |
25
daa724b27300
Fix corruption from manifest.listcache optimization
mpm@selenic.com
parents:
20
diff
changeset
|
28 self.listcache = (text, text.splitlines(1)) |
daa724b27300
Fix corruption from manifest.listcache optimization
mpm@selenic.com
parents:
20
diff
changeset
|
29 for l in self.listcache[1]: |
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 | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
42 def diff(self, a, b): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
43 # this is sneaky, as we're not actually using a and b |
140 | 44 if self.listcache and self.addlist and self.listcache[0] == a: |
98 | 45 d = mdiff.diff(self.listcache[1], self.addlist, 1) |
46 if mdiff.patch(a, d) != b: | |
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
|
47 raise AssertionError(_("sortdiff failed!")) |
98 | 48 return d |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
49 else: |
44 | 50 return mdiff.textdiff(a, b) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
51 |
741 | 52 def add(self, map, flags, transaction, link, p1=None, p2=None, |
53 changed=None): | |
644 | 54 # directly generate the mdiff delta from the data collected during |
55 # the bisect loop below | |
56 def gendelta(delta): | |
57 i = 0 | |
58 result = [] | |
59 while i < len(delta): | |
60 start = delta[i][2] | |
61 end = delta[i][3] | |
62 l = delta[i][4] | |
63 if l == None: | |
64 l = "" | |
741 | 65 while i < len(delta) - 1 and start <= delta[i+1][2] \ |
66 and end >= delta[i+1][2]: | |
644 | 67 if delta[i+1][3] > end: |
68 end = delta[i+1][3] | |
69 if delta[i+1][4]: | |
70 l += delta[i+1][4] | |
71 i += 1 | |
72 result.append(struct.pack(">lll", start, end, len(l)) + l) | |
73 i += 1 | |
74 return result | |
75 | |
76 # apply the changes collected during the bisect loop to our addlist | |
77 def addlistdelta(addlist, delta): | |
78 # apply the deltas to the addlist. start from the bottom up | |
79 # so changes to the offsets don't mess things up. | |
80 i = len(delta) | |
81 while i > 0: | |
82 i -= 1 | |
83 start = delta[i][0] | |
84 end = delta[i][1] | |
85 if delta[i][4]: | |
86 addlist[start:end] = [delta[i][4]] | |
87 else: | |
88 del addlist[start:end] | |
89 return addlist | |
90 | |
91 # calculate the byte offset of the start of each line in the | |
92 # manifest | |
93 def calcoffsets(addlist): | |
94 offsets = [0] * (len(addlist) + 1) | |
95 offset = 0 | |
96 i = 0 | |
97 while i < len(addlist): | |
98 offsets[i] = offset | |
99 offset += len(addlist[i]) | |
100 i += 1 | |
101 offsets[i] = offset | |
102 return offsets | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
103 |
644 | 104 # if we're using the listcache, make sure it is valid and |
105 # parented by the same node we're diffing against | |
741 | 106 if not changed or not self.listcache or not p1 or \ |
107 self.mapcache[0] != p1: | |
644 | 108 files = map.keys() |
109 files.sort() | |
110 | |
111 self.addlist = ["%s\000%s%s\n" % | |
112 (f, hex(map[f]), flags[f] and "x" or '') | |
113 for f in files] | |
114 cachedelta = None | |
115 else: | |
116 addlist = self.listcache[1] | |
117 | |
118 # find the starting offset for each line in the add list | |
119 offsets = calcoffsets(addlist) | |
120 | |
121 # combine the changed lists into one list for sorting | |
122 work = [[x, 0] for x in changed[0]] | |
123 work[len(work):] = [[x, 1] for x in changed[1]] | |
124 work.sort() | |
125 | |
126 delta = [] | |
127 bs = 0 | |
128 | |
129 for w in work: | |
130 f = w[0] | |
741 | 131 # bs will either be the index of the item or the insert point |
644 | 132 bs = bisect.bisect(addlist, f, bs) |
133 if bs < len(addlist): | |
134 fn = addlist[bs][:addlist[bs].index('\0')] | |
135 else: | |
136 fn = None | |
137 if w[1] == 0: | |
741 | 138 l = "%s\000%s%s\n" % (f, hex(map[f]), |
139 flags[f] and "x" or '') | |
644 | 140 else: |
141 l = None | |
142 start = bs | |
143 if fn != f: | |
144 # item not found, insert a new one | |
659 | 145 end = bs |
644 | 146 if w[1] == 1: |
1098
50a0a36dd48a
manifest: convert sys.stderr bits to AssertionError
mpm@selenic.com
parents:
1089
diff
changeset
|
147 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
|
148 _("failed to remove %s from manifest\n") % f) |
644 | 149 else: |
150 # item is found, replace/delete the existing line | |
151 end = bs + 1 | |
152 delta.append([start, end, offsets[start], offsets[end], l]) | |
153 | |
154 self.addlist = addlistdelta(addlist, delta) | |
155 if self.mapcache[0] == self.tip(): | |
156 cachedelta = "".join(gendelta(delta)) | |
157 else: | |
158 cachedelta = None | |
159 | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
160 text = "".join(self.addlist) |
644 | 161 if cachedelta and mdiff.patch(self.listcache[0], cachedelta) != text: |
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
|
162 raise AssertionError(_("manifest delta failure\n")) |
644 | 163 n = self.addrevision(text, transaction, link, p1, p2, cachedelta) |
302 | 164 self.mapcache = (n, map, flags) |
25
daa724b27300
Fix corruption from manifest.listcache optimization
mpm@selenic.com
parents:
20
diff
changeset
|
165 self.listcache = (text, self.addlist) |
140 | 166 self.addlist = None |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
167 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
168 return n |