Show More
@@ -15,6 +15,12 b' from i18n import _' | |||
|
15 | 15 | import binascii, changegroup, errno, ancestor, mdiff, os |
|
16 | 16 | import sha, struct, util, zlib |
|
17 | 17 | |
|
18 | _pack = struct.pack | |
|
19 | _unpack = struct.unpack | |
|
20 | _compress = zlib.compress | |
|
21 | _decompress = zlib.decompress | |
|
22 | _sha = sha.new | |
|
23 | ||
|
18 | 24 | # revlog flags |
|
19 | 25 | REVLOGV0 = 0 |
|
20 | 26 | REVLOGNG = 1 |
@@ -46,7 +52,7 b' def hash(text, p1, p2):' | |||
|
46 | 52 | """ |
|
47 | 53 | l = [p1, p2] |
|
48 | 54 | l.sort() |
|
49 |
s = sha |
|
|
55 | s = _sha(l[0]) | |
|
50 | 56 | s.update(l[1]) |
|
51 | 57 | s.update(text) |
|
52 | 58 | return s.digest() |
@@ -59,7 +65,7 b' def compress(text):' | |||
|
59 | 65 | if text[0] == '\0': |
|
60 | 66 | return ("", text) |
|
61 | 67 | return ('u', text) |
|
62 |
bin = |
|
|
68 | bin = _compress(text) | |
|
63 | 69 | if len(bin) > len(text): |
|
64 | 70 | if text[0] == '\0': |
|
65 | 71 | return ("", text) |
@@ -74,7 +80,7 b' def decompress(bin):' | |||
|
74 | 80 | if t == '\0': |
|
75 | 81 | return bin |
|
76 | 82 | if t == 'x': |
|
77 |
return |
|
|
83 | return _decompress(bin) | |
|
78 | 84 | if t == 'u': |
|
79 | 85 | return bin[1:] |
|
80 | 86 | raise RevlogError(_("unknown compression type %r") % t) |
@@ -234,16 +240,15 b' class lazyindex(object):' | |||
|
234 | 240 | self.p.loadindex(pos) |
|
235 | 241 | return self.p.index[pos] |
|
236 | 242 | def __getitem__(self, pos): |
|
237 |
return |
|
|
238 | self.p.index[pos] or self.load(pos)) | |
|
243 | return _unpack(indexformatng, self.p.index[pos] or self.load(pos)) | |
|
239 | 244 | def __setitem__(self, pos, item): |
|
240 |
self.p.index[pos] = |
|
|
245 | self.p.index[pos] = _pack(indexformatng, *item) | |
|
241 | 246 | def __delitem__(self, pos): |
|
242 | 247 | del self.p.index[pos] |
|
243 | 248 | def insert(self, pos, e): |
|
244 |
self.p.index.insert(pos, |
|
|
249 | self.p.index.insert(pos, _pack(indexformatng, *e)) | |
|
245 | 250 | def append(self, e): |
|
246 |
self.p.index.append( |
|
|
251 | self.p.index.append(_pack(indexformatng, *e)) | |
|
247 | 252 | |
|
248 | 253 | class lazymap(object): |
|
249 | 254 | """a lazy version of the node map""" |
@@ -266,7 +271,7 b' class lazymap(object):' | |||
|
266 | 271 | self.p.loadindex(i) |
|
267 | 272 | ret = self.p.index[i] |
|
268 | 273 | if isinstance(ret, str): |
|
269 |
ret = |
|
|
274 | ret = _unpack(indexformatng, ret) | |
|
270 | 275 | yield ret[7] |
|
271 | 276 | def __getitem__(self, key): |
|
272 | 277 | try: |
@@ -299,7 +304,7 b' class revlogoldio(object):' | |||
|
299 | 304 | while off + s <= l: |
|
300 | 305 | cur = data[off:off + s] |
|
301 | 306 | off += s |
|
302 |
e = |
|
|
307 | e = _unpack(indexformatv0, cur) | |
|
303 | 308 | # transform to revlogv1 format |
|
304 | 309 | e2 = (offset_type(e[0], 0), e[1], -1, e[2], e[3], |
|
305 | 310 | nodemap[e[4]], nodemap[e[5]], e[6]) |
@@ -312,7 +317,7 b' class revlogoldio(object):' | |||
|
312 | 317 | def packentry(self, entry, node, version): |
|
313 | 318 | e2 = (getoffset(entry[0]), entry[1], entry[3], entry[4], |
|
314 | 319 | node(entry[5]), node(entry[6]), entry[7]) |
|
315 |
return |
|
|
320 | return _pack(indexformatv0, *e2) | |
|
316 | 321 | |
|
317 | 322 | # index ng: |
|
318 | 323 | # 6 bytes offset |
@@ -357,12 +362,11 b' class revlogio(object):' | |||
|
357 | 362 | # if we're not using lazymap, always read the whole index |
|
358 | 363 | data = fp.read() |
|
359 | 364 | l = len(data) - s |
|
360 | unpack = struct.unpack | |
|
361 | 365 | append = index.append |
|
362 | 366 | if inline: |
|
363 | 367 | cache = (0, data) |
|
364 | 368 | while off <= l: |
|
365 | e = unpack(indexformatng, data[off:off + s]) | |
|
369 | e = _unpack(indexformatng, data[off:off + s]) | |
|
366 | 370 | nodemap[e[7]] = n |
|
367 | 371 | append(e) |
|
368 | 372 | n += 1 |
@@ -371,7 +375,7 b' class revlogio(object):' | |||
|
371 | 375 | off += e[1] + s |
|
372 | 376 | else: |
|
373 | 377 | while off <= l: |
|
374 | e = unpack(indexformatng, data[off:off + s]) | |
|
378 | e = _unpack(indexformatng, data[off:off + s]) | |
|
375 | 379 | nodemap[e[7]] = n |
|
376 | 380 | append(e) |
|
377 | 381 | n += 1 |
@@ -385,9 +389,9 b' class revlogio(object):' | |||
|
385 | 389 | return index, nodemap, cache |
|
386 | 390 | |
|
387 | 391 | def packentry(self, entry, node, version): |
|
388 |
p = |
|
|
392 | p = _pack(indexformatng, *entry) | |
|
389 | 393 | if not entry[3] and not getoffset(entry[0]) and entry[5] == nullrev: |
|
390 |
p = |
|
|
394 | p = _pack(versionformat, version) + p[4:] | |
|
391 | 395 | return p |
|
392 | 396 | |
|
393 | 397 | class revlog(object): |
General Comments 0
You need to be logged in to leave comments.
Login now