Skip to content

Commit 9993a60

Browse files
committed
range-diff: internally force diff.noprefix=true
When parsing the diffs, `range-diff` expects to see the prefixes `a/` and `b/` in the diff headers. These prefixes can be forced off via the config setting `diff.noprefix=true`. As `range-diff` is not prepared for that situation, this will cause a segmentation fault. Let's avoid that by passing the `--no-prefix` option to the `git log` process that generates the diffs that `range-diff` wants to parse. And of course expect the output to have no prefixes, then. Reported-by: Michal Suchánek <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent bc12974 commit 9993a60

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

range-diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static int read_patches(const char *range, struct string_list *list)
5252

5353
argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
5454
"--reverse", "--date-order", "--decorate=no",
55+
"--no-prefix",
5556
/*
5657
* Choose indicators that are not used anywhere
5758
* else in diffs, but still look reasonable
@@ -111,7 +112,7 @@ static int read_patches(const char *range, struct string_list *list)
111112
if (!util->diff_offset)
112113
util->diff_offset = buf.len;
113114
line[len - 1] = '\n';
114-
len = parse_git_diff_header(&root, &linenr, 1, line,
115+
len = parse_git_diff_header(&root, &linenr, 0, line,
115116
len, size, &patch);
116117
if (len < 0)
117118
die(_("could not parse git header '%.*s'"), (int)len, line);

t/t3206-range-diff.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,8 @@ test_expect_success 'format-patch --range-diff as commentary' '
461461
grep "> 1: .* new message" 0001-*
462462
'
463463

464+
test_expect_success 'range-diff overrides diff.noprefix internally' '
465+
git -c diff.noprefix=true range-diff HEAD^...
466+
'
467+
464468
test_done

0 commit comments

Comments
 (0)