# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 2013-06-20 05:34:34
# Node ID 66da6e9feacd05d499cda67dbfc6718fb6ccda4e
# Parent  6f3428c528b4ce7f545a25a3cd3f63110ffc40ad

pathencode: fix hashmangle short dir limit (issue3958)

The Python version of this (see mercurial/store.py:_hashencode) copies path
components up to a limit of maxshortdirslen bytes. The Python version does not
consider the initial "dh/" to be part of the this, though, while the C version
currently does. Adding len("dh/") == 3 to the limit for the C version brings it
in line with the Python version.

This was not caught by the randomized testing scheme in test-pathencode.py
because of a couple of flaws with the test. Upcoming patches will fix those
problems.

diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -585,7 +585,8 @@ static PyObject *hashmangle(const char *
 			   in a space or dot, which are unportable. */
 			if (d == '.' || d == ' ')
 				dest[destlen - 1] = '_';
-			if (destlen > maxshortdirslen)
+			/* The + 3 is to account for "dh/" in the beginning */
+			if (destlen > maxshortdirslen + 3)
 				break;
 			charcopy(dest, &destlen, destsize, src[i]);
 			p = -1;