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