mercurial/pathencode.c
changeset 18452 8bd338c7c4c9
parent 18434 3807ec0c6bba
child 19051 55c6ab8163ec
equal deleted inserted replaced
18451:d6b3b36f1db2 18452:8bd338c7c4c9
   694 	memcpy(hash, PyString_AS_STRING(hashobj), 20);
   694 	memcpy(hash, PyString_AS_STRING(hashobj), 20);
   695 	Py_DECREF(hashobj);
   695 	Py_DECREF(hashobj);
   696 	return 0;
   696 	return 0;
   697 }
   697 }
   698 
   698 
       
   699 #define MAXENCODE 4096 * 3
       
   700 
   699 static PyObject *hashencode(const char *src, Py_ssize_t len)
   701 static PyObject *hashencode(const char *src, Py_ssize_t len)
   700 {
   702 {
   701 	const Py_ssize_t baselen = (len - 5) * 3;
   703 	char dired[MAXENCODE];
   702 #ifndef _MSC_VER
   704 	char lowered[MAXENCODE];
   703 	/* alloca is surprisingly slow, so avoid when possible */
   705 	char auxed[MAXENCODE];
   704 	char dired[baselen];
   706 	Py_ssize_t dirlen, lowerlen, auxlen, baselen;
   705 	char lowered[baselen];
       
   706 	char auxed[baselen];
       
   707 #else
       
   708 	char *dired = alloca(baselen);
       
   709 	char *lowered = alloca(baselen);
       
   710 	char *auxed = alloca(baselen);
       
   711 #endif
       
   712 	Py_ssize_t dirlen, lowerlen, auxlen;
       
   713 	char sha[20];
   707 	char sha[20];
       
   708 
       
   709 	baselen = (len - 5) * 3;
       
   710 	if (baselen >= MAXENCODE) {
       
   711 		PyErr_SetString(PyExc_ValueError, "string too long");
       
   712 		return NULL;
       
   713 	}
   714 
   714 
   715 	dirlen = _encodedir(dired, baselen, src, len);
   715 	dirlen = _encodedir(dired, baselen, src, len);
   716 	if (sha1hash(sha, dired, dirlen - 1) == -1)
   716 	if (sha1hash(sha, dired, dirlen - 1) == -1)
   717 		return NULL;
   717 		return NULL;
   718 	lowerlen = _lowerencode(lowered, baselen, dired + 5, dirlen - 5);
   718 	lowerlen = _lowerencode(lowered, baselen, dired + 5, dirlen - 5);