summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-03-25 21:00:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-03-25 21:00:37 (GMT)
commitcaf217a3b8ed4b88f58e2a151c07221d37db7abe (patch)
tree79b3ae9735eaef05809f2b9310683095f9280d0d /diff.c
parentb03b41e24c84731742e132d86ef3e449dcd6ec25 (diff)
parentb174eb42d08eeb32ae7341ff46b05c20d38abc2b (diff)
downloadgit-caf217a3b8ed4b88f58e2a151c07221d37db7abe.zip
git-caf217a3b8ed4b88f58e2a151c07221d37db7abe.tar.gz
git-caf217a3b8ed4b88f58e2a151c07221d37db7abe.tar.bz2
Merge branch 'ap/maint-diff-rename-avoid-overlap'
The logic used by "git diff -M --stat" to shorten the names of files before and after a rename did not work correctly when the common prefix and suffix between the two filenames overlapped. * ap/maint-diff-rename-avoid-overlap: tests: make sure rename pretty print works diff: prevent pprint_rename from underrunning input diff: Fix rename pretty-print when suffix and prefix overlap
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/diff.c b/diff.c
index 052974e..db952a5 100644
--- a/diff.c
+++ b/diff.c
@@ -1264,6 +1264,7 @@ static char *pprint_rename(const char *a, const char *b)
const char *new = b;
struct strbuf name = STRBUF_INIT;
int pfx_length, sfx_length;
+ int pfx_adjust_for_slash;
int len_a = strlen(a);
int len_b = strlen(b);
int a_midlen, b_midlen;
@@ -1290,7 +1291,18 @@ 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) {
+ /*
+ * If there is a common prefix, it must end in a slash. In
+ * that case we let this loop run 1 into the prefix to see the
+ * same slash.
+ *
+ * If there is no common prefix, we cannot do this as it would
+ * underrun the input strings.
+ */
+ pfx_adjust_for_slash = (pfx_length ? 1 : 0);
+ while (a + pfx_length - pfx_adjust_for_slash <= old &&
+ b + pfx_length - pfx_adjust_for_slash <= new &&
+ *old == *new) {
if (*old == '/')
sfx_length = len_a - (old - a);
old--;