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