Mercurial > hg
annotate mercurial/pure/parsers.py @ 7873:4a4c7f6a5912
cleanup: drop unused imports
author | Peter Arrenbrecht <peter.arrenbrecht@gmail.com> |
---|---|
date | Mon, 23 Mar 2009 13:12:07 +0100 |
parents | f410c552fa15 |
children | 94d7e14cfa42 |
rev | line source |
---|---|
7700
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
1 # parsers.py - Python implementation of parsers.c |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
2 # |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
3 # Copyright 2009 Matt Mackall <mpm@selenic.com> and others |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
4 # |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
7 |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7700
diff
changeset
|
8 from node import bin, nullid, nullrev |
7700
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
9 import revlog, dirstate, struct, util, zlib |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
10 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
11 _pack = struct.pack |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
12 _unpack = struct.unpack |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
13 _compress = zlib.compress |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
14 _decompress = zlib.decompress |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
15 _sha = util.sha1 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
16 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
17 def parse_manifest(mfdict, fdict, lines): |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
18 for l in lines.splitlines(): |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
19 f, n = l.split('\0') |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
20 if len(n) > 40: |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
21 fdict[f] = n[40:] |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
22 mfdict[f] = bin(n[:40]) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
23 else: |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
24 mfdict[f] = bin(n) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
25 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
26 def parse_index(data, inline): |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
27 indexformatng = revlog.indexformatng |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
28 s = struct.calcsize(indexformatng) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
29 index = [] |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
30 cache = None |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
31 nodemap = {nullid: nullrev} |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
32 n = off = 0 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
33 # if we're not using lazymap, always read the whole index |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
34 l = len(data) - s |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
35 append = index.append |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
36 if inline: |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
37 cache = (0, data) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
38 while off <= l: |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
39 e = _unpack(indexformatng, data[off:off + s]) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
40 nodemap[e[7]] = n |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
41 append(e) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
42 n += 1 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
43 if e[1] < 0: |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
44 break |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
45 off += e[1] + s |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
46 else: |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
47 while off <= l: |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
48 e = _unpack(indexformatng, data[off:off + s]) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
49 nodemap[e[7]] = n |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
50 append(e) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
51 n += 1 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
52 off += s |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
53 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
54 e = list(index[0]) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
55 type = revlog.gettype(e[0]) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
56 e[0] = revlog.offset_type(0, type) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
57 index[0] = tuple(e) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
58 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
59 # add the magic null revision at -1 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
60 index.append((0, 0, 0, -1, -1, -1, -1, nullid)) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
61 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
62 return index, nodemap, cache |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
63 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
64 def parse_dirstate(dmap, copymap, st): |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
65 parents = [st[:20], st[20: 40]] |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
66 # deref fields so they will be local in loop |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
67 e_size = struct.calcsize(dirstate._format) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
68 pos1 = 40 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
69 l = len(st) |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
70 |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
71 # the inner loop |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
72 while pos1 < l: |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
73 pos2 = pos1 + e_size |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
74 e = _unpack(">cllll", st[pos1:pos2]) # a literal here is faster |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
75 pos1 = pos2 + e[4] |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
76 f = st[pos2:pos1] |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
77 if '\0' in f: |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
78 f, c = f.split('\0') |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
79 copymap[f] = c |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
80 dmap[f] = e[:4] |
f410c552fa15
pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff
changeset
|
81 return parents |