[PATCH 5 of 7 resend] pathencode: implement both basic and hashed encoding in C
Bryan O'Sullivan
bos at serpentine.com
Wed Dec 12 15:11:00 CST 2012
# 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
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;
}
More information about the Mercurial-devel
mailing list