##// END OF EJS Templates
dirstate: speed up read and write...
Matt Mackall -
r5327:f46ab9ca default
parent child Browse files
Show More
@@ -141,22 +141,20 b' class dirstate(object):'
141 141 dmap = self._map
142 142 copymap = self._copymap
143 143 unpack = struct.unpack
144
145 pos = 40
146 144 e_size = struct.calcsize(_format)
145 pos1 = 40
146 l = len(st)
147 147
148 while pos < len(st):
149 newpos = pos + e_size
150 e = unpack(_format, st[pos:newpos])
151 l = e[4]
152 pos = newpos
153 newpos = pos + l
154 f = st[pos:newpos]
148 # the inner loop
149 while pos1 < l:
150 pos2 = pos1 + e_size
151 e = unpack(">cllll", st[pos1:pos2]) # a literal here is faster
152 pos1 = pos2 + e[4]
153 f = st[pos2:pos1]
155 154 if '\0' in f:
156 155 f, c = f.split('\0')
157 156 copymap[f] = c
158 dmap[f] = e[:4]
159 pos = newpos
157 dmap[f] = e # we hold onto e[4] because making a subtuple is slow
160 158
161 159 def invalidate(self):
162 160 for a in "_map _copymap _branch _pl _dirs _ignore".split():
@@ -216,21 +214,21 b' class dirstate(object):'
216 214 'mark a file normal and clean'
217 215 self._dirty = True
218 216 s = os.lstat(self._join(f))
219 self._map[f] = ('n', s.st_mode, s.st_size, s.st_mtime)
217 self._map[f] = ('n', s.st_mode, s.st_size, s.st_mtime, 0)
220 218 if self._copymap.has_key(f):
221 219 del self._copymap[f]
222 220
223 221 def normallookup(self, f):
224 222 'mark a file normal, but possibly dirty'
225 223 self._dirty = True
226 self._map[f] = ('n', 0, -1, -1)
224 self._map[f] = ('n', 0, -1, -1, 0)
227 225 if f in self._copymap:
228 226 del self._copymap[f]
229 227
230 228 def normaldirty(self, f):
231 229 'mark a file normal, but dirty'
232 230 self._dirty = True
233 self._map[f] = ('n', 0, -2, -1)
231 self._map[f] = ('n', 0, -2, -1, 0)
234 232 if f in self._copymap:
235 233 del self._copymap[f]
236 234
@@ -238,14 +236,14 b' class dirstate(object):'
238 236 'mark a file added'
239 237 self._dirty = True
240 238 self._incpathcheck(f)
241 self._map[f] = ('a', 0, -1, -1)
239 self._map[f] = ('a', 0, -1, -1, 0)
242 240 if f in self._copymap:
243 241 del self._copymap[f]
244 242
245 243 def remove(self, f):
246 244 'mark a file removed'
247 245 self._dirty = True
248 self._map[f] = ('r', 0, 0, 0)
246 self._map[f] = ('r', 0, 0, 0, 0)
249 247 self._decpath(f)
250 248 if f in self._copymap:
251 249 del self._copymap[f]
@@ -254,7 +252,7 b' class dirstate(object):'
254 252 'mark a file merged'
255 253 self._dirty = True
256 254 s = os.lstat(self._join(f))
257 self._map[f] = ('m', s.st_mode, s.st_size, s.st_mtime)
255 self._map[f] = ('m', s.st_mode, s.st_size, s.st_mtime, 0)
258 256 if f in self._copymap:
259 257 del self._copymap[f]
260 258
@@ -277,9 +275,9 b' class dirstate(object):'
277 275 self.clear()
278 276 for f in files:
279 277 if files.execf(f):
280 self._map[f] = ('n', 0777, -1, 0)
278 self._map[f] = ('n', 0777, -1, 0, 0)
281 279 else:
282 self._map[f] = ('n', 0666, -1, 0)
280 self._map[f] = ('n', 0666, -1, 0, 0)
283 281 self._pl = (parent, nullid)
284 282 self._dirty = True
285 283
@@ -287,14 +285,16 b' class dirstate(object):'
287 285 if not self._dirty:
288 286 return
289 287 cs = cStringIO.StringIO()
290 cs.write("".join(self._pl))
288 copymap = self._copymap
289 pack = struct.pack
290 write = cs.write
291 write("".join(self._pl))
291 292 for f, e in self._map.iteritems():
292 c = self.copied(f)
293 if c:
294 f = f + "\0" + c
295 e = struct.pack(_format, e[0], e[1], e[2], e[3], len(f))
296 cs.write(e)
297 cs.write(f)
293 if f in copymap:
294 f = "%s\0%s" % (f, copymap[f])
295 e = pack(_format, e[0], e[1], e[2], e[3], len(f))
296 write(e)
297 write(f)
298 298 st = self._opener("dirstate", "w", atomictemp=True)
299 299 st.write(cs.getvalue())
300 300 st.rename()
@@ -510,7 +510,7 b' class dirstate(object):'
510 510
511 511 for src, fn, st in self.statwalk(files, match, ignored=list_ignored):
512 512 if fn in dmap:
513 type_, mode, size, time = dmap[fn]
513 type_, mode, size, time, foo = dmap[fn]
514 514 else:
515 515 if list_ignored and self._ignore(fn):
516 516 iadd(fn)
General Comments 0
You need to be logged in to leave comments. Login now