##// END OF EJS Templates
pathencode: allow clang-format oversight...
Augie Fackler -
r36073:44cb058b default
parent child Browse files
Show More
@@ -8,7 +8,6 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
@@ -45,7 +45,7 enum path_state {
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 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)
@@ -98,8 +98,8 static inline void escape3(char *dest, P
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 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,8 +173,7 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;
@@ -182,8 +181,7 PyObject *encodedir(PyObject *self, PyOb
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 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 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 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 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,8 +397,8 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] == '/') {
@@ -403,8 +407,8 static Py_ssize_t _encode(const uint32_t
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]) {
@@ -447,14 +451,12 static Py_ssize_t _encode(const uint32_t
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;
@@ -466,8 +468,8 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
@@ -477,18 +479,16 static Py_ssize_t basicencode(char *dest
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
@@ -524,8 +524,8 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
@@ -590,8 +590,7 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
@@ -757,8 +756,7 PyObject *pathencode(PyObject *self, PyO
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