line-log: allow non-patch diff formats with -L
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Montalbo committed
May 28, 2026 at 20:47 UTC
4b5d8a0163fe4e9a4ac074f407e0599ba27acf68
3 files changed
+54
-7
Documentation/line-range-options.adoc
+6
-4
@@ -8,12 +8,14 @@
8
give zero or one positive revision arguments, and
9
_<start>_ and _<end>_ (or _<funcname>_) must exist in the starting revision.
10
You can specify this option more than once. Implies `--patch`.
11
- Patch output can be suppressed using `--no-patch`, but other diff formats
12
- (namely `--raw`, `--numstat`, `--shortstat`, `--dirstat`, `--summary`,
13
- `--name-only`, `--name-status`, `--check`) are not currently implemented.
11
+ Patch output can be suppressed using `--no-patch`.
12
+ Non-patch diff formats `--raw`, `--name-only`, `--name-status`,
13
+ and `--summary` are supported. Diff stat formats
14
+ (`--stat`, `--numstat`, `--shortstat`, `--dirstat`) are not
15
+ currently implemented.
16
+
17
Patch formatting options such as `--word-diff`, `--color-moved`,
18
`--no-prefix`, and whitespace options (`-w`, `-b`) are supported,
17
-as are pickaxe options (`-S`, `-G`).
19
+as are pickaxe options (`-S`, `-G`) and `--diff-filter`.
20
+
21
include::line-range-format.adoc[]
revision.c
+3
-1
@@ -3181,7 +3181,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
3181
if (revs->line_level_traverse &&
3182
(revs->full_diff ||
3183
(revs->diffopt.output_format &
3184
- ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT))))
3184
+ ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT |
3185
+ DIFF_FORMAT_RAW | DIFF_FORMAT_NAME |
3186
+ DIFF_FORMAT_NAME_STATUS | DIFF_FORMAT_SUMMARY))))
3187
die(_("-L does not yet support the requested diff format"));
3188
3189
if (revs->expand_tabs_in_log < 0)
t/t4211-line-log.sh
+45
-2
@@ -155,8 +155,45 @@ test_expect_success '-p shows the default patch output' '
155
test_cmp expect actual
156
'
157
158
-test_expect_success '--raw is forbidden' '
159
- test_must_fail git log -L1,24:b.c --raw
158
+test_expect_success '--raw shows mode, oid, status and path' '
159
+ git log -L1,24:b.c --raw --format= >actual &&
160
+ test_grep "^:100644 100644 [0-9a-f]\{7\} [0-9a-f]\{7\} M b.c$" actual &&
161
+ test_grep ! "^diff --git" actual &&
162
+ test_grep ! "^@@" actual
163
+'
164
+
165
+test_expect_success '--name-only shows path' '
166
+ git log -L1,24:b.c --name-only --format= >actual &&
167
+ test_grep "^b.c$" actual &&
168
+ test_grep ! "^diff --git" actual &&
169
+ test_grep ! "^@@" actual
170
+'
171
+
172
+test_expect_success '--name-status shows status and path' '
173
+ git log -L1,24:b.c --name-status --format= >actual &&
174
+ test_grep "^M b.c$" actual &&
175
+ test_grep ! "^diff --git" actual &&
176
+ test_grep ! "^@@" actual
177
+'
178
+
179
+test_expect_success '--stat is not yet supported with -L' '
180
+ test_must_fail git log -L1,24:b.c --stat 2>err &&
181
+ test_grep "does not yet support" err
182
+'
183
+
184
+test_expect_success '--numstat is not yet supported with -L' '
185
+ test_must_fail git log -L1,24:b.c --numstat 2>err &&
186
+ test_grep "does not yet support" err
187
+'
188
+
189
+test_expect_success '--shortstat is not yet supported with -L' '
190
+ test_must_fail git log -L1,24:b.c --shortstat 2>err &&
191
+ test_grep "does not yet support" err
192
+'
193
+
194
+test_expect_success '--dirstat is not yet supported with -L' '
195
+ test_must_fail git log -L1,24:b.c --dirstat 2>err &&
196
+ test_grep "does not yet support" err
197
'
198
199
test_expect_success 'setup for checking fancy rename following' '
@@ -738,4 +775,10 @@ test_expect_success '-L --oneline has no extra blank line before diff' '
775
test_grep "^diff --git" line2
776
'
777
778
+test_expect_success '--summary shows new file on root commit' '
779
+ git checkout parent-oids &&
780
+ git log -L:func2:file.c --summary --format= >actual &&
781
+ test_grep "create mode 100644 file.c" actual
782
+'
783
+
784
test_done