Show More
@@ -1,90 +1,87 b'' | |||
|
1 | 1 | # parsers.py - Python implementation of parsers.c |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2009 Matt Mackall <mpm@selenic.com> and others |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from mercurial.node import bin, nullid, nullrev |
|
9 | 9 | from mercurial import util |
|
10 | 10 | import struct, zlib |
|
11 | 11 | |
|
12 | 12 | _pack = struct.pack |
|
13 | 13 | _unpack = struct.unpack |
|
14 | 14 | _compress = zlib.compress |
|
15 | 15 | _decompress = zlib.decompress |
|
16 | 16 | _sha = util.sha1 |
|
17 | 17 | |
|
18 | 18 | def parse_manifest(mfdict, fdict, lines): |
|
19 | 19 | for l in lines.splitlines(): |
|
20 | 20 | f, n = l.split('\0') |
|
21 | 21 | if len(n) > 40: |
|
22 | 22 | fdict[f] = n[40:] |
|
23 | 23 | mfdict[f] = bin(n[:40]) |
|
24 | 24 | else: |
|
25 | 25 | mfdict[f] = bin(n) |
|
26 | 26 | |
|
27 | def parse_index(data, inline): | |
|
27 | def parse_index2(data, inline): | |
|
28 | 28 | def gettype(q): |
|
29 | 29 | return int(q & 0xFFFF) |
|
30 | 30 | |
|
31 | 31 | def offset_type(offset, type): |
|
32 | 32 | return long(long(offset) << 16 | type) |
|
33 | 33 | |
|
34 | 34 | indexformatng = ">Qiiiiii20s12x" |
|
35 | 35 | |
|
36 | 36 | s = struct.calcsize(indexformatng) |
|
37 | 37 | index = [] |
|
38 | 38 | cache = None |
|
39 | nodemap = {nullid: nullrev} | |
|
40 | 39 | n = off = 0 |
|
41 | 40 | |
|
42 | 41 | l = len(data) - s |
|
43 | 42 | append = index.append |
|
44 | 43 | if inline: |
|
45 | 44 | cache = (0, data) |
|
46 | 45 | while off <= l: |
|
47 | 46 | e = _unpack(indexformatng, data[off:off + s]) |
|
48 | nodemap[e[7]] = n | |
|
49 | 47 | append(e) |
|
50 | 48 | n += 1 |
|
51 | 49 | if e[1] < 0: |
|
52 | 50 | break |
|
53 | 51 | off += e[1] + s |
|
54 | 52 | else: |
|
55 | 53 | while off <= l: |
|
56 | 54 | e = _unpack(indexformatng, data[off:off + s]) |
|
57 | nodemap[e[7]] = n | |
|
58 | 55 | append(e) |
|
59 | 56 | n += 1 |
|
60 | 57 | off += s |
|
61 | 58 | |
|
62 | 59 | e = list(index[0]) |
|
63 | 60 | type = gettype(e[0]) |
|
64 | 61 | e[0] = offset_type(0, type) |
|
65 | 62 | index[0] = tuple(e) |
|
66 | 63 | |
|
67 | 64 | # add the magic null revision at -1 |
|
68 | 65 | index.append((0, 0, 0, -1, -1, -1, -1, nullid)) |
|
69 | 66 | |
|
70 |
return index, |
|
|
67 | return index, cache | |
|
71 | 68 | |
|
72 | 69 | def parse_dirstate(dmap, copymap, st): |
|
73 | 70 | parents = [st[:20], st[20: 40]] |
|
74 | 71 | # deref fields so they will be local in loop |
|
75 | 72 | format = ">cllll" |
|
76 | 73 | e_size = struct.calcsize(format) |
|
77 | 74 | pos1 = 40 |
|
78 | 75 | l = len(st) |
|
79 | 76 | |
|
80 | 77 | # the inner loop |
|
81 | 78 | while pos1 < l: |
|
82 | 79 | pos2 = pos1 + e_size |
|
83 | 80 | e = _unpack(">cllll", st[pos1:pos2]) # a literal here is faster |
|
84 | 81 | pos1 = pos2 + e[4] |
|
85 | 82 | f = st[pos2:pos1] |
|
86 | 83 | if '\0' in f: |
|
87 | 84 | f, c = f.split('\0') |
|
88 | 85 | copymap[f] = c |
|
89 | 86 | dmap[f] = e[:4] |
|
90 | 87 | return parents |
General Comments 0
You need to be logged in to leave comments.
Login now