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