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