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