changeset 18434:3807ec0c6bba

pathencode: implement both basic and hashed encoding in C
author Bryan O'Sullivan <bryano@fb.com>
date Wed, 12 Dec 2012 13:09:36 -0800
parents 79f4a2a8f248
children 8c019d2fd7c0
files mercurial/pathencode.c
diffstat 1 files changed, 6 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }