168 PyObject *fname = NULL, *cname = NULL, *entry = NULL; |
168 PyObject *fname = NULL, *cname = NULL, *entry = NULL; |
169 char *str, *cur, *end, *cpos; |
169 char *str, *cur, *end, *cpos; |
170 int state, mode, size, mtime; |
170 int state, mode, size, mtime; |
171 unsigned int flen; |
171 unsigned int flen; |
172 int len; |
172 int len; |
173 char decode[16]; /* for alignment */ |
173 uint32_t decode[4]; /* for alignment */ |
174 |
174 |
175 if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", |
175 if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", |
176 &PyDict_Type, &dmap, |
176 &PyDict_Type, &dmap, |
177 &PyDict_Type, &cmap, |
177 &PyDict_Type, &cmap, |
178 &str, &len)) |
178 &str, &len)) |
192 |
192 |
193 while (cur < end - 17) { |
193 while (cur < end - 17) { |
194 /* unpack header */ |
194 /* unpack header */ |
195 state = *cur; |
195 state = *cur; |
196 memcpy(decode, cur + 1, 16); |
196 memcpy(decode, cur + 1, 16); |
197 mode = ntohl(*(uint32_t *)(decode)); |
197 mode = ntohl(decode[0]); |
198 size = ntohl(*(uint32_t *)(decode + 4)); |
198 size = ntohl(decode[1]); |
199 mtime = ntohl(*(uint32_t *)(decode + 8)); |
199 mtime = ntohl(decode[2]); |
200 flen = ntohl(*(uint32_t *)(decode + 12)); |
200 flen = ntohl(decode[3]); |
201 cur += 17; |
201 cur += 17; |
202 if (cur + flen > end || cur + flen < cur) { |
202 if (cur + flen > end || cur + flen < cur) { |
203 PyErr_SetString(PyExc_ValueError, "overflow in dirstate"); |
203 PyErr_SetString(PyExc_ValueError, "overflow in dirstate"); |
204 goto quit; |
204 goto quit; |
205 } |
205 } |
262 int n = 0, err; |
262 int n = 0, err; |
263 uint64_t offset_flags; |
263 uint64_t offset_flags; |
264 int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2; |
264 int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2; |
265 const char *c_node_id; |
265 const char *c_node_id; |
266 const char *end = data + size; |
266 const char *end = data + size; |
267 char decode[64]; /* to enforce alignment with inline data */ |
267 uint32_t decode[8]; /* to enforce alignment with inline data */ |
268 |
268 |
269 while (data < end) { |
269 while (data < end) { |
270 unsigned int step; |
270 unsigned int step; |
271 |
271 |
272 memcpy(decode, data, 64); |
272 memcpy(decode, data, 32); |
273 offset_flags = ntohl(*((uint32_t *) (decode + 4))); |
273 offset_flags = ntohl(decode[1]); |
274 if (n == 0) /* mask out version number for the first entry */ |
274 if (n == 0) /* mask out version number for the first entry */ |
275 offset_flags &= 0xFFFF; |
275 offset_flags &= 0xFFFF; |
276 else { |
276 else { |
277 uint32_t offset_high = ntohl(*((uint32_t *)decode)); |
277 uint32_t offset_high = ntohl(decode[0]); |
278 offset_flags |= ((uint64_t)offset_high) << 32; |
278 offset_flags |= ((uint64_t)offset_high) << 32; |
279 } |
279 } |
280 |
280 |
281 comp_len = ntohl(*((uint32_t *)(decode + 8))); |
281 comp_len = ntohl(decode[2]); |
282 uncomp_len = ntohl(*((uint32_t *)(decode + 12))); |
282 uncomp_len = ntohl(decode[3]); |
283 base_rev = ntohl(*((uint32_t *)(decode + 16))); |
283 base_rev = ntohl(decode[4]); |
284 link_rev = ntohl(*((uint32_t *)(decode + 20))); |
284 link_rev = ntohl(decode[5]); |
285 parent_1 = ntohl(*((uint32_t *)(decode + 24))); |
285 parent_1 = ntohl(decode[6]); |
286 parent_2 = ntohl(*((uint32_t *)(decode + 28))); |
286 parent_2 = ntohl(decode[7]); |
287 c_node_id = decode + 32; |
287 c_node_id = data + 32; |
288 |
288 |
289 entry = Py_BuildValue("Liiiiiis#", offset_flags, comp_len, |
289 entry = Py_BuildValue("Liiiiiis#", offset_flags, comp_len, |
290 uncomp_len, base_rev, link_rev, |
290 uncomp_len, base_rev, link_rev, |
291 parent_1, parent_2, c_node_id, 20); |
291 parent_1, parent_2, c_node_id, 20); |
292 |
292 |