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