提交 8f780ca9 编写于 作者: J Junio C Hamano

Merge branch 'ap/maint-diff-rename-avoid-overlap' into maint-1.8.1

* 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
...@@ -1256,6 +1256,7 @@ static char *pprint_rename(const char *a, const char *b) ...@@ -1256,6 +1256,7 @@ static char *pprint_rename(const char *a, const char *b)
const char *new = b; const char *new = b;
struct strbuf name = STRBUF_INIT; struct strbuf name = STRBUF_INIT;
int pfx_length, sfx_length; int pfx_length, sfx_length;
int pfx_adjust_for_slash;
int len_a = strlen(a); int len_a = strlen(a);
int len_b = strlen(b); int len_b = strlen(b);
int a_midlen, b_midlen; int a_midlen, b_midlen;
...@@ -1282,7 +1283,18 @@ static char *pprint_rename(const char *a, const char *b) ...@@ -1282,7 +1283,18 @@ static char *pprint_rename(const char *a, const char *b)
old = a + len_a; old = a + len_a;
new = b + len_b; new = b + len_b;
sfx_length = 0; 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 == '/') if (*old == '/')
sfx_length = len_a - (old - a); sfx_length = len_a - (old - a);
old--; old--;
......
...@@ -102,4 +102,58 @@ test_expect_success 'setup for many rename source candidates' ' ...@@ -102,4 +102,58 @@ test_expect_success 'setup for many rename source candidates' '
grep warning actual.err grep warning actual.err
' '
test_expect_success 'rename pretty print with nothing in common' '
mkdir -p a/b/ &&
: >a/b/c &&
git add a/b/c &&
git commit -m "create a/b/c" &&
mkdir -p c/b/ &&
git mv a/b/c c/b/a &&
git commit -m "a/b/c -> c/b/a" &&
git diff -M --summary HEAD^ HEAD >output &&
test_i18ngrep " a/b/c => c/b/a " output &&
git diff -M --stat HEAD^ HEAD >output &&
test_i18ngrep " a/b/c => c/b/a " output
'
test_expect_success 'rename pretty print with common prefix' '
mkdir -p c/d &&
git mv c/b/a c/d/e &&
git commit -m "c/b/a -> c/d/e" &&
git diff -M --summary HEAD^ HEAD >output &&
test_i18ngrep " c/{b/a => d/e} " output &&
git diff -M --stat HEAD^ HEAD >output &&
test_i18ngrep " c/{b/a => d/e} " output
'
test_expect_success 'rename pretty print with common suffix' '
mkdir d &&
git mv c/d/e d/e &&
git commit -m "c/d/e -> d/e" &&
git diff -M --summary HEAD^ HEAD >output &&
test_i18ngrep " {c/d => d}/e " output &&
git diff -M --stat HEAD^ HEAD >output &&
test_i18ngrep " {c/d => d}/e " output
'
test_expect_success 'rename pretty print with common prefix and suffix' '
mkdir d/f &&
git mv d/e d/f/e &&
git commit -m "d/e -> d/f/e" &&
git diff -M --summary HEAD^ HEAD >output &&
test_i18ngrep " d/{ => f}/e " output &&
git diff -M --stat HEAD^ HEAD >output &&
test_i18ngrep " d/{ => f}/e " output
'
test_expect_success 'rename pretty print common prefix and suffix overlap' '
mkdir d/f/f &&
git mv d/f/e d/f/f/e &&
git commit -m "d/f/e d/f/f/e" &&
git diff -M --summary HEAD^ HEAD >output &&
test_i18ngrep " d/f/{ => f}/e " output &&
git diff -M --stat HEAD^ HEAD >output &&
test_i18ngrep " d/f/{ => f}/e " output
'
test_done test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册