]> git.ipfire.org Git - thirdparty/git.git/commitdiff
range-diff: internally force `diff.noprefix=true`
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 2 Oct 2019 21:10:47 +0000 (14:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Oct 2019 02:10:33 +0000 (11:10 +0900)
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 <msuchanek@suse.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
range-diff.c
t/t3206-range-diff.sh

index ba1e9a4265a6cb3e6ae77b2f32f9fd64bee04cc6..f2fc1e02c2c74034c3fe1f3c29fcc81458ccb738 100644 (file)
@@ -52,6 +52,7 @@ static int read_patches(const char *range, struct string_list *list)
 
        argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
                        "--reverse", "--date-order", "--decorate=no",
+                       "--no-prefix",
                        /*
                         * Choose indicators that are not used anywhere
                         * else in diffs, but still look reasonable
@@ -111,7 +112,7 @@ static int read_patches(const char *range, struct string_list *list)
                        if (!util->diff_offset)
                                util->diff_offset = buf.len;
                        line[len - 1] = '\n';
-                       len = parse_git_diff_header(&root, &linenr, 1, line,
+                       len = parse_git_diff_header(&root, &linenr, 0, line,
                                                    len, size, &patch);
                        if (len < 0)
                                die(_("could not parse git header '%.*s'"), (int)len, line);
index ec548654ce1cae8773ad642877e525896a6b54f4..be60976c283f582ee89e5abb8673d92bbe6052ac 100755 (executable)
@@ -354,4 +354,8 @@ test_expect_success 'format-patch --range-diff as commentary' '
        grep "> 1: .* new message" 0001-*
 '
 
+test_expect_success 'range-diff overrides diff.noprefix internally' '
+       git -c diff.noprefix=true range-diff HEAD^...
+'
+
 test_done