THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

Merge branch 'tg/range-diff-output-update'

"git range-diff" failed to handle mode-only change, which has been
corrected.

* tg/range-diff-output-update:
  range-diff: don't segfault with mode-only changes
tags/v2.24.0-rc0
Junio C Hamano 1 month ago
parent
commit
b6d712fa4e
3 changed files with 92 additions and 22 deletions
  1. +22
    -21
      apply.c
  2. +40
    -0
      t/t3206-range-diff.sh
  3. +30
    -1
      t/t3206/history.export

+ 22
- 21
apply.c View File

@@ -1361,11 +1361,32 @@ int parse_git_diff_header(struct strbuf *root,
if (check_header_line(*linenr, patch))
return -1;
if (res > 0)
return offset;
goto done;
break;
}
}

done:
if (!patch->old_name && !patch->new_name) {
if (!patch->def_name) {
error(Q_("git diff header lacks filename information when removing "
"%d leading pathname component (line %d)",
"git diff header lacks filename information when removing "
"%d leading pathname components (line %d)",
parse_hdr_state.p_value),
parse_hdr_state.p_value, *linenr);
return -128;
}
patch->old_name = xstrdup(patch->def_name);
patch->new_name = xstrdup(patch->def_name);
}
if ((!patch->new_name && !patch->is_delete) ||
(!patch->old_name && !patch->is_new)) {
error(_("git diff header lacks filename information "
"(line %d)"), *linenr);
return -128;
}
patch->is_toplevel_relative = 1;
return offset;
}

@@ -1546,26 +1567,6 @@ static int find_header(struct apply_state *state,
return -128;
if (git_hdr_len <= len)
continue;
if (!patch->old_name && !patch->new_name) {
if (!patch->def_name) {
error(Q_("git diff header lacks filename information when removing "
"%d leading pathname component (line %d)",
"git diff header lacks filename information when removing "
"%d leading pathname components (line %d)",
state->p_value),
state->p_value, state->linenr);
return -128;
}
patch->old_name = xstrdup(patch->def_name);
patch->new_name = xstrdup(patch->def_name);
}
if ((!patch->new_name && !patch->is_delete) ||
(!patch->old_name && !patch->is_new)) {
error(_("git diff header lacks filename information "
"(line %d)"), state->linenr);
return -128;
}
patch->is_toplevel_relative = 1;
*hdrsize = git_hdr_len;
return offset;
}


+ 40
- 0
t/t3206-range-diff.sh View File

@@ -333,6 +333,46 @@ test_expect_success 'renamed file' '
test_cmp expected actual
'

test_expect_success 'file with mode only change' '
git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
sed s/Z/\ /g >expected <<-EOF &&
1: fccce22 ! 1: 4d39cb3 s/4/A/
@@ Metadata
ZAuthor: Thomas Rast <trast@inf.ethz.ch>
Z
Z ## Commit message ##
- s/4/A/
+ s/4/A/ + add other-file
Z
Z ## file ##
Z@@
@@ file
Z A
Z 6
Z 7
+
+ ## other-file (new) ##
2: 147e64e ! 2: 26c107f s/11/B/
@@ Metadata
ZAuthor: Thomas Rast <trast@inf.ethz.ch>
Z
Z ## Commit message ##
- s/11/B/
+ s/11/B/ + mode change other-file
Z
Z ## file ##
Z@@ file: A
@@ file: A
Z 12
Z 13
Z 14
+
+ ## other-file (mode change 100644 => 100755) ##
3: a63e992 = 3: 4c1e0f5 s/12/B/
EOF
test_cmp expected actual
'

test_expect_success 'file added and later removed' '
git range-diff --no-color --submodule=log topic...added-removed >actual &&
sed s/Z/\ /g >expected <<-EOF &&


+ 30
- 1
t/t3206/history.export View File

@@ -55,7 +55,7 @@ A
19
20

commit refs/heads/topic
commit refs/heads/mode-only-change
mark :4
author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
committer Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
@@ -678,3 +678,32 @@ s/12/B/
from :55
M 100644 :9 renamed-file

commit refs/heads/mode-only-change
mark :57
author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
committer Thomas Gummerer <t.gummerer@gmail.com> 1570473767 +0100
data 24
s/4/A/ + add other-file
from :4
M 100644 :5 file
M 100644 :49 other-file

commit refs/heads/mode-only-change
mark :58
author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
committer Thomas Gummerer <t.gummerer@gmail.com> 1570473768 +0100
data 33
s/11/B/ + mode change other-file
from :57
M 100644 :7 file
M 100755 :49 other-file

commit refs/heads/mode-only-change
mark :59
author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
committer Thomas Gummerer <t.gummerer@gmail.com> 1570473768 +0100
data 8
s/12/B/
from :58
M 100644 :9 file


Loading…
Cancel
Save