[PATCH 6 of 8] pathencode: implement both basic and hashed encoding in C

Bryan O'Sullivan bos at serpentine.com
Tue Nov 13 16:00:51 CST 2012


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1352842701 28800
# Node ID d7177075d40bb0876695cf0532d8575829ac7800
# Parent  361c0e6e6308b7a83101e49016c6514fb6c5261b
pathencode: implement both basic and hashed encoding in C

diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -715,12 +715,6 @@ static PyObject *hashencode(const char *
 	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;
@@ -735,13 +729,10 @@ PyObject *pathencode(PyObject *self, PyO
 		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) {
@@ -756,10 +747,9 @@ PyObject *pathencode(PyObject *self, PyO
 			basicencode(PyString_AS_STRING(newobj), newlen, path,
 				    len + 1);
 		}
-	} else {
-		newobj = Py_None;
-		Py_INCREF(newobj);
 	}
+	else
+		newobj = hashencode(path, len + 1);
 
 	return newobj;
 }


More information about the Mercurial-devel mailing list