author | Adrian Buehlmann <adrian@cadifra.com> |
Thu, 02 Sep 2010 14:45:16 +0200 | |
changeset 12151 | cc5b71840148 |
parent 12011 | f38b0a3308b6 |
child 13031 | 3da456d0c885 |
permissions | -rw-r--r-- |
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 _ |
8390
beae42f3d93b
drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8312
diff
changeset
|
9 |
import mdiff, parsers, error, revlog |
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 |
|
2835
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2834
diff
changeset
|
12 |
class manifestdict(dict): |
2857
18cf5349a361
Fix some bugs introduced during the manifest refactoring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2841
diff
changeset
|
13 |
def __init__(self, mapping=None, flags=None): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
14 |
if mapping is None: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
15 |
mapping = {} |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
16 |
if flags is None: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
17 |
flags = {} |
2831 | 18 |
dict.__init__(self, mapping) |
2839
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2835
diff
changeset
|
19 |
self._flags = flags |
2834
35af2e56f15a
manifestflags: eliminate remaining users of direct dict access
Matt Mackall <mpm@selenic.com>
parents:
2833
diff
changeset
|
20 |
def flags(self, f): |
2839
b4f05ecf4ee8
Switch to simpler manifestdict
Matt Mackall <mpm@selenic.com>
parents:
2835
diff
changeset
|
21 |
return self._flags.get(f, "") |
6743 | 22 |
def set(self, f, flags): |
23 |
self._flags[f] = flags |
|
2831 | 24 |
def copy(self): |
9416
eecbaac5ca88
manifestdict: remove unnecessary dictionary copy
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9415
diff
changeset
|
25 |
return manifestdict(self, dict.copy(self._flags)) |
2831 | 26 |
|
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
27 |
class manifest(revlog.revlog): |
4258
b11a2fb59cf5
revlog: simplify revlog version handling
Matt Mackall <mpm@selenic.com>
parents:
4257
diff
changeset
|
28 |
def __init__(self, opener): |
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
29 |
self._mancache = None |
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
30 |
revlog.revlog.__init__(self, opener, "00manifest.i") |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
31 |
|
4995
e45fc5d03798
manifest: speed up creation of the manifestdict
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
32 |
def parse(self, lines): |
e45fc5d03798
manifest: speed up creation of the manifestdict
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
33 |
mfdict = manifestdict() |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
6212
diff
changeset
|
34 |
parsers.parse_manifest(mfdict, mfdict._flags, lines) |
4995
e45fc5d03798
manifest: speed up creation of the manifestdict
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
35 |
return mfdict |
3196
f3b939444c72
Abstract manifest block parsing.
Brendan Cully <brendan@kublai.com>
parents:
3148
diff
changeset
|
36 |
|
f3b939444c72
Abstract manifest block parsing.
Brendan Cully <brendan@kublai.com>
parents:
3148
diff
changeset
|
37 |
def readdelta(self, node): |
7362
6db4a2ccef3a
revlog: remove delta function
Matt Mackall <mpm@selenic.com>
parents:
6765
diff
changeset
|
38 |
r = self.rev(node) |
12011
f38b0a3308b6
deltaparent(): don't return nullrev for a revision containing a full snapshot
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11962
diff
changeset
|
39 |
return self.parse(mdiff.patchtext(self.revdiff(self.deltaparent(r), r))) |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3196
diff
changeset
|
40 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
41 |
def read(self, node): |
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
42 |
if node == revlog.nullid: |
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
43 |
return manifestdict() # don't upset local cache |
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
44 |
if self._mancache and self._mancache[0] == node: |
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
45 |
return self._mancache[1] |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
46 |
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
|
47 |
arraytext = array.array('c', text) |
4995
e45fc5d03798
manifest: speed up creation of the manifestdict
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
48 |
mapping = self.parse(text) |
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
49 |
self._mancache = (node, mapping, arraytext) |
2835
a9f5d4149123
Combine manifest dict and flags dict into a single object
Matt Mackall <mpm@selenic.com>
parents:
2834
diff
changeset
|
50 |
return mapping |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
51 |
|
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
52 |
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
|
53 |
'''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
|
54 |
|
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
|
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
return i |
7405
f1944e74e83c
manifest: fix _search() corner-case
Patrick Mezard <pmezard@gmail.com>
parents:
7362
diff
changeset
|
67 |
if not s: |
f1944e74e83c
manifest: fix _search() corner-case
Patrick Mezard <pmezard@gmail.com>
parents:
7362
diff
changeset
|
68 |
return (lo, lo) |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
start = mid |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
75 |
while start > 0 and m[start - 1] != '\n': |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
76 |
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
|
77 |
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
|
78 |
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
|
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 |
# 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
|
81 |
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
|
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 |
# 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
|
84 |
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
|
85 |
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
|
86 |
found = m[lo:end] |
11763
69e0bcf36961
manifest: removed usage of the global cmp function
Renato Cunha <renatoc@gmail.com>
parents:
10282
diff
changeset
|
87 |
if s == found: |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
88 |
# 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
|
89 |
end = advance(end + 40, '\n') |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
90 |
return (lo, end + 1) |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
91 |
else: |
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
92 |
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
|
93 |
|
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
94 |
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
|
95 |
'''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
|
96 |
return (node, flags) pair if found, (None, None) if not.''' |
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
97 |
if self._mancache and self._mancache[0] == node: |
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
98 |
return self._mancache[1].get(f), self._mancache[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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
f, n = l.split('\0') |
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
105 |
return revlog.bin(n[:40]), n[40:-1] |
2320
dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2142
diff
changeset
|
106 |
|
2841 | 107 |
def add(self, map, transaction, link, p1=None, p2=None, |
741 | 108 |
changed=None): |
644 | 109 |
# apply the changes collected during the bisect loop to our addlist |
1534 | 110 |
# return a delta suitable for addrevision |
111 |
def addlistdelta(addlist, x): |
|
112 |
# start from the bottom up |
|
644 | 113 |
# so changes to the offsets don't mess things up. |
9413
a5adf55ee533
manifest.add(): simplify with iterators and generator expressions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8390
diff
changeset
|
114 |
for start, end, content in reversed(x): |
a5adf55ee533
manifest.add(): simplify with iterators and generator expressions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8390
diff
changeset
|
115 |
if content: |
a5adf55ee533
manifest.add(): simplify with iterators and generator expressions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8390
diff
changeset
|
116 |
addlist[start:end] = array.array('c', content) |
644 | 117 |
else: |
118 |
del addlist[start:end] |
|
9413
a5adf55ee533
manifest.add(): simplify with iterators and generator expressions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8390
diff
changeset
|
119 |
return "".join(struct.pack(">lll", start, end, len(content)) + content |
a5adf55ee533
manifest.add(): simplify with iterators and generator expressions
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8390
diff
changeset
|
120 |
for start, end, content in x) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
121 |
|
6765
be142cb994ff
manifest: make checkforbidden take a list
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
122 |
def checkforbidden(l): |
be142cb994ff
manifest: make checkforbidden take a list
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
123 |
for f in l: |
be142cb994ff
manifest: make checkforbidden take a list
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
124 |
if '\n' in f or '\r' in f: |
7633 | 125 |
raise error.RevlogError( |
8077
d051342f1ad1
manifest: improve error message about newlines in filenames
Greg Ward <greg-hg@gerg.ca>
parents:
7634
diff
changeset
|
126 |
_("'\\n' and '\\r' disallowed in filenames: %r") % f) |
3607
f4c9bb4ad7b1
issue352: disallow '\n' and '\r' in filenames (dirstate and manifest)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3223
diff
changeset
|
127 |
|
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
128 |
# if we're using the cache, make sure it is valid and |
644 | 129 |
# parented by the same node we're diffing against |
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
130 |
if not (changed and self._mancache and p1 and self._mancache[0] == p1): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8077
diff
changeset
|
131 |
files = sorted(map) |
6765
be142cb994ff
manifest: make checkforbidden take a list
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
132 |
checkforbidden(files) |
3607
f4c9bb4ad7b1
issue352: disallow '\n' and '\r' in filenames (dirstate and manifest)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3223
diff
changeset
|
133 |
|
1651 | 134 |
# if this is changed to support newlines in filenames, |
135 |
# be sure to check the templates/ dir again (especially *-raw.tmpl) |
|
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
136 |
hex, flags = revlog.hex, map.flags |
9420
d0db168136dc
manifest/revlog: do not let the revlog cache mutable objects
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9416
diff
changeset
|
137 |
text = ''.join("%s\000%s%s\n" % (f, hex(map[f]), flags(f)) |
d0db168136dc
manifest/revlog: do not let the revlog cache mutable objects
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9416
diff
changeset
|
138 |
for f in files) |
d0db168136dc
manifest/revlog: do not let the revlog cache mutable objects
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9416
diff
changeset
|
139 |
arraytext = array.array('c', text) |
644 | 140 |
cachedelta = None |
141 |
else: |
|
9415
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
142 |
added, removed = changed |
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
143 |
addlist = self._mancache[2] |
644 | 144 |
|
9415
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
145 |
checkforbidden(added) |
644 | 146 |
# 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
|
147 |
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
|
148 |
work.extend((x, True) for x in removed) |
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
149 |
# this could use heapq.merge() (from python2.6+) or equivalent |
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
150 |
# since the lists are already sorted |
644 | 151 |
work.sort() |
152 |
||
153 |
delta = [] |
|
1534 | 154 |
dstart = None |
155 |
dend = None |
|
156 |
dline = [""] |
|
157 |
start = 0 |
|
158 |
# zero copy representation of addlist as a buffer |
|
159 |
addbuf = buffer(addlist) |
|
644 | 160 |
|
1534 | 161 |
# start with a readonly loop that finds the offset of |
162 |
# each line and creates the deltas |
|
9415
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
163 |
for f, todelete in work: |
741 | 164 |
# 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
|
165 |
start, end = self._search(addbuf, f, start) |
9415
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
166 |
if not todelete: |
7634
14a4337a9b9b
revlog: kill from-style imports
Matt Mackall <mpm@selenic.com>
parents:
7633
diff
changeset
|
167 |
l = "%s\000%s%s\n" % (f, revlog.hex(map[f]), map.flags(f)) |
644 | 168 |
else: |
9415
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
169 |
if start == end: |
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
170 |
# item we want to delete was not found, error out |
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
171 |
raise AssertionError( |
e0cc9fa2a576
manifest.add(): cleanup worklist construction and iteration
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9414
diff
changeset
|
172 |
_("failed to remove %s from manifest") % f) |
1534 | 173 |
l = "" |
174 |
if dstart != None and dstart <= start and dend >= start: |
|
175 |
if dend < end: |
|
176 |
dend = end |
|
177 |
if l: |
|
178 |
dline.append(l) |
|
644 | 179 |
else: |
1534 | 180 |
if dstart != None: |
181 |
delta.append([dstart, dend, "".join(dline)]) |
|
182 |
dstart = start |
|
183 |
dend = end |
|
184 |
dline = [l] |
|
644 | 185 |
|
1534 | 186 |
if dstart != None: |
187 |
delta.append([dstart, dend, "".join(dline)]) |
|
188 |
# apply the delta to the addlist, and get a delta for addrevision |
|
11962
5f7ee3db3dd8
revlog._addrevision(): make the parent of the cached delta explicit
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11934
diff
changeset
|
189 |
cachedelta = (self.rev(p1), addlistdelta(addlist, delta)) |
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
190 |
arraytext = addlist |
9420
d0db168136dc
manifest/revlog: do not let the revlog cache mutable objects
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9416
diff
changeset
|
191 |
text = buffer(arraytext) |
1534 | 192 |
|
9420
d0db168136dc
manifest/revlog: do not let the revlog cache mutable objects
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9416
diff
changeset
|
193 |
n = self.addrevision(text, transaction, link, p1, p2, cachedelta) |
9414
65dc516363ee
manifest: simplify cache handling, use a unique cache
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9413
diff
changeset
|
194 |
self._mancache = (n, map, arraytext) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
195 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
196 |
return n |