Patchwork [5,of,7,resend] pathencode: implement both basic and hashed encoding in C

login
register
mail settings
Submitter Bryan O'Sullivan
Date Dec. 12, 2012, 9:11 p.m.
Message ID <9fcae4777e797bd8ec8f.1355346660@australite.local>
Download mbox | patch
Permalink /patch/74/
State Accepted
Commit 3807ec0c6bbaeac7a27ea9105204291ba2acb368
Delegated to: Matt Mackall
Headers show

Comments

Bryan O'Sullivan - Dec. 12, 2012, 9:11 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1355346576 28800
# Node ID 9fcae4777e797bd8ec8f968b4fde7a148e0963c0
# Parent  719157ceff748fbe5d55af773c53ec459fef20ad
pathencode: implement both basic and hashed encoding in C

Patch

diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -720,12 +720,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;
@@ -740,13 +734,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) {
@@ -761,10 +752,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;
 }