Show More
@@ -8,7 +8,6 b' mercurial/cext/dirs.c' | |||
|
8 | 8 | mercurial/cext/manifest.c |
|
9 | 9 | mercurial/cext/mpatch.c |
|
10 | 10 | mercurial/cext/osutil.c |
|
11 | mercurial/cext/pathencode.c | |
|
12 | 11 | mercurial/cext/revlog.c |
|
13 | 12 | # Vendored code that we should never format: |
|
14 | 13 | contrib/python-zstandard/c-ext/bufferutil.c |
@@ -26,26 +26,26 b'' | |||
|
26 | 26 | |
|
27 | 27 | /* state machine for the fast path */ |
|
28 | 28 | enum path_state { |
|
29 |
START, |
|
|
30 |
A, |
|
|
29 | START, /* first byte of a path component */ | |
|
30 | A, /* "AUX" */ | |
|
31 | 31 | AU, |
|
32 |
THIRD, |
|
|
33 |
C, |
|
|
32 | THIRD, /* third of a 3-byte sequence, e.g. "AUX", "NUL" */ | |
|
33 | C, /* "CON" or "COMn" */ | |
|
34 | 34 | CO, |
|
35 |
COMLPT, |
|
|
35 | COMLPT, /* "COM" or "LPT" */ | |
|
36 | 36 | COMLPTn, |
|
37 | 37 | L, |
|
38 | 38 | LP, |
|
39 | 39 | N, |
|
40 | 40 | NU, |
|
41 |
P, |
|
|
41 | P, /* "PRN" */ | |
|
42 | 42 | PR, |
|
43 |
LDOT, |
|
|
44 |
DOT, |
|
|
45 |
H, |
|
|
46 |
HGDI, |
|
|
43 | LDOT, /* leading '.' */ | |
|
44 | DOT, /* '.' in a non-leading position */ | |
|
45 | H, /* ".h" */ | |
|
46 | HGDI, /* ".hg", ".d", or ".i" */ | |
|
47 | 47 | SPACE, |
|
48 |
DEFAULT |
|
|
48 | DEFAULT, /* byte of a path component after the first */ | |
|
49 | 49 | }; |
|
50 | 50 | |
|
51 | 51 | /* state machine for dir-encoding */ |
@@ -53,7 +53,7 b' enum dir_state {' | |||
|
53 | 53 | DDOT, |
|
54 | 54 | DH, |
|
55 | 55 | DHGDI, |
|
56 | DDEFAULT | |
|
56 | DDEFAULT, | |
|
57 | 57 | }; |
|
58 | 58 | |
|
59 | 59 | static inline int inset(const uint32_t bitset[], char c) |
@@ -82,7 +82,7 b' static inline void memcopy(char *dest, P' | |||
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | static inline void hexencode(char *dest, Py_ssize_t *destlen, size_t destsize, |
|
85 | uint8_t c) | |
|
85 | uint8_t c) | |
|
86 | 86 | { |
|
87 | 87 | static const char hexdigit[] = "0123456789abcdef"; |
|
88 | 88 | |
@@ -92,14 +92,14 b' static inline void hexencode(char *dest,' | |||
|
92 | 92 | |
|
93 | 93 | /* 3-byte escape: tilde followed by two hex digits */ |
|
94 | 94 | static inline void escape3(char *dest, Py_ssize_t *destlen, size_t destsize, |
|
95 | char c) | |
|
95 | char c) | |
|
96 | 96 | { |
|
97 | 97 | charcopy(dest, destlen, destsize, '~'); |
|
98 | 98 | hexencode(dest, destlen, destsize, c); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | static Py_ssize_t _encodedir(char *dest, size_t destsize, | |
|
102 |
|
|
|
101 | static Py_ssize_t _encodedir(char *dest, size_t destsize, const char *src, | |
|
102 | Py_ssize_t len) | |
|
103 | 103 | { |
|
104 | 104 | enum dir_state state = DDEFAULT; |
|
105 | 105 | Py_ssize_t i = 0, destlen = 0; |
@@ -126,8 +126,8 b' static Py_ssize_t _encodedir(char *dest,' | |||
|
126 | 126 | if (src[i] == 'g') { |
|
127 | 127 | state = DHGDI; |
|
128 | 128 | charcopy(dest, &destlen, destsize, src[i++]); |
|
129 | } | |
|
130 |
|
|
|
129 | } else | |
|
130 | state = DDEFAULT; | |
|
131 | 131 | break; |
|
132 | 132 | case DHGDI: |
|
133 | 133 | if (src[i] == '/') { |
@@ -173,17 +173,15 b' PyObject *encodedir(PyObject *self, PyOb' | |||
|
173 | 173 | if (newobj) { |
|
174 | 174 | assert(PyBytes_Check(newobj)); |
|
175 | 175 | Py_SIZE(newobj)--; |
|
176 | _encodedir(PyBytes_AS_STRING(newobj), newlen, path, | |
|
177 | len + 1); | |
|
176 | _encodedir(PyBytes_AS_STRING(newobj), newlen, path, len + 1); | |
|
178 | 177 | } |
|
179 | 178 | |
|
180 | 179 | return newobj; |
|
181 | 180 | } |
|
182 | 181 | |
|
183 | 182 | static Py_ssize_t _encode(const uint32_t twobytes[8], const uint32_t onebyte[8], |
|
184 |
|
|
|
185 |
|
|
|
186 | int encodedir) | |
|
183 | char *dest, Py_ssize_t destlen, size_t destsize, | |
|
184 | const char *src, Py_ssize_t len, int encodedir) | |
|
187 | 185 | { |
|
188 | 186 | enum path_state state = START; |
|
189 | 187 | Py_ssize_t i = 0; |
@@ -237,15 +235,15 b' static Py_ssize_t _encode(const uint32_t' | |||
|
237 | 235 | if (src[i] == 'u') { |
|
238 | 236 | state = AU; |
|
239 | 237 | charcopy(dest, &destlen, destsize, src[i++]); |
|
240 | } | |
|
241 |
|
|
|
238 | } else | |
|
239 | state = DEFAULT; | |
|
242 | 240 | break; |
|
243 | 241 | case AU: |
|
244 | 242 | if (src[i] == 'x') { |
|
245 | 243 | state = THIRD; |
|
246 | 244 | i++; |
|
247 | } | |
|
248 |
|
|
|
245 | } else | |
|
246 | state = DEFAULT; | |
|
249 | 247 | break; |
|
250 | 248 | case THIRD: |
|
251 | 249 | state = DEFAULT; |
@@ -264,24 +262,30 b' static Py_ssize_t _encode(const uint32_t' | |||
|
264 | 262 | if (src[i] == 'o') { |
|
265 | 263 | state = CO; |
|
266 | 264 | charcopy(dest, &destlen, destsize, src[i++]); |
|
267 | } | |
|
268 |
|
|
|
265 | } else | |
|
266 | state = DEFAULT; | |
|
269 | 267 | break; |
|
270 | 268 | case CO: |
|
271 | 269 | if (src[i] == 'm') { |
|
272 | 270 | state = COMLPT; |
|
273 | 271 | i++; |
|
274 | } | |
|
275 | else if (src[i] == 'n') { | |
|
272 | } else if (src[i] == 'n') { | |
|
276 | 273 | state = THIRD; |
|
277 | 274 | i++; |
|
278 | } | |
|
279 |
|
|
|
275 | } else | |
|
276 | state = DEFAULT; | |
|
280 | 277 | break; |
|
281 | 278 | case COMLPT: |
|
282 | 279 | switch (src[i]) { |
|
283 | case '1': case '2': case '3': case '4': case '5': | |
|
284 | case '6': case '7': case '8': case '9': | |
|
280 | case '1': | |
|
281 | case '2': | |
|
282 | case '3': | |
|
283 | case '4': | |
|
284 | case '5': | |
|
285 | case '6': | |
|
286 | case '7': | |
|
287 | case '8': | |
|
288 | case '9': | |
|
285 | 289 | state = COMLPTn; |
|
286 | 290 | i++; |
|
287 | 291 | break; |
@@ -301,8 +305,8 b' static Py_ssize_t _encode(const uint32_t' | |||
|
301 | 305 | charcopy(dest, &destlen, destsize, src[i - 1]); |
|
302 | 306 | break; |
|
303 | 307 | default: |
|
304 | memcopy(dest, &destlen, destsize, | |
|
305 | &src[i - 2], 2); | |
|
308 | memcopy(dest, &destlen, destsize, &src[i - 2], | |
|
309 | 2); | |
|
306 | 310 | break; |
|
307 | 311 | } |
|
308 | 312 | break; |
@@ -310,43 +314,43 b' static Py_ssize_t _encode(const uint32_t' | |||
|
310 | 314 | if (src[i] == 'p') { |
|
311 | 315 | state = LP; |
|
312 | 316 | charcopy(dest, &destlen, destsize, src[i++]); |
|
313 | } | |
|
314 |
|
|
|
317 | } else | |
|
318 | state = DEFAULT; | |
|
315 | 319 | break; |
|
316 | 320 | case LP: |
|
317 | 321 | if (src[i] == 't') { |
|
318 | 322 | state = COMLPT; |
|
319 | 323 | i++; |
|
320 | } | |
|
321 |
|
|
|
324 | } else | |
|
325 | state = DEFAULT; | |
|
322 | 326 | break; |
|
323 | 327 | case N: |
|
324 | 328 | if (src[i] == 'u') { |
|
325 | 329 | state = NU; |
|
326 | 330 | charcopy(dest, &destlen, destsize, src[i++]); |
|
327 | } | |
|
328 |
|
|
|
331 | } else | |
|
332 | state = DEFAULT; | |
|
329 | 333 | break; |
|
330 | 334 | case NU: |
|
331 | 335 | if (src[i] == 'l') { |
|
332 | 336 | state = THIRD; |
|
333 | 337 | i++; |
|
334 | } | |
|
335 |
|
|
|
338 | } else | |
|
339 | state = DEFAULT; | |
|
336 | 340 | break; |
|
337 | 341 | case P: |
|
338 | 342 | if (src[i] == 'r') { |
|
339 | 343 | state = PR; |
|
340 | 344 | charcopy(dest, &destlen, destsize, src[i++]); |
|
341 | } | |
|
342 |
|
|
|
345 | } else | |
|
346 | state = DEFAULT; | |
|
343 | 347 | break; |
|
344 | 348 | case PR: |
|
345 | 349 | if (src[i] == 'n') { |
|
346 | 350 | state = THIRD; |
|
347 | 351 | i++; |
|
348 | } | |
|
349 |
|
|
|
352 | } else | |
|
353 | state = DEFAULT; | |
|
350 | 354 | break; |
|
351 | 355 | case LDOT: |
|
352 | 356 | switch (src[i]) { |
@@ -393,18 +397,18 b' static Py_ssize_t _encode(const uint32_t' | |||
|
393 | 397 | if (src[i] == 'g') { |
|
394 | 398 | state = HGDI; |
|
395 | 399 | charcopy(dest, &destlen, destsize, src[i++]); |
|
396 | } | |
|
397 |
|
|
|
400 | } else | |
|
401 | state = DEFAULT; | |
|
398 | 402 | break; |
|
399 | 403 | case HGDI: |
|
400 | 404 | if (src[i] == '/') { |
|
401 | 405 | state = START; |
|
402 | 406 | if (encodedir) |
|
403 | 407 | memcopy(dest, &destlen, destsize, ".hg", |
|
404 |
|
|
|
408 | 3); | |
|
405 | 409 | charcopy(dest, &destlen, destsize, src[i++]); |
|
406 | } | |
|
407 |
|
|
|
410 | } else | |
|
411 | state = DEFAULT; | |
|
408 | 412 | break; |
|
409 | 413 | case SPACE: |
|
410 | 414 | switch (src[i]) { |
@@ -444,19 +448,17 b' static Py_ssize_t _encode(const uint32_t' | |||
|
444 | 448 | if (inset(onebyte, src[i])) { |
|
445 | 449 | do { |
|
446 | 450 | charcopy(dest, &destlen, |
|
447 |
|
|
|
451 | destsize, src[i++]); | |
|
448 | 452 | } while (i < len && |
|
449 |
|
|
|
450 | } | |
|
451 | else if (inset(twobytes, src[i])) { | |
|
453 | inset(onebyte, src[i])); | |
|
454 | } else if (inset(twobytes, src[i])) { | |
|
452 | 455 | char c = src[i++]; |
|
453 | 456 | charcopy(dest, &destlen, destsize, '_'); |
|
454 | 457 | charcopy(dest, &destlen, destsize, |
|
455 |
|
|
|
456 | } | |
|
457 | else | |
|
458 | c == '_' ? '_' : c + 32); | |
|
459 | } else | |
|
458 | 460 | escape3(dest, &destlen, destsize, |
|
459 |
|
|
|
461 | src[i++]); | |
|
460 | 462 | break; |
|
461 | 463 | } |
|
462 | 464 | break; |
@@ -466,31 +468,29 b' done:' | |||
|
466 | 468 | return destlen; |
|
467 | 469 | } |
|
468 | 470 | |
|
469 | static Py_ssize_t basicencode(char *dest, size_t destsize, | |
|
470 | const char *src, Py_ssize_t len) | |
|
471 | static Py_ssize_t basicencode(char *dest, size_t destsize, const char *src, | |
|
472 | Py_ssize_t len) | |
|
471 | 473 | { |
|
472 |
static const uint32_t twobytes[8] = { |
|
|
474 | static const uint32_t twobytes[8] = {0, 0, 0x87fffffe}; | |
|
473 | 475 | |
|
474 | 476 | static const uint32_t onebyte[8] = { |
|
475 |
|
|
|
477 | 1, 0x2bff3bfa, 0x68000001, 0x2fffffff, | |
|
476 | 478 | }; |
|
477 | 479 | |
|
478 | 480 | Py_ssize_t destlen = 0; |
|
479 | 481 | |
|
480 | return _encode(twobytes, onebyte, dest, destlen, destsize, | |
|
481 | src, len, 1); | |
|
482 | return _encode(twobytes, onebyte, dest, destlen, destsize, src, len, 1); | |
|
482 | 483 | } |
|
483 | 484 | |
|
484 | 485 | static const Py_ssize_t maxstorepathlen = 120; |
|
485 | 486 | |
|
486 | static Py_ssize_t _lowerencode(char *dest, size_t destsize, | |
|
487 | const char *src, Py_ssize_t len) | |
|
487 | static Py_ssize_t _lowerencode(char *dest, size_t destsize, const char *src, | |
|
488 | Py_ssize_t len) | |
|
488 | 489 | { |
|
489 | static const uint32_t onebyte[8] = { | |
|
490 | 1, 0x2bfffbfb, 0xe8000001, 0x2fffffff | |
|
491 | }; | |
|
490 | static const uint32_t onebyte[8] = {1, 0x2bfffbfb, 0xe8000001, | |
|
491 | 0x2fffffff}; | |
|
492 | 492 | |
|
493 |
static const uint32_t lower[8] = { |
|
|
493 | static const uint32_t lower[8] = {0, 0, 0x7fffffe}; | |
|
494 | 494 | |
|
495 | 495 | Py_ssize_t i, destlen = 0; |
|
496 | 496 | |
@@ -524,13 +524,13 b' PyObject *lowerencode(PyObject *self, Py' | |||
|
524 | 524 | } |
|
525 | 525 | |
|
526 | 526 | /* See store.py:_auxencode for a description. */ |
|
527 | static Py_ssize_t auxencode(char *dest, size_t destsize, | |
|
528 | const char *src, Py_ssize_t len) | |
|
527 | static Py_ssize_t auxencode(char *dest, size_t destsize, const char *src, | |
|
528 | Py_ssize_t len) | |
|
529 | 529 | { |
|
530 | 530 | static const uint32_t twobytes[8]; |
|
531 | 531 | |
|
532 | 532 | static const uint32_t onebyte[8] = { |
|
533 |
|
|
|
533 | ~0U, 0xffff3ffe, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, | |
|
534 | 534 | }; |
|
535 | 535 | |
|
536 | 536 | return _encode(twobytes, onebyte, dest, 0, destsize, src, len, 0); |
@@ -590,8 +590,7 b' static PyObject *hashmangle(const char *' | |||
|
590 | 590 | break; |
|
591 | 591 | charcopy(dest, &destlen, destsize, src[i]); |
|
592 | 592 | p = -1; |
|
593 | } | |
|
594 | else if (p < dirprefixlen) | |
|
593 | } else if (p < dirprefixlen) | |
|
595 | 594 | charcopy(dest, &destlen, destsize, src[i]); |
|
596 | 595 | } |
|
597 | 596 | |
@@ -622,13 +621,13 b' static PyObject *hashmangle(const char *' | |||
|
622 | 621 | slop = maxstorepathlen - used; |
|
623 | 622 | if (slop > 0) { |
|
624 | 623 | Py_ssize_t basenamelen = |
|
625 |
|
|
|
624 | lastslash >= 0 ? len - lastslash - 2 : len - 1; | |
|
626 | 625 | |
|
627 | 626 | if (basenamelen > slop) |
|
628 | 627 | basenamelen = slop; |
|
629 | 628 | if (basenamelen > 0) |
|
630 | 629 | memcopy(dest, &destlen, destsize, &src[lastslash + 1], |
|
631 |
|
|
|
630 | basenamelen); | |
|
632 | 631 | } |
|
633 | 632 | |
|
634 | 633 | /* Add hash and suffix. */ |
@@ -637,7 +636,7 b' static PyObject *hashmangle(const char *' | |||
|
637 | 636 | |
|
638 | 637 | if (lastdot >= 0) |
|
639 | 638 | memcopy(dest, &destlen, destsize, &src[lastdot], |
|
640 |
|
|
|
639 | len - lastdot - 1); | |
|
641 | 640 | |
|
642 | 641 | assert(PyBytes_Check(ret)); |
|
643 | 642 | Py_SIZE(ret) = destlen; |
@@ -672,8 +671,8 b' static int sha1hash(char hash[20], const' | |||
|
672 | 671 | |
|
673 | 672 | if (shafunc == NULL) { |
|
674 | 673 | PyErr_SetString(PyExc_AttributeError, |
|
675 |
|
|
|
676 |
|
|
|
674 | "module 'hashlib' has no " | |
|
675 | "attribute 'sha1'"); | |
|
677 | 676 | return -1; |
|
678 | 677 | } |
|
679 | 678 | } |
@@ -690,7 +689,7 b' static int sha1hash(char hash[20], const' | |||
|
690 | 689 | |
|
691 | 690 | if (!PyBytes_Check(hashobj) || PyBytes_GET_SIZE(hashobj) != 20) { |
|
692 | 691 | PyErr_SetString(PyExc_TypeError, |
|
693 |
|
|
|
692 | "result of digest is not a 20-byte hash"); | |
|
694 | 693 | Py_DECREF(hashobj); |
|
695 | 694 | return -1; |
|
696 | 695 | } |
@@ -755,10 +754,9 b' PyObject *pathencode(PyObject *self, PyO' | |||
|
755 | 754 | assert(PyBytes_Check(newobj)); |
|
756 | 755 | Py_SIZE(newobj)--; |
|
757 | 756 | basicencode(PyBytes_AS_STRING(newobj), newlen, path, |
|
758 |
|
|
|
757 | len + 1); | |
|
759 | 758 | } |
|
760 | } | |
|
761 | else | |
|
759 | } else | |
|
762 | 760 | newobj = hashencode(path, len + 1); |
|
763 | 761 | |
|
764 | 762 | return newobj; |
General Comments 0
You need to be logged in to leave comments.
Login now