##// END OF EJS Templates
parsers: remove unused dependency on util...
Drew Gottlieb -
r24634:4ece2847 default
parent child Browse files
Show More
@@ -1,112 +1,110 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 of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from mercurial.node import nullid
9 from mercurial import util
10 9 import struct, zlib, cStringIO
11 10
12 11 _pack = struct.pack
13 12 _unpack = struct.unpack
14 13 _compress = zlib.compress
15 14 _decompress = zlib.decompress
16 _sha = util.sha1
17 15
18 16 # Some code below makes tuples directly because it's more convenient. However,
19 17 # code outside this module should always use dirstatetuple.
20 18 def dirstatetuple(*x):
21 19 # x is a tuple
22 20 return x
23 21
24 22 def parse_index2(data, inline):
25 23 def gettype(q):
26 24 return int(q & 0xFFFF)
27 25
28 26 def offset_type(offset, type):
29 27 return long(long(offset) << 16 | type)
30 28
31 29 indexformatng = ">Qiiiiii20s12x"
32 30
33 31 s = struct.calcsize(indexformatng)
34 32 index = []
35 33 cache = None
36 34 off = 0
37 35
38 36 l = len(data) - s
39 37 append = index.append
40 38 if inline:
41 39 cache = (0, data)
42 40 while off <= l:
43 41 e = _unpack(indexformatng, data[off:off + s])
44 42 append(e)
45 43 if e[1] < 0:
46 44 break
47 45 off += e[1] + s
48 46 else:
49 47 while off <= l:
50 48 e = _unpack(indexformatng, data[off:off + s])
51 49 append(e)
52 50 off += s
53 51
54 52 if off != len(data):
55 53 raise ValueError('corrupt index file')
56 54
57 55 if index:
58 56 e = list(index[0])
59 57 type = gettype(e[0])
60 58 e[0] = offset_type(0, type)
61 59 index[0] = tuple(e)
62 60
63 61 # add the magic null revision at -1
64 62 index.append((0, 0, 0, -1, -1, -1, -1, nullid))
65 63
66 64 return index, cache
67 65
68 66 def parse_dirstate(dmap, copymap, st):
69 67 parents = [st[:20], st[20: 40]]
70 68 # dereference fields so they will be local in loop
71 69 format = ">cllll"
72 70 e_size = struct.calcsize(format)
73 71 pos1 = 40
74 72 l = len(st)
75 73
76 74 # the inner loop
77 75 while pos1 < l:
78 76 pos2 = pos1 + e_size
79 77 e = _unpack(">cllll", st[pos1:pos2]) # a literal here is faster
80 78 pos1 = pos2 + e[4]
81 79 f = st[pos2:pos1]
82 80 if '\0' in f:
83 81 f, c = f.split('\0')
84 82 copymap[f] = c
85 83 dmap[f] = e[:4]
86 84 return parents
87 85
88 86 def pack_dirstate(dmap, copymap, pl, now):
89 87 now = int(now)
90 88 cs = cStringIO.StringIO()
91 89 write = cs.write
92 90 write("".join(pl))
93 91 for f, e in dmap.iteritems():
94 92 if e[0] == 'n' and e[3] == now:
95 93 # The file was last modified "simultaneously" with the current
96 94 # write to dirstate (i.e. within the same second for file-
97 95 # systems with a granularity of 1 sec). This commonly happens
98 96 # for at least a couple of files on 'update'.
99 97 # The user could change the file without changing its size
100 98 # within the same second. Invalidate the file's mtime in
101 99 # dirstate, forcing future 'status' calls to compare the
102 100 # contents of the file if the size is the same. This prevents
103 101 # mistakenly treating such files as clean.
104 102 e = dirstatetuple(e[0], e[1], e[2], -1)
105 103 dmap[f] = e
106 104
107 105 if f in copymap:
108 106 f = "%s\0%s" % (f, copymap[f])
109 107 e = _pack(">cllll", e[0], e[1], e[2], e[3], len(f))
110 108 write(e)
111 109 write(f)
112 110 return cs.getvalue()
General Comments 0
You need to be logged in to leave comments. Login now