Mercurial > public > mercurial-scm > hg
comparison mercurial/pure/parsers.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | d783f945a701 |
comparison
equal
deleted
inserted
replaced
43076:2372284d9457 | 43077:687b865b95ad |
---|---|
26 def dirstatetuple(*x): | 26 def dirstatetuple(*x): |
27 # x is a tuple | 27 # x is a tuple |
28 return x | 28 return x |
29 | 29 |
30 | 30 |
31 indexformatng = ">Qiiiiii20s12x" | 31 indexformatng = b">Qiiiiii20s12x" |
32 indexfirst = struct.calcsize('Q') | 32 indexfirst = struct.calcsize(b'Q') |
33 sizeint = struct.calcsize('i') | 33 sizeint = struct.calcsize(b'i') |
34 indexsize = struct.calcsize(indexformatng) | 34 indexsize = struct.calcsize(indexformatng) |
35 | 35 |
36 | 36 |
37 def gettype(q): | 37 def gettype(q): |
38 return int(q & 0xFFFF) | 38 return int(q & 0xFFFF) |
49 def append(self, tup): | 49 def append(self, tup): |
50 self._extra.append(tup) | 50 self._extra.append(tup) |
51 | 51 |
52 def _check_index(self, i): | 52 def _check_index(self, i): |
53 if not isinstance(i, int): | 53 if not isinstance(i, int): |
54 raise TypeError("expecting int indexes") | 54 raise TypeError(b"expecting int indexes") |
55 if i < 0 or i >= len(self): | 55 if i < 0 or i >= len(self): |
56 raise IndexError | 56 raise IndexError |
57 | 57 |
58 def __getitem__(self, i): | 58 def __getitem__(self, i): |
59 if i == -1: | 59 if i == -1: |
81 def _calculate_index(self, i): | 81 def _calculate_index(self, i): |
82 return i * indexsize | 82 return i * indexsize |
83 | 83 |
84 def __delitem__(self, i): | 84 def __delitem__(self, i): |
85 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None: | 85 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None: |
86 raise ValueError("deleting slices only supports a:-1 with step 1") | 86 raise ValueError(b"deleting slices only supports a:-1 with step 1") |
87 i = i.start | 87 i = i.start |
88 self._check_index(i) | 88 self._check_index(i) |
89 if i < self._lgt: | 89 if i < self._lgt: |
90 self._data = self._data[: i * indexsize] | 90 self._data = self._data[: i * indexsize] |
91 self._lgt = i | 91 self._lgt = i |
106 if lgt is not None: | 106 if lgt is not None: |
107 self._offsets = [0] * lgt | 107 self._offsets = [0] * lgt |
108 count = 0 | 108 count = 0 |
109 while off <= len(self._data) - indexsize: | 109 while off <= len(self._data) - indexsize: |
110 (s,) = struct.unpack( | 110 (s,) = struct.unpack( |
111 '>i', self._data[off + indexfirst : off + sizeint + indexfirst] | 111 b'>i', self._data[off + indexfirst : off + sizeint + indexfirst] |
112 ) | 112 ) |
113 if lgt is not None: | 113 if lgt is not None: |
114 self._offsets[count] = off | 114 self._offsets[count] = off |
115 count += 1 | 115 count += 1 |
116 off += indexsize + s | 116 off += indexsize + s |
117 if off != len(self._data): | 117 if off != len(self._data): |
118 raise ValueError("corrupted data") | 118 raise ValueError(b"corrupted data") |
119 return count | 119 return count |
120 | 120 |
121 def __delitem__(self, i): | 121 def __delitem__(self, i): |
122 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None: | 122 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None: |
123 raise ValueError("deleting slices only supports a:-1 with step 1") | 123 raise ValueError(b"deleting slices only supports a:-1 with step 1") |
124 i = i.start | 124 i = i.start |
125 self._check_index(i) | 125 self._check_index(i) |
126 if i < self._lgt: | 126 if i < self._lgt: |
127 self._offsets = self._offsets[:i] | 127 self._offsets = self._offsets[:i] |
128 self._lgt = i | 128 self._lgt = i |
141 | 141 |
142 | 142 |
143 def parse_dirstate(dmap, copymap, st): | 143 def parse_dirstate(dmap, copymap, st): |
144 parents = [st[:20], st[20:40]] | 144 parents = [st[:20], st[20:40]] |
145 # dereference fields so they will be local in loop | 145 # dereference fields so they will be local in loop |
146 format = ">cllll" | 146 format = b">cllll" |
147 e_size = struct.calcsize(format) | 147 e_size = struct.calcsize(format) |
148 pos1 = 40 | 148 pos1 = 40 |
149 l = len(st) | 149 l = len(st) |
150 | 150 |
151 # the inner loop | 151 # the inner loop |
152 while pos1 < l: | 152 while pos1 < l: |
153 pos2 = pos1 + e_size | 153 pos2 = pos1 + e_size |
154 e = _unpack(">cllll", st[pos1:pos2]) # a literal here is faster | 154 e = _unpack(b">cllll", st[pos1:pos2]) # a literal here is faster |
155 pos1 = pos2 + e[4] | 155 pos1 = pos2 + e[4] |
156 f = st[pos2:pos1] | 156 f = st[pos2:pos1] |
157 if '\0' in f: | 157 if b'\0' in f: |
158 f, c = f.split('\0') | 158 f, c = f.split(b'\0') |
159 copymap[f] = c | 159 copymap[f] = c |
160 dmap[f] = e[:4] | 160 dmap[f] = e[:4] |
161 return parents | 161 return parents |
162 | 162 |
163 | 163 |
164 def pack_dirstate(dmap, copymap, pl, now): | 164 def pack_dirstate(dmap, copymap, pl, now): |
165 now = int(now) | 165 now = int(now) |
166 cs = stringio() | 166 cs = stringio() |
167 write = cs.write | 167 write = cs.write |
168 write("".join(pl)) | 168 write(b"".join(pl)) |
169 for f, e in dmap.iteritems(): | 169 for f, e in dmap.iteritems(): |
170 if e[0] == 'n' and e[3] == now: | 170 if e[0] == b'n' and e[3] == now: |
171 # The file was last modified "simultaneously" with the current | 171 # The file was last modified "simultaneously" with the current |
172 # write to dirstate (i.e. within the same second for file- | 172 # write to dirstate (i.e. within the same second for file- |
173 # systems with a granularity of 1 sec). This commonly happens | 173 # systems with a granularity of 1 sec). This commonly happens |
174 # for at least a couple of files on 'update'. | 174 # for at least a couple of files on 'update'. |
175 # The user could change the file without changing its size | 175 # The user could change the file without changing its size |
179 # mistakenly treating such files as clean. | 179 # mistakenly treating such files as clean. |
180 e = dirstatetuple(e[0], e[1], e[2], -1) | 180 e = dirstatetuple(e[0], e[1], e[2], -1) |
181 dmap[f] = e | 181 dmap[f] = e |
182 | 182 |
183 if f in copymap: | 183 if f in copymap: |
184 f = "%s\0%s" % (f, copymap[f]) | 184 f = b"%s\0%s" % (f, copymap[f]) |
185 e = _pack(">cllll", e[0], e[1], e[2], e[3], len(f)) | 185 e = _pack(b">cllll", e[0], e[1], e[2], e[3], len(f)) |
186 write(e) | 186 write(e) |
187 write(f) | 187 write(f) |
188 return cs.getvalue() | 188 return cs.getvalue() |