mercurial/cext/pathencode.c
changeset 41361 763b45bc4483
parent 38702 992e108212a9
child 46446 e92ca942ddca
equal deleted inserted replaced
41360:b81ca9a3f4e4 41361:763b45bc4483
   124 			break;
   124 			break;
   125 		case DH:
   125 		case DH:
   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 			} else
   129 			} else {
   130 				state = DDEFAULT;
   130 				state = DDEFAULT;
       
   131 			}
   131 			break;
   132 			break;
   132 		case DHGDI:
   133 		case DHGDI:
   133 			if (src[i] == '/') {
   134 			if (src[i] == '/') {
   134 				memcopy(dest, &destlen, destsize, ".hg", 3);
   135 				memcopy(dest, &destlen, destsize, ".hg", 3);
   135 				charcopy(dest, &destlen, destsize, src[i++]);
   136 				charcopy(dest, &destlen, destsize, src[i++]);
   136 			}
   137 			}
   137 			state = DDEFAULT;
   138 			state = DDEFAULT;
   138 			break;
   139 			break;
   139 		case DDEFAULT:
   140 		case DDEFAULT:
   140 			if (src[i] == '.')
   141 			if (src[i] == '.') {
   141 				state = DDOT;
   142 				state = DDOT;
       
   143 			}
   142 			charcopy(dest, &destlen, destsize, src[i++]);
   144 			charcopy(dest, &destlen, destsize, src[i++]);
   143 			break;
   145 			break;
   144 		}
   146 		}
   145 	}
   147 	}
   146 
   148 
   151 {
   153 {
   152 	Py_ssize_t len, newlen;
   154 	Py_ssize_t len, newlen;
   153 	PyObject *pathobj, *newobj;
   155 	PyObject *pathobj, *newobj;
   154 	char *path;
   156 	char *path;
   155 
   157 
   156 	if (!PyArg_ParseTuple(args, "O:encodedir", &pathobj))
   158 	if (!PyArg_ParseTuple(args, "O:encodedir", &pathobj)) {
   157 		return NULL;
   159 		return NULL;
       
   160 	}
   158 
   161 
   159 	if (PyBytes_AsStringAndSize(pathobj, &path, &len) == -1) {
   162 	if (PyBytes_AsStringAndSize(pathobj, &path, &len) == -1) {
   160 		PyErr_SetString(PyExc_TypeError, "expected a string");
   163 		PyErr_SetString(PyExc_TypeError, "expected a string");
   161 		return NULL;
   164 		return NULL;
   162 	}
   165 	}
   233 			break;
   236 			break;
   234 		case A:
   237 		case A:
   235 			if (src[i] == 'u') {
   238 			if (src[i] == 'u') {
   236 				state = AU;
   239 				state = AU;
   237 				charcopy(dest, &destlen, destsize, src[i++]);
   240 				charcopy(dest, &destlen, destsize, src[i++]);
   238 			} else
   241 			} else {
   239 				state = DEFAULT;
   242 				state = DEFAULT;
       
   243 			}
   240 			break;
   244 			break;
   241 		case AU:
   245 		case AU:
   242 			if (src[i] == 'x') {
   246 			if (src[i] == 'x') {
   243 				state = THIRD;
   247 				state = THIRD;
   244 				i++;
   248 				i++;
   245 			} else
   249 			} else {
   246 				state = DEFAULT;
   250 				state = DEFAULT;
       
   251 			}
   247 			break;
   252 			break;
   248 		case THIRD:
   253 		case THIRD:
   249 			state = DEFAULT;
   254 			state = DEFAULT;
   250 			switch (src[i]) {
   255 			switch (src[i]) {
   251 			case '.':
   256 			case '.':
   260 			break;
   265 			break;
   261 		case C:
   266 		case C:
   262 			if (src[i] == 'o') {
   267 			if (src[i] == 'o') {
   263 				state = CO;
   268 				state = CO;
   264 				charcopy(dest, &destlen, destsize, src[i++]);
   269 				charcopy(dest, &destlen, destsize, src[i++]);
   265 			} else
   270 			} else {
   266 				state = DEFAULT;
   271 				state = DEFAULT;
       
   272 			}
   267 			break;
   273 			break;
   268 		case CO:
   274 		case CO:
   269 			if (src[i] == 'm') {
   275 			if (src[i] == 'm') {
   270 				state = COMLPT;
   276 				state = COMLPT;
   271 				i++;
   277 				i++;
   272 			} else if (src[i] == 'n') {
   278 			} else if (src[i] == 'n') {
   273 				state = THIRD;
   279 				state = THIRD;
   274 				i++;
   280 				i++;
   275 			} else
   281 			} else {
   276 				state = DEFAULT;
   282 				state = DEFAULT;
       
   283 			}
   277 			break;
   284 			break;
   278 		case COMLPT:
   285 		case COMLPT:
   279 			switch (src[i]) {
   286 			switch (src[i]) {
   280 			case '1':
   287 			case '1':
   281 			case '2':
   288 			case '2':
   312 			break;
   319 			break;
   313 		case L:
   320 		case L:
   314 			if (src[i] == 'p') {
   321 			if (src[i] == 'p') {
   315 				state = LP;
   322 				state = LP;
   316 				charcopy(dest, &destlen, destsize, src[i++]);
   323 				charcopy(dest, &destlen, destsize, src[i++]);
   317 			} else
   324 			} else {
   318 				state = DEFAULT;
   325 				state = DEFAULT;
       
   326 			}
   319 			break;
   327 			break;
   320 		case LP:
   328 		case LP:
   321 			if (src[i] == 't') {
   329 			if (src[i] == 't') {
   322 				state = COMLPT;
   330 				state = COMLPT;
   323 				i++;
   331 				i++;
   324 			} else
   332 			} else {
   325 				state = DEFAULT;
   333 				state = DEFAULT;
       
   334 			}
   326 			break;
   335 			break;
   327 		case N:
   336 		case N:
   328 			if (src[i] == 'u') {
   337 			if (src[i] == 'u') {
   329 				state = NU;
   338 				state = NU;
   330 				charcopy(dest, &destlen, destsize, src[i++]);
   339 				charcopy(dest, &destlen, destsize, src[i++]);
   331 			} else
   340 			} else {
   332 				state = DEFAULT;
   341 				state = DEFAULT;
       
   342 			}
   333 			break;
   343 			break;
   334 		case NU:
   344 		case NU:
   335 			if (src[i] == 'l') {
   345 			if (src[i] == 'l') {
   336 				state = THIRD;
   346 				state = THIRD;
   337 				i++;
   347 				i++;
   338 			} else
   348 			} else {
   339 				state = DEFAULT;
   349 				state = DEFAULT;
       
   350 			}
   340 			break;
   351 			break;
   341 		case P:
   352 		case P:
   342 			if (src[i] == 'r') {
   353 			if (src[i] == 'r') {
   343 				state = PR;
   354 				state = PR;
   344 				charcopy(dest, &destlen, destsize, src[i++]);
   355 				charcopy(dest, &destlen, destsize, src[i++]);
   345 			} else
   356 			} else {
   346 				state = DEFAULT;
   357 				state = DEFAULT;
       
   358 			}
   347 			break;
   359 			break;
   348 		case PR:
   360 		case PR:
   349 			if (src[i] == 'n') {
   361 			if (src[i] == 'n') {
   350 				state = THIRD;
   362 				state = THIRD;
   351 				i++;
   363 				i++;
   352 			} else
   364 			} else {
   353 				state = DEFAULT;
   365 				state = DEFAULT;
       
   366 			}
   354 			break;
   367 			break;
   355 		case LDOT:
   368 		case LDOT:
   356 			switch (src[i]) {
   369 			switch (src[i]) {
   357 			case 'd':
   370 			case 'd':
   358 			case 'i':
   371 			case 'i':
   395 			break;
   408 			break;
   396 		case H:
   409 		case H:
   397 			if (src[i] == 'g') {
   410 			if (src[i] == 'g') {
   398 				state = HGDI;
   411 				state = HGDI;
   399 				charcopy(dest, &destlen, destsize, src[i++]);
   412 				charcopy(dest, &destlen, destsize, src[i++]);
   400 			} else
   413 			} else {
   401 				state = DEFAULT;
   414 				state = DEFAULT;
       
   415 			}
   402 			break;
   416 			break;
   403 		case HGDI:
   417 		case HGDI:
   404 			if (src[i] == '/') {
   418 			if (src[i] == '/') {
   405 				state = START;
   419 				state = START;
   406 				if (encodedir)
   420 				if (encodedir) {
   407 					memcopy(dest, &destlen, destsize, ".hg",
   421 					memcopy(dest, &destlen, destsize, ".hg",
   408 					        3);
   422 					        3);
   409 				charcopy(dest, &destlen, destsize, src[i++]);
   423 				}
   410 			} else
   424 				charcopy(dest, &destlen, destsize, src[i++]);
   411 				state = DEFAULT;
   425 			} else {
       
   426 				state = DEFAULT;
       
   427 			}
   412 			break;
   428 			break;
   413 		case SPACE:
   429 		case SPACE:
   414 			switch (src[i]) {
   430 			switch (src[i]) {
   415 			case '/':
   431 			case '/':
   416 			case '\0':
   432 			case '\0':
   425 			}
   441 			}
   426 			break;
   442 			break;
   427 		case DEFAULT:
   443 		case DEFAULT:
   428 			while (inset(onebyte, src[i])) {
   444 			while (inset(onebyte, src[i])) {
   429 				charcopy(dest, &destlen, destsize, src[i++]);
   445 				charcopy(dest, &destlen, destsize, src[i++]);
   430 				if (i == len)
   446 				if (i == len) {
   431 					goto done;
   447 					goto done;
       
   448 				}
   432 			}
   449 			}
   433 			switch (src[i]) {
   450 			switch (src[i]) {
   434 			case '.':
   451 			case '.':
   435 				state = DOT;
   452 				state = DOT;
   436 				i++;
   453 				i++;
   454 				} else if (inset(twobytes, src[i])) {
   471 				} else if (inset(twobytes, src[i])) {
   455 					char c = src[i++];
   472 					char c = src[i++];
   456 					charcopy(dest, &destlen, destsize, '_');
   473 					charcopy(dest, &destlen, destsize, '_');
   457 					charcopy(dest, &destlen, destsize,
   474 					charcopy(dest, &destlen, destsize,
   458 					         c == '_' ? '_' : c + 32);
   475 					         c == '_' ? '_' : c + 32);
   459 				} else
   476 				} else {
   460 					escape3(dest, &destlen, destsize,
   477 					escape3(dest, &destlen, destsize,
   461 					        src[i++]);
   478 					        src[i++]);
       
   479 				}
   462 				break;
   480 				break;
   463 			}
   481 			}
   464 			break;
   482 			break;
   465 		}
   483 		}
   466 	}
   484 	}
   496 	static const uint32_t lower[8] = {0, 0, 0x7fffffe};
   514 	static const uint32_t lower[8] = {0, 0, 0x7fffffe};
   497 
   515 
   498 	Py_ssize_t i, destlen = 0;
   516 	Py_ssize_t i, destlen = 0;
   499 
   517 
   500 	for (i = 0; i < len; i++) {
   518 	for (i = 0; i < len; i++) {
   501 		if (inset(onebyte, src[i]))
   519 		if (inset(onebyte, src[i])) {
   502 			charcopy(dest, &destlen, destsize, src[i]);
   520 			charcopy(dest, &destlen, destsize, src[i]);
   503 		else if (inset(lower, src[i]))
   521 		} else if (inset(lower, src[i])) {
   504 			charcopy(dest, &destlen, destsize, src[i] + 32);
   522 			charcopy(dest, &destlen, destsize, src[i] + 32);
   505 		else
   523 		} else {
   506 			escape3(dest, &destlen, destsize, src[i]);
   524 			escape3(dest, &destlen, destsize, src[i]);
       
   525 		}
   507 	}
   526 	}
   508 
   527 
   509 	return destlen;
   528 	return destlen;
   510 }
   529 }
   511 
   530 
   514 	char *path;
   533 	char *path;
   515 	Py_ssize_t len, newlen;
   534 	Py_ssize_t len, newlen;
   516 	PyObject *ret;
   535 	PyObject *ret;
   517 
   536 
   518 	if (!PyArg_ParseTuple(args, PY23("s#:lowerencode", "y#:lowerencode"),
   537 	if (!PyArg_ParseTuple(args, PY23("s#:lowerencode", "y#:lowerencode"),
   519 	                      &path, &len))
   538 	                      &path, &len)) {
   520 		return NULL;
   539 		return NULL;
       
   540 	}
   521 
   541 
   522 	newlen = _lowerencode(NULL, 0, path, len);
   542 	newlen = _lowerencode(NULL, 0, path, len);
   523 	ret = PyBytes_FromStringAndSize(NULL, newlen);
   543 	ret = PyBytes_FromStringAndSize(NULL, newlen);
   524 	if (ret)
   544 	if (ret) {
   525 		_lowerencode(PyBytes_AS_STRING(ret), newlen, path, len);
   545 		_lowerencode(PyBytes_AS_STRING(ret), newlen, path, len);
       
   546 	}
   526 
   547 
   527 	return ret;
   548 	return ret;
   528 }
   549 }
   529 
   550 
   530 /* See store.py:_auxencode for a description. */
   551 /* See store.py:_auxencode for a description. */
   549 
   570 
   550 	Py_ssize_t i, d, p, lastslash = len - 1, lastdot = -1;
   571 	Py_ssize_t i, d, p, lastslash = len - 1, lastdot = -1;
   551 	Py_ssize_t destsize, destlen = 0, slop, used;
   572 	Py_ssize_t destsize, destlen = 0, slop, used;
   552 
   573 
   553 	while (lastslash >= 0 && src[lastslash] != '/') {
   574 	while (lastslash >= 0 && src[lastslash] != '/') {
   554 		if (src[lastslash] == '.' && lastdot == -1)
   575 		if (src[lastslash] == '.' && lastdot == -1) {
   555 			lastdot = lastslash;
   576 			lastdot = lastslash;
       
   577 		}
   556 		lastslash--;
   578 		lastslash--;
   557 	}
   579 	}
   558 
   580 
   559 #if 0
   581 #if 0
   560 	/* All paths should end in a suffix of ".i" or ".d".
   582 	/* All paths should end in a suffix of ".i" or ".d".
   568 #endif
   590 #endif
   569 
   591 
   570 	/* If src contains a suffix, we will append it to the end of
   592 	/* If src contains a suffix, we will append it to the end of
   571 	   the new string, so make room. */
   593 	   the new string, so make room. */
   572 	destsize = 120;
   594 	destsize = 120;
   573 	if (lastdot >= 0)
   595 	if (lastdot >= 0) {
   574 		destsize += len - lastdot - 1;
   596 		destsize += len - lastdot - 1;
       
   597 	}
   575 
   598 
   576 	ret = PyBytes_FromStringAndSize(NULL, destsize);
   599 	ret = PyBytes_FromStringAndSize(NULL, destsize);
   577 	if (ret == NULL)
   600 	if (ret == NULL) {
   578 		return NULL;
   601 		return NULL;
       
   602 	}
   579 
   603 
   580 	dest = PyBytes_AS_STRING(ret);
   604 	dest = PyBytes_AS_STRING(ret);
   581 	memcopy(dest, &destlen, destsize, "dh/", 3);
   605 	memcopy(dest, &destlen, destsize, "dh/", 3);
   582 
   606 
   583 	/* Copy up to dirprefixlen bytes of each path component, up to
   607 	/* Copy up to dirprefixlen bytes of each path component, up to
   585 	for (i = d = p = 0; i < lastslash; i++, p++) {
   609 	for (i = d = p = 0; i < lastslash; i++, p++) {
   586 		if (src[i] == '/') {
   610 		if (src[i] == '/') {
   587 			char d = dest[destlen - 1];
   611 			char d = dest[destlen - 1];
   588 			/* After truncation, a directory name may end
   612 			/* After truncation, a directory name may end
   589 			   in a space or dot, which are unportable. */
   613 			   in a space or dot, which are unportable. */
   590 			if (d == '.' || d == ' ')
   614 			if (d == '.' || d == ' ') {
   591 				dest[destlen - 1] = '_';
   615 				dest[destlen - 1] = '_';
   592 			/* The + 3 is to account for "dh/" in the beginning */
   616 				/* The + 3 is to account for "dh/" in the
   593 			if (destlen > maxshortdirslen + 3)
   617 				 * beginning */
   594 				break;
   618 			}
       
   619 			if (destlen > maxshortdirslen + 3) {
       
   620 				break;
       
   621 			}
   595 			charcopy(dest, &destlen, destsize, src[i]);
   622 			charcopy(dest, &destlen, destsize, src[i]);
   596 			p = -1;
   623 			p = -1;
   597 		} else if (p < dirprefixlen)
   624 		} else if (p < dirprefixlen) {
   598 			charcopy(dest, &destlen, destsize, src[i]);
   625 			charcopy(dest, &destlen, destsize, src[i]);
       
   626 		}
   599 	}
   627 	}
   600 
   628 
   601 	/* Rewind to just before the last slash copied. */
   629 	/* Rewind to just before the last slash copied. */
   602 	if (destlen > maxshortdirslen + 3)
   630 	if (destlen > maxshortdirslen + 3) {
   603 		do {
   631 		do {
   604 			destlen--;
   632 			destlen--;
   605 		} while (destlen > 0 && dest[destlen] != '/');
   633 		} while (destlen > 0 && dest[destlen] != '/');
       
   634 	}
   606 
   635 
   607 	if (destlen > 3) {
   636 	if (destlen > 3) {
   608 		if (lastslash > 0) {
   637 		if (lastslash > 0) {
   609 			char d = dest[destlen - 1];
   638 			char d = dest[destlen - 1];
   610 			/* The last directory component may be
   639 			/* The last directory component may be
   611 			   truncated, so make it safe. */
   640 			   truncated, so make it safe. */
   612 			if (d == '.' || d == ' ')
   641 			if (d == '.' || d == ' ') {
   613 				dest[destlen - 1] = '_';
   642 				dest[destlen - 1] = '_';
       
   643 			}
   614 		}
   644 		}
   615 
   645 
   616 		charcopy(dest, &destlen, destsize, '/');
   646 		charcopy(dest, &destlen, destsize, '/');
   617 	}
   647 	}
   618 
   648 
   619 	/* Add a prefix of the original file's name. Its length
   649 	/* Add a prefix of the original file's name. Its length
   620 	   depends on the number of bytes left after accounting for
   650 	   depends on the number of bytes left after accounting for
   621 	   hash and suffix. */
   651 	   hash and suffix. */
   622 	used = destlen + 40;
   652 	used = destlen + 40;
   623 	if (lastdot >= 0)
   653 	if (lastdot >= 0) {
   624 		used += len - lastdot - 1;
   654 		used += len - lastdot - 1;
       
   655 	}
   625 	slop = maxstorepathlen - used;
   656 	slop = maxstorepathlen - used;
   626 	if (slop > 0) {
   657 	if (slop > 0) {
   627 		Py_ssize_t basenamelen =
   658 		Py_ssize_t basenamelen =
   628 		    lastslash >= 0 ? len - lastslash - 2 : len - 1;
   659 		    lastslash >= 0 ? len - lastslash - 2 : len - 1;
   629 
   660 
   630 		if (basenamelen > slop)
   661 		if (basenamelen > slop) {
   631 			basenamelen = slop;
   662 			basenamelen = slop;
   632 		if (basenamelen > 0)
   663 		}
       
   664 		if (basenamelen > 0) {
   633 			memcopy(dest, &destlen, destsize, &src[lastslash + 1],
   665 			memcopy(dest, &destlen, destsize, &src[lastslash + 1],
   634 			        basenamelen);
   666 			        basenamelen);
       
   667 		}
   635 	}
   668 	}
   636 
   669 
   637 	/* Add hash and suffix. */
   670 	/* Add hash and suffix. */
   638 	for (i = 0; i < 20; i++)
   671 	for (i = 0; i < 20; i++) {
   639 		hexencode(dest, &destlen, destsize, sha[i]);
   672 		hexencode(dest, &destlen, destsize, sha[i]);
   640 
   673 	}
   641 	if (lastdot >= 0)
   674 
       
   675 	if (lastdot >= 0) {
   642 		memcopy(dest, &destlen, destsize, &src[lastdot],
   676 		memcopy(dest, &destlen, destsize, &src[lastdot],
   643 		        len - lastdot - 1);
   677 		        len - lastdot - 1);
       
   678 	}
   644 
   679 
   645 	assert(PyBytes_Check(ret));
   680 	assert(PyBytes_Check(ret));
   646 	Py_SIZE(ret) = destlen;
   681 	Py_SIZE(ret) = destlen;
   647 
   682 
   648 	return ret;
   683 	return ret;
   675 		}
   710 		}
   676 	}
   711 	}
   677 
   712 
   678 	shaobj = PyObject_CallFunction(shafunc, PY23("s#", "y#"), str, len);
   713 	shaobj = PyObject_CallFunction(shafunc, PY23("s#", "y#"), str, len);
   679 
   714 
   680 	if (shaobj == NULL)
   715 	if (shaobj == NULL) {
   681 		return -1;
   716 		return -1;
       
   717 	}
   682 
   718 
   683 	hashobj = PyObject_CallMethod(shaobj, "digest", "");
   719 	hashobj = PyObject_CallMethod(shaobj, "digest", "");
   684 	Py_DECREF(shaobj);
   720 	Py_DECREF(shaobj);
   685 	if (hashobj == NULL)
   721 	if (hashobj == NULL) {
   686 		return -1;
   722 		return -1;
       
   723 	}
   687 
   724 
   688 	if (!PyBytes_Check(hashobj) || PyBytes_GET_SIZE(hashobj) != 20) {
   725 	if (!PyBytes_Check(hashobj) || PyBytes_GET_SIZE(hashobj) != 20) {
   689 		PyErr_SetString(PyExc_TypeError,
   726 		PyErr_SetString(PyExc_TypeError,
   690 		                "result of digest is not a 20-byte hash");
   727 		                "result of digest is not a 20-byte hash");
   691 		Py_DECREF(hashobj);
   728 		Py_DECREF(hashobj);
   712 		PyErr_SetString(PyExc_ValueError, "string too long");
   749 		PyErr_SetString(PyExc_ValueError, "string too long");
   713 		return NULL;
   750 		return NULL;
   714 	}
   751 	}
   715 
   752 
   716 	dirlen = _encodedir(dired, baselen, src, len);
   753 	dirlen = _encodedir(dired, baselen, src, len);
   717 	if (sha1hash(sha, dired, dirlen - 1) == -1)
   754 	if (sha1hash(sha, dired, dirlen - 1) == -1) {
   718 		return NULL;
   755 		return NULL;
       
   756 	}
   719 	lowerlen = _lowerencode(lowered, baselen, dired + 5, dirlen - 5);
   757 	lowerlen = _lowerencode(lowered, baselen, dired + 5, dirlen - 5);
   720 	auxlen = auxencode(auxed, baselen, lowered, lowerlen);
   758 	auxlen = auxencode(auxed, baselen, lowered, lowerlen);
   721 	return hashmangle(auxed, auxlen, sha);
   759 	return hashmangle(auxed, auxlen, sha);
   722 }
   760 }
   723 
   761 
   725 {
   763 {
   726 	Py_ssize_t len, newlen;
   764 	Py_ssize_t len, newlen;
   727 	PyObject *pathobj, *newobj;
   765 	PyObject *pathobj, *newobj;
   728 	char *path;
   766 	char *path;
   729 
   767 
   730 	if (!PyArg_ParseTuple(args, "O:pathencode", &pathobj))
   768 	if (!PyArg_ParseTuple(args, "O:pathencode", &pathobj)) {
   731 		return NULL;
   769 		return NULL;
       
   770 	}
   732 
   771 
   733 	if (PyBytes_AsStringAndSize(pathobj, &path, &len) == -1) {
   772 	if (PyBytes_AsStringAndSize(pathobj, &path, &len) == -1) {
   734 		PyErr_SetString(PyExc_TypeError, "expected a string");
   773 		PyErr_SetString(PyExc_TypeError, "expected a string");
   735 		return NULL;
   774 		return NULL;
   736 	}
   775 	}
   737 
   776 
   738 	if (len > maxstorepathlen)
   777 	if (len > maxstorepathlen) {
   739 		newlen = maxstorepathlen + 2;
   778 		newlen = maxstorepathlen + 2;
   740 	else
   779 	} else {
   741 		newlen = len ? basicencode(NULL, 0, path, len + 1) : 1;
   780 		newlen = len ? basicencode(NULL, 0, path, len + 1) : 1;
       
   781 	}
   742 
   782 
   743 	if (newlen <= maxstorepathlen + 1) {
   783 	if (newlen <= maxstorepathlen + 1) {
   744 		if (newlen == len + 1) {
   784 		if (newlen == len + 1) {
   745 			Py_INCREF(pathobj);
   785 			Py_INCREF(pathobj);
   746 			return pathobj;
   786 			return pathobj;
   752 			assert(PyBytes_Check(newobj));
   792 			assert(PyBytes_Check(newobj));
   753 			Py_SIZE(newobj)--;
   793 			Py_SIZE(newobj)--;
   754 			basicencode(PyBytes_AS_STRING(newobj), newlen, path,
   794 			basicencode(PyBytes_AS_STRING(newobj), newlen, path,
   755 			            len + 1);
   795 			            len + 1);
   756 		}
   796 		}
   757 	} else
   797 	} else {
   758 		newobj = hashencode(path, len + 1);
   798 		newobj = hashencode(path, len + 1);
       
   799 	}
   759 
   800 
   760 	return newobj;
   801 	return newobj;
   761 }
   802 }