Skip to content

Commit d020e27

Browse files
apelissegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f174a25 commit d020e27

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

diff.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,16 @@ static char *pprint_rename(const char *a, const char *b)
11771177
old = a + len_a;
11781178
new = b + len_b;
11791179
sfx_length = 0;
1180-
while (a <= old && b <= new && *old == *new) {
1180+
/*
1181+
* Note:
1182+
* if pfx_length is 0, old/new will never reach a - 1 because it
1183+
* would mean the whole string is common suffix. But then, the
1184+
* whole string would also be a common prefix, and we would not
1185+
* have pfx_length equals 0.
1186+
*/
1187+
while (a + pfx_length - 1 <= old &&
1188+
b + pfx_length - 1 <= new &&
1189+
*old == *new) {
11811190
if (*old == '/')
11821191
sfx_length = len_a - (old - a);
11831192
old--;

0 commit comments

Comments
 (0)