git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Regression in v2.23

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 8, 2019, 07:49 UTC
Message-ID
<nycvar.QRO.7.76.6.1910080947070.46@tvgsbejvaqbjf.bet>
In-Reply-To
<nycvar.QRO.7.76.6.1910080932560.46@tvgsbejvaqbjf.bet>
Hi Thomas,
On Tue, 8 Oct 2019, Johannes Schindelin wrote:
Show 56 quoted lines
> On Mon, 7 Oct 2019, Thomas Gummerer wrote:
>
> > Subject: [PATCH] range-diff: don't segfault with mode-only changes
> >
> > If we don't have a new file, deleted file or renamed file in a diff,
> > we currently add 'patch.new_name' to the range-diff header.  This
> > works well for files that are changed.  However if we have a pure mode
> > change, 'patch.new_name' is NULL, and thus range-diff segfaults.
> >
> > We can however rely on 'patch.def_name' in that case, which is
> > extracted from the 'diff --git' line and should be equal to
> > 'patch.new_name'.  Use that instead to avoid the segfault.
> >
> > Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
> > ---
> >  range-diff.c | 20 ++++++++++----------
> >  1 file changed, 10 insertions(+), 10 deletions(-)
> >
> > diff --git a/range-diff.c b/range-diff.c
> > index ba1e9a4265..d8d906b3c6 100644
> > --- a/range-diff.c
> > +++ b/range-diff.c
> > @@ -116,20 +116,20 @@ static int read_patches(const char *range, struct string_list *list)
> >  			if (len < 0)
> >  				die(_("could not parse git header '%.*s'"), (int)len, line);
> >  			strbuf_addstr(&buf, " ## ");
> > -			if (patch.is_new > 0)
> > +			free(current_filename);
> > +			if (patch.is_new > 0) {
> >  				strbuf_addf(&buf, "%s (new)", patch.new_name);
> > -			else if (patch.is_delete > 0)
> > +				current_filename = xstrdup(patch.new_name);
> > +			} else if (patch.is_delete > 0) {
> >  				strbuf_addf(&buf, "%s (deleted)", patch.old_name);
> > -			else if (patch.is_rename)
> > -				strbuf_addf(&buf, "%s => %s", patch.old_name, patch.new_name);
> > -			else
> > -				strbuf_addstr(&buf, patch.new_name);
> > -
> > -			free(current_filename);
> > -			if (patch.is_delete > 0)
> >  				current_filename = xstrdup(patch.old_name);
> > -			else
> > +			} else if (patch.is_rename) {
> > +				strbuf_addf(&buf, "%s => %s", patch.old_name, patch.new_name);
> >  				current_filename = xstrdup(patch.new_name);
> > +			} else {
> > +				strbuf_addstr(&buf, patch.def_name);
> > +				current_filename = xstrdup(patch.def_name);
> > +			}
> >
> >  			if (patch.new_mode && patch.old_mode &&
> >  			    patch.old_mode != patch.new_mode)
> > --
>
> I am not quite sure that this fixes it...

Whoops. I should learn to distrust `git apply` claiming success when running in `t/`. (I tried to apply your patch, but nothing was actually applied before I ran `make`.)

So it totally fixes the issue (feel free to just pick up the regression test case).

Having said that, I would agree with Junio that it'd be nicer to make `parse_git_diff_header()` more useful to all of its callers, including future ones.

Sorry for the misreport, and thanks for all the patch, Dscho

Show 29 quoted lines
> Here is my regression test case:
>
> -- snipsnap --
> diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
> index ec548654ce1..6aca7f5a5b1 100755
> --- a/t/t3206-range-diff.sh
> +++ b/t/t3206-range-diff.sh
> @@ -354,4 +354,18 @@ test_expect_success 'format-patch --range-diff as commentary' '
>  	grep "> 1: .* new message" 0001-*
>  '
>
> +test_expect_success 'range-diff and mode-only changes' '
> +	git switch -c mode-only &&
> +
> +	test_commit mode-only &&
> +
> +	: pretend it is executable &&
> +	git add --chmod=+x mode-only.t &&
> +	chmod a+x mode-only.t &&
> +	test_tick &&
> +	git commit -m mode-only &&
> +
> +	git range-diff @^...
> +'
> +
>  test_done
>
>
>
Previous: Johannes SchindelinNext: Thomas Gummerer
Message 7 of 10 in “Regression in v2.23”
  1. Uwe Kleine-KönigOct 7, 2019
  2. Thomas GummererOct 7, 2019
  3. Junio C HamanoOct 8, 2019
  4. Johannes SchindelinOct 8, 2019
  5. Uwe Kleine-KönigOct 8, 2019
  6. Johannes SchindelinOct 8, 2019
  7. Johannes SchindelinOct 8, 2019
  8. range-diff: don't segfault with mode-only changesThomas Gummerer, Oct 8, 2019
  9. Johannes SchindelinOct 8, 2019
  10. Uwe Kleine-KönigOct 9, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.