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

[PATCH 3/3] line-log: allow non-patch diff formats with -L

From
Michael Montalbo via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 28, 2026, 04:05 UTC
Message-ID
<06c24b416f55f43d5d05340130180176ee8029f0.1777349126.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2094.git.1777349126.gitgitgadget@gmail.com>
From: Michael Montalbo <mmontalbo@gmail.com>

Now that -L flows through log_tree_diff_flush() and diff_flush(), metadata-only diff formats work because they only read filepair fields (status, mode, path, oid) already set on the pre-computed pairs.

Expand the allowlist in setup_revisions() to also accept --raw, --name-only, --name-status, and --summary. Diff stat formats (--stat, --numstat, --shortstat, --dirstat) remain blocked because they call compute_diffstat() on full blob content and would show whole-file statistics rather than range-scoped ones.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
---
 Documentation/line-range-options.adoc | 10 +++---
 revision.c                            |  7 ++--
 t/t4211-line-log.sh                   | 47 +++++++++++++++++++++++++--
 3 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/Documentation/line-range-options.adoc b/Documentation/line-range-options.adoc
index ecb2c79fb9..72f639b5e7 100644
--- a/Documentation/line-range-options.adoc
+++ b/Documentation/line-range-options.adoc
@@ -8,12 +8,14 @@
 	give zero or one positive revision arguments, and
 	_<start>_ and _<end>_ (or _<funcname>_) must exist in the starting revision.
 	You can specify this option more than once. Implies `--patch`.
-	Patch output can be suppressed using `--no-patch`, but other diff formats
-	(namely `--raw`, `--numstat`, `--shortstat`, `--dirstat`, `--summary`,
-	`--name-only`, `--name-status`, `--check`) are not currently implemented.
+	Patch output can be suppressed using `--no-patch`.
+	Non-patch diff formats `--raw`, `--name-only`, `--name-status`,
+	and `--summary` are supported.  Diff stat formats
+	(`--stat`, `--numstat`, `--shortstat`, `--dirstat`) are not
+	currently implemented.
 +
 Patch formatting options such as `--word-diff`, `--color-moved`,
 `--no-prefix`, and whitespace options (`-w`, `-b`) are supported,
-as are pickaxe options (`-S`, `-G`).
+as are pickaxe options (`-S`, `-G`) and `--diff-filter`.
 +
 include::line-range-format.adoc[]
diff --git a/revision.c b/revision.c
index a1c795de96..b41ec4016b 100644
--- a/revision.c
+++ b/revision.c
@@ -3179,8 +3179,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 		die(_("the option '%s' requires '%s'"), "--grep-reflog", "--walk-reflogs");
 
 	if (revs->line_level_traverse &&
-	    (revs->diffopt.output_format & ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT)))
-		die(_("-L does not yet support diff formats besides -p and -s"));
+	    (revs->diffopt.output_format &
+	     ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT |
+	       DIFF_FORMAT_RAW | DIFF_FORMAT_NAME |
+	       DIFF_FORMAT_NAME_STATUS | DIFF_FORMAT_SUMMARY)))
+		die(_("-L does not yet support the requested diff format"));
 	if (revs->line_level_traverse && revs->full_diff)
 		die(_("-L is not compatible with --full-diff"));
 
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index 1d566ea9bd..63cf8e5d9f 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -155,8 +155,45 @@ test_expect_success '-p shows the default patch output' '
 	test_cmp expect actual
 '
 
-test_expect_success '--raw is forbidden' '
-	test_must_fail git log -L1,24:b.c --raw
+test_expect_success '--raw shows mode, oid, status and path' '
+	git log -L1,24:b.c --raw --format= >actual &&
+	grep "^:100644 100644 [0-9a-f]\{7\} [0-9a-f]\{7\} M	b.c$" actual &&
+	! grep "^diff --git" actual &&
+	! grep "^@@" actual
+'
+
+test_expect_success '--name-only shows path' '
+	git log -L1,24:b.c --name-only --format= >actual &&
+	grep "^b.c$" actual &&
+	! grep "^diff --git" actual &&
+	! grep "^@@" actual
+'
+
+test_expect_success '--name-status shows status and path' '
+	git log -L1,24:b.c --name-status --format= >actual &&
+	grep "^M	b.c$" actual &&
+	! grep "^diff --git" actual &&
+	! grep "^@@" actual
+'
+
+test_expect_success '--stat is not yet supported with -L' '
+	test_must_fail git log -L1,24:b.c --stat 2>err &&
+	test_grep "does not yet support" err
+'
+
+test_expect_success '--numstat is not yet supported with -L' '
+	test_must_fail git log -L1,24:b.c --numstat 2>err &&
+	test_grep "does not yet support" err
+'
+
+test_expect_success '--shortstat is not yet supported with -L' '
+	test_must_fail git log -L1,24:b.c --shortstat 2>err &&
+	test_grep "does not yet support" err
+'
+
+test_expect_success '--dirstat is not yet supported with -L' '
+	test_must_fail git log -L1,24:b.c --dirstat 2>err &&
+	test_grep "does not yet support" err
 '
 
 test_expect_success 'setup for checking fancy rename following' '
@@ -737,4 +774,10 @@ test_expect_success '-L --oneline has no extra blank line before diff' '
 	sed -n 2p actual | grep "^diff --git"
 '
 
+test_expect_success '--summary shows new file on root commit' '
+	git checkout parent-oids &&
+	git log -L:func2:file.c --summary --format= >actual &&
+	grep "create mode 100644 file.c" actual
+'
+
 test_done
-- 
gitgitgadget
Previous: Michael Montalbo via GitGitGadgetNext: Junio C Hamano
Message 4 of 20 in “line-log: integrate -L with the standard log output pipeline”
  1. 0/3 line-log: integrate -L with the standard log output pipelineMichael Montalbo via GitGitGadget, Apr 28, 2026
  2. 1/3 revision: move -L setup before output_format-to-diff derivationMichael Montalbo via GitGitGadget, Apr 28, 2026
  3. 2/3 line-log: integrate -L output with the standard log-tree pipelineMichael Montalbo via GitGitGadget, Apr 28, 2026
  4. 3/3 line-log: allow non-patch diff formats with -LMichael Montalbo via GitGitGadget, Apr 28, 2026
  5. Junio C HamanoMay 12, 2026
  6. D. Ben KnobleMay 22, 2026
  7. 0/3 line-log: integrate -L with the standard log output pipelineMichael Montalbo via GitGitGadget, May 25, 2026
  8. 1/3 revision: move -L setup before output_format-to-diff derivationMichael Montalbo via GitGitGadget, May 25, 2026
  9. 2/3 line-log: integrate -L output with the standard log-tree pipelineMichael Montalbo via GitGitGadget, May 25, 2026
  10. 3/3 line-log: allow non-patch diff formats with -LMichael Montalbo via GitGitGadget, May 25, 2026
  11. D. Ben KnobleMay 27, 2026
  12. Junio C HamanoMay 28, 2026
  13. Michael MontalboMay 28, 2026
  14. 0/3 line-log: integrate -L with the standard log output pipelineMichael Montalbo via GitGitGadget, May 28, 2026
  15. 1/3 revision: move -L setup before output_format-to-diff derivationMichael Montalbo via GitGitGadget, May 28, 2026
  16. 2/3 line-log: integrate -L output with the standard log-tree pipelineMichael Montalbo via GitGitGadget, May 28, 2026
  17. 3/3 line-log: allow non-patch diff formats with -LMichael Montalbo via GitGitGadget, May 28, 2026
  18. Ben KnobleMay 29, 2026
  19. Junio C HamanoJun 1, 2026
  20. Michael MontalboMay 24, 2026

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.