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 4, 2020, 17:54 UTC
Message-ID
<xmqq7dr1nh3a.fsf_-_@gitster.c.googlers.com>
In-Reply-To
<xmqqimamqjhl.fsf@gitster.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
>>> +	if (rev->line_level_traverse) {
>>> +		if (rev->diffopt.filter)
>>> +			die(_("-L<range>:<file> cannot be used with pathspec"));
>>
>> Should this be checking rev->diffopt.pathspec.nr?
>
> Embarrassing but yes ;-).
I wonder if rev->prune_data.nr is what matters here, though.

The prune_data is often identical to diffopt.pathspec, but the former affects the paths that participate in history simplification, while the latter is used when deciding which paths to show differences between the commit and its parent(s) and used to widen the set independently from prune_data for the "--full-diff" option.

-- >8 --
Subject: [PATCH] log: diagnose -L used with pathspec as an error

The -L option is documented to accept no pathspec, but the command line option parser has allowed the combination without checking so far. Ensure that there is no pathspec when the -L option is in effect to fix this.

Incidentally, this change fixes another bug in the command line option parser, which has allowed the -L option used together with the --follow option. Because the latter requires exactly one path given, but the former takes no pathspec, they become mutually incompatible automatically. Because the -L option follows renames on its own, there is no reason to give --follow at the same time.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/log.c       |  3 +++
 t/t4211-line-log.sh | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
diff --git a/builtin/log.c b/builtin/log.c
index 0a7ed4bef9..9d70f3e60b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -206,6 +206,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 	if (argc > 1)
 		die(_("unrecognized argument: %s"), argv[1]);
 
+	if (rev->line_level_traverse && rev->prune_data.nr)
+		die(_("-L<range>:<file> cannot be used with pathspec"));
+
 	memset(&w, 0, sizeof(w));
 	userformat_find_requirements(NULL, &w);
 
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index 2d1d7b5d19..3d1bd6ed80 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -8,6 +8,24 @@ test_expect_success 'setup (import history)' '
 	git reset --hard
 '
 
+# Basic command line option parsing
+test_expect_success '-L is incompatible with pathspec' '
+	# This may fail due to "no such path a.c in commit",
+	# or "-L is incompatible with pathspec". Either is acceptable.
+	test_must_fail git log -L1,1:a.c -- a.c &&
+
+	# This must fail due to "-L is incompatible with pathspec".
+	test_must_fail git log -L1,1:b.c -- b.c &&
+
+	# These must fail due to "follow requires one pathspec".
+	test_must_fail git log -L1,1:b.c --follow &&
+	test_must_fail git log --follow -L1,1:b.c &&
+
+	# This may fail due to "-L is incompatible with pathspec",
+	# or "-L is incompatible with pathspec". Either is acceptable.
+	test_must_fail git log --follow -L1,1:b.c -- b.c
+'
+
 canned_test_1 () {
 	test_expect_$1 "$2" "
 		git log $2 >actual &&
-- 
2.29.2-287-gba574db674
Previous: Junio C HamanoNext: Jeff King
Message 13 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.