pathencode: implement both basic and hashed encoding in C
authorBryan O'Sullivan <bryano@fb.com>
Wed, 12 Dec 2012 13:09:36 -0800
changeset 18434 3807ec0c6bba
parent 18433 79f4a2a8f248
child 18435 8c019d2fd7c0
pathencode: implement both basic and hashed encoding in C
mercurial/pathencode.c
--- a/mercurial/pathencode.c	Wed Dec 12 13:09:36 2012 -0800
+++ b/mercurial/pathencode.c	Wed Dec 12 13:09:36 2012 -0800
@@ -720,12 +720,6 @@
 	return hashmangle(auxed, auxlen, sha);
 }
 
-/*
- * We currently implement only basic encoding.
- *
- * If a name is too long to encode due to Windows path name limits,
- * this function returns None.
- */
 PyObject *pathencode(PyObject *self, PyObject *args)
 {
 	Py_ssize_t len, newlen;
@@ -740,13 +734,10 @@
 		return NULL;
 	}
 
-	if (len > maxstorepathlen) {
-		newobj = Py_None;
-		Py_INCREF(newobj);
-		return newobj;
-	}
-
-	newlen = len ? basicencode(NULL, 0, path, len + 1) : 1;
+	if (len > maxstorepathlen)
+		newlen = maxstorepathlen + 2;
+	else
+		newlen = len ? basicencode(NULL, 0, path, len + 1) : 1;
 
 	if (newlen <= maxstorepathlen + 1) {
 		if (newlen == len + 1) {
@@ -761,10 +752,9 @@
 			basicencode(PyString_AS_STRING(newobj), newlen, path,
 				    len + 1);
 		}
-	} else {
-		newobj = Py_None;
-		Py_INCREF(newobj);
 	}
+	else
+		newobj = hashencode(path, len + 1);
 
 	return newobj;
 }