From: Antoine Pelisse Date: Sat, 23 Feb 2013 16:48:45 +0000 (+0100) Subject: diff: Fix rename pretty-print when suffix and prefix overlap X-Git-Tag: v1.8.1.6~8^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d020e27;p=thirdparty%2Fgit.git diff: Fix rename pretty-print when suffix and prefix overlap When considering a rename for two files that have a suffix and a prefix that can overlap, a confusing line is shown. As an example, renaming "a/b/b/c" to "a/b/c" shows "a/b/{ => }/b/c". Currently, what we do is calculate the common prefix ("a/b/"), and the common suffix ("/b/c"), but the same "/b/" is actually counted both in prefix and suffix. Then when calculating the size of the non-common part, we end-up with a negative value which is reset to 0, thus the "{ => }". Do not allow the common suffix to overlap the common prefix and stop when reaching a "/" that would be in both. Signed-off-by: Antoine Pelisse Signed-off-by: Junio C Hamano --- diff --git a/diff.c b/diff.c index 9038f190ec..e1d82c9672 100644 --- a/diff.c +++ b/diff.c @@ -1177,7 +1177,16 @@ static char *pprint_rename(const char *a, const char *b) old = a + len_a; new = b + len_b; sfx_length = 0; - while (a <= old && b <= new && *old == *new) { + /* + * Note: + * if pfx_length is 0, old/new will never reach a - 1 because it + * would mean the whole string is common suffix. But then, the + * whole string would also be a common prefix, and we would not + * have pfx_length equals 0. + */ + while (a + pfx_length - 1 <= old && + b + pfx_length - 1 <= new && + *old == *new) { if (*old == '/') sfx_length = len_a - (old - a); old--;