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

Re: Segfault in git when using git logs

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 2, 2020, 18:31 UTC
Message-ID
<xmqqzh3zvce5.fsf@gitster.c.googlers.com>
In-Reply-To
<20201102144321.GA3962443@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 23 quoted lines
> That commit causes the line-log to clear the set of pathspecs, but the
> --follow option requires exactly one pathspec (and it even makes sure
> the user gives us one, but that happens before we clear it internally).
> Something like this makes the segfault go away:
>
> diff --git a/line-log.c b/line-log.c
> index 42c5e41f68..f789863928 100644
> --- a/line-log.c
> +++ b/line-log.c
> @@ -847,6 +847,7 @@ static void queue_diffs(struct line_log_data *range,
>  		clear_pathspec(&opt->pathspec);
>  		parse_pathspec_from_ranges(&opt->pathspec, range);
>  	}
> +	opt->flags.follow_renames = 0;
>  	DIFF_QUEUE_CLEAR(&diff_queued_diff);
>  	diff_tree_oid(parent_tree_oid, tree_oid, "", opt);
>  	if (opt->detect_rename && diff_might_be_rename()) {
>
> but I'm not clear on how "--follow" and "-L" are supposed to interact. I
> wouldn't expect --follow to do anything at all with line-log (nor for it
> to be useful to specify pathspecs outside of the -L option). So possibly
> this is restoring the behavior prior to that commit, or possibly it's
> just papering over a breakage. ;)

Another option is to catch it as "these options are mutually exclusive" error early before the control reaches this deep in the codeflow, I would think, but I suspect that some people may habitually add the "--follow" option in a context where it does not make sense, so "--follow is silently ignored when other options that contradict it is in effect at the same time" is OK by me, too.

I do not know if that is the case offhand, but in the ideal world, I would imagine

	git log -L1,5:hello.c -C -C -- hello.c goodbye.c
	git log -L1,5:hello.c -C -C

to notice and show that some of these five lines were copied when or after hello.c was created, and keep following the origin of them in goodbye.c, and

	git log -L1,5:hello.c -C -C

may do the same or find better match outside goodbye.c for the origin of these lines and follow them instead, while

	git log -L1,5:hello.c -- hello.c
	git log -L1,5:hello.c --no-renames

in the same history may say the commit that actually copied these lines from goodbye.c just added them directly to hello.c instead.

And to extend the imagination a bit more,
	git log -M -L1,5:hello.c
	git log -L1,5:hello.c
	git log --follow -L1,5:hello.c

in a different history may notice that hello.c was created wholesale by renaming hola.c and follow the changes to these five lines down the history. As -M is in effect by default these days, the first two would be equivalent, and "--follow" would be a meaningless noiseword in the context of this example where we are interested only in a single path hello.c in the end result, but in the ideal world, meaningless noiseword should become hardless no-op, I would think.

Of course, the above assumes that -L plays well with the -M/-C/--follow options and pathspec. If not, then "they are incompatible" would be the more sensible and easy-to-explain option.

Thanks.
Previous: Jeff KingNext: SZEDER Gábor
Message 3 of 23 in “Segfault in git when using git logs”
  1. Sathyajith BhatNov 2, 2020
  2. Jeff KingNov 2, 2020
  3. Junio C HamanoNov 2, 2020
  4. SZEDER GáborNov 3, 2020
  5. Christian CouderNov 3, 2020
  6. Elijah NewrenNov 3, 2020
  7. Jeff KingNov 3, 2020
  8. Junio C HamanoNov 3, 2020
  9. Jeff KingNov 3, 2020
  10. Junio C HamanoNov 3, 2020
  11. Jeff KingNov 4, 2020
  12. Junio C HamanoNov 4, 2020
  13. Re*: Segfault in git when using git logsJunio C Hamano, Nov 4, 2020
  14. Jeff KingNov 4, 2020
  15. Junio C HamanoNov 4, 2020
  16. log: diagnose -L used with pathspec as an errorJunio C Hamano, Nov 4, 2020
  17. Jeff KingNov 4, 2020
  18. Derrick StoleeNov 3, 2020
  19. Sathyajith BhatNov 3, 2020
  20. Jeff KingNov 3, 2020
  21. Derrick StoleeNov 3, 2020
  22. Derrick StoleeNov 3, 2020
  23. Sathyajith BhatNov 4, 2020

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.