Message ID | 1f84f92846bc14d21aa7339c8baa0f9bb710b17d.1570039511.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Avoid segmentation fault in git range-diff when diff.noprefix=true | expand |
On Wed, Oct 2, 2019 at 2:05 PM Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com> wrote: > 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 forcing `diff.noprefix=false` just for that all to s/all/call/ > `git log` that generates the diffs that `range-diff` wants to parse. > > Noticed-by: Michal Suchánek <msuchanek@suse.de> s/Noticed/Reported/ perhaps? > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
On Wed, Oct 02, 2019 at 11:05:13AM -0700, Johannes Schindelin via GitGitGadget wrote: > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > 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 forcing `diff.noprefix=false` just for that all to > `git log` that generates the diffs that `range-diff` wants to parse. > > Noticed-by: Michal Suchánek <msuchanek@suse.de> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Tested-by: Michal Suchánek <msuchanek@suse.de> Thanks Michal > --- > range-diff.c | 3 ++- > t/t3206-range-diff.sh | 4 ++++ > 2 files changed, 6 insertions(+), 1 deletion(-) > > diff --git a/range-diff.c b/range-diff.c > index ba1e9a4265..8cc348b4cb 100644 > --- a/range-diff.c > +++ b/range-diff.c > @@ -50,7 +50,8 @@ static int read_patches(const char *range, struct string_list *list) > int offset, len; > size_t size; > > - argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges", > + argv_array_pushl(&cp.args, "-c", "diff.noprefix=false", > + "log", "--no-color", "-p", "--no-merges", > "--reverse", "--date-order", "--decorate=no", > /* > * Choose indicators that are not used anywhere > diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh > index 0120f769f1..64b66f2094 100755 > --- a/t/t3206-range-diff.sh > +++ b/t/t3206-range-diff.sh > @@ -461,4 +461,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 > -- > gitgitgadget
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > When parsing the diffs, `range-diff` expects to see the prefixes `a/` > and `b/` in the diff headers. If so, passing src/dst prefix as command line option is a much better solution, I think. diff.noprefix may not stay to be (or it may already not to be) the only thing how the prefix gets chosen. > - argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges", > + argv_array_pushl(&cp.args, "-c", "diff.noprefix=false", > + "log", "--no-color", "-p", "--no-merges", > "--reverse", "--date-order", "--decorate=no", > /* > * Choose indicators that are not used anywhere > diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh > index 0120f769f1..64b66f2094 100755 > --- a/t/t3206-range-diff.sh > +++ b/t/t3206-range-diff.sh > @@ -461,4 +461,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
Hi Junio, On Thu, 3 Oct 2019, Junio C Hamano wrote: > "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> > writes: > > > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > > > When parsing the diffs, `range-diff` expects to see the prefixes `a/` > > and `b/` in the diff headers. > > If so, passing src/dst prefix as command line option is a much better > solution, I think. diff.noprefix may not stay to be (or it may > already not to be) the only thing how the prefix gets chosen. Good point. While at it, I invert the logic in v2: instead of forcing a prefix, I now force no prefix (and reduce the strip level from 1 to 0 when parsing the diff header). Thanks, Dscho > > > - argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges", > > + argv_array_pushl(&cp.args, "-c", "diff.noprefix=false", > > + "log", "--no-color", "-p", "--no-merges", > > "--reverse", "--date-order", "--decorate=no", > > /* > > * Choose indicators that are not used anywhere > > diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh > > index 0120f769f1..64b66f2094 100755 > > --- a/t/t3206-range-diff.sh > > +++ b/t/t3206-range-diff.sh > > @@ -461,4 +461,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 >
Junio C Hamano <gitster@pobox.com> writes: > "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> > writes: > >> From: Johannes Schindelin <johannes.schindelin@gmx.de> >> >> When parsing the diffs, `range-diff` expects to see the prefixes `a/` >> and `b/` in the diff headers. > > If so, passing src/dst prefix as command line option is a much > better solution, I think. diff.noprefix may not stay to be (or it > may already not to be) the only thing how the prefix gets chosen. That is, "--src-prefix=a/ --dst-prefix=b/", so that configuration variables yet to be invented for setting prefixes different from a/ and b/ can also be overridden, not just diff.noprefix (ancient Git used l/ and k/ as src and dst prefix, IIRC).
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes: > While at it, I invert the logic in v2: instead of forcing a prefix, I > now force no prefix (and reduce the strip level from 1 to 0 when parsing > the diff header). Ah, that approach would also work and may be conceptually cleaner than requiring a/ and b/ prefix and forcing them.
diff --git a/range-diff.c b/range-diff.c index ba1e9a4265..8cc348b4cb 100644 --- a/range-diff.c +++ b/range-diff.c @@ -50,7 +50,8 @@ static int read_patches(const char *range, struct string_list *list) int offset, len; size_t size; - argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges", + argv_array_pushl(&cp.args, "-c", "diff.noprefix=false", + "log", "--no-color", "-p", "--no-merges", "--reverse", "--date-order", "--decorate=no", /* * Choose indicators that are not used anywhere diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index 0120f769f1..64b66f2094 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -461,4 +461,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