comparison mercurial/manifest.py @ 22409:8f09b785b59b

manifest: move addlistdelta to module-level Again, there's no reason for this to be inside manifest.add, so we'll define it only once.
author Augie Fackler <raf@durin42.com>
date Thu, 07 Aug 2014 12:47:20 -0400
parents dc97e04c12ad
children 65ec6c5c0fb3
comparison
equal deleted inserted replaced
22408:dc97e04c12ad 22409:8f09b785b59b
45 """Check filenames for illegal characters.""" 45 """Check filenames for illegal characters."""
46 for f in l: 46 for f in l:
47 if '\n' in f or '\r' in f: 47 if '\n' in f or '\r' in f:
48 raise error.RevlogError( 48 raise error.RevlogError(
49 _("'\\n' and '\\r' disallowed in filenames: %r") % f) 49 _("'\\n' and '\\r' disallowed in filenames: %r") % f)
50
51
52 # apply the changes collected during the bisect loop to our addlist
53 # return a delta suitable for addrevision
54 def addlistdelta(addlist, x):
55 # for large addlist arrays, building a new array is cheaper
56 # than repeatedly modifying the existing one
57 currentposition = 0
58 newaddlist = array.array('c')
59
60 for start, end, content in x:
61 newaddlist += addlist[currentposition:start]
62 if content:
63 newaddlist += array.array('c', content)
64
65 currentposition = end
66
67 newaddlist += addlist[currentposition:]
68
69 deltatext = "".join(struct.pack(">lll", start, end, len(content))
70 + content for start, end, content in x)
71 return deltatext, newaddlist
50 72
51 73
52 class manifest(revlog.revlog): 74 class manifest(revlog.revlog):
53 def __init__(self, opener): 75 def __init__(self, opener):
54 # we expect to deal with not more than four revs at a time, 76 # we expect to deal with not more than four revs at a time,
138 f, n = l.split('\0') 160 f, n = l.split('\0')
139 return revlog.bin(n[:40]), n[40:-1] 161 return revlog.bin(n[:40]), n[40:-1]
140 162
141 def add(self, map, transaction, link, p1=None, p2=None, 163 def add(self, map, transaction, link, p1=None, p2=None,
142 changed=None): 164 changed=None):
143 # apply the changes collected during the bisect loop to our addlist
144 # return a delta suitable for addrevision
145 def addlistdelta(addlist, x):
146 # for large addlist arrays, building a new array is cheaper
147 # than repeatedly modifying the existing one
148 currentposition = 0
149 newaddlist = array.array('c')
150
151 for start, end, content in x:
152 newaddlist += addlist[currentposition:start]
153 if content:
154 newaddlist += array.array('c', content)
155
156 currentposition = end
157
158 newaddlist += addlist[currentposition:]
159
160 deltatext = "".join(struct.pack(">lll", start, end, len(content))
161 + content for start, end, content in x)
162 return deltatext, newaddlist
163
164 # if we're using the cache, make sure it is valid and 165 # if we're using the cache, make sure it is valid and
165 # parented by the same node we're diffing against 166 # parented by the same node we're diffing against
166 if not (changed and p1 and (p1 in self._mancache)): 167 if not (changed and p1 and (p1 in self._mancache)):
167 files = sorted(map) 168 files = sorted(map)
168 checkforbidden(files) 169 checkforbidden(files)