Skip to content

Commit 151ccc5

Browse files
committed
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, --summary, and --check. 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. Also reject --full-diff, which is meaningless with -L: the filepairs are pre-computed during the history walk and scoped to tracked paths, so there is no tree diff to widen. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
1 parent d7c86b6 commit 151ccc5

3 files changed

Lines changed: 88 additions & 7 deletions

File tree

Documentation/line-range-options.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
give zero or one positive revision arguments, and
99
_<start>_ and _<end>_ (or _<funcname>_) must exist in the starting revision.
1010
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+
`--summary`, and `--check` are supported; diff stat formats
14+
(`--stat`, `--numstat`, `--shortstat`, `--dirstat`) are not
15+
currently implemented.
1416
+
1517
Patch formatting options such as `--word-diff`, `--color-moved`,
1618
`--no-prefix`, and whitespace options (`-w`, `-b`) are supported,

revision.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,8 +3179,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
31793179
die(_("the option '%s' requires '%s'"), "--grep-reflog", "--walk-reflogs");
31803180

31813181
if (revs->line_level_traverse &&
3182-
(revs->diffopt.output_format & ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT)))
3183-
die(_("-L does not yet support diff formats besides -p and -s"));
3182+
(revs->diffopt.output_format &
3183+
~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT |
3184+
DIFF_FORMAT_RAW | DIFF_FORMAT_NAME |
3185+
DIFF_FORMAT_NAME_STATUS | DIFF_FORMAT_SUMMARY |
3186+
DIFF_FORMAT_CHECKDIFF)))
3187+
die(_("-L does not yet support diff stat formats "
3188+
"(--stat, --numstat, --shortstat, --dirstat)"));
3189+
if (revs->line_level_traverse && revs->full_diff)
3190+
die(_("-L is not compatible with --full-diff"));
31843191

31853192
if (revs->expand_tabs_in_log < 0)
31863193
revs->expand_tabs_in_log = revs->expand_tabs_in_log_default;

t/t4211-line-log.sh

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,35 @@ test_expect_success '-p shows the default patch output' '
155155
test_cmp expect actual
156156
'
157157

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+
grep "^:100644 100644 [0-9a-f]\{7\} [0-9a-f]\{7\} M b.c$" actual &&
161+
! grep "^diff --git" actual &&
162+
! grep "^@@" actual
163+
'
164+
165+
test_expect_success '--name-only shows path' '
166+
git log -L1,24:b.c --name-only --format= >actual &&
167+
grep "^b.c$" actual &&
168+
! grep "^diff --git" actual &&
169+
! 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+
grep "^M b.c$" actual &&
175+
! grep "^diff --git" actual &&
176+
! 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 '--full-diff is not supported with -L' '
185+
test_must_fail git log -L1,24:b.c --full-diff 2>err &&
186+
test_grep "not compatible with --full-diff" err
160187
'
161188

162189
test_expect_success 'setup for checking fancy rename following' '
@@ -725,4 +752,49 @@ test_expect_success '-L with -S suppresses non-matching commits' '
725752
test_cmp expect actual
726753
'
727754

755+
test_expect_success '--summary shows new file on root commit' '
756+
git checkout parent-oids &&
757+
git log -L:func2:file.c --summary --format= >actual &&
758+
grep "create mode 100644 file.c" actual
759+
'
760+
761+
test_expect_success 'setup for --check test' '
762+
git checkout --orphan check-test &&
763+
git reset --hard &&
764+
cat >check.c <<-\EOF &&
765+
void tracked()
766+
{
767+
return;
768+
}
769+
770+
void other()
771+
{
772+
return;
773+
}
774+
EOF
775+
git add check.c &&
776+
test_tick &&
777+
git commit -m "add check.c" &&
778+
# Introduce trailing whitespace errors in both functions
779+
sed "s/return;/return; /" check.c >check.c.tmp &&
780+
mv check.c.tmp check.c &&
781+
git commit -a -m "introduce trailing whitespace"
782+
'
783+
784+
test_expect_success '--check reports whitespace errors in tracked range' '
785+
test_must_fail git log -L:tracked:check.c --check --format= >actual &&
786+
grep "trailing whitespace" actual
787+
'
788+
789+
# --check currently examines the entire file diff, not just the tracked
790+
# range. Scoping --check to line_ranges would require threading range
791+
# filtering into run_checkdiff(), similar to how builtin_diff() filters
792+
# patch output.
793+
test_expect_failure '--check should not report errors outside tracked range' '
794+
test_must_fail git log -L:tracked:check.c --check --format= >actual &&
795+
# line 3 is inside tracked(), line 8 is inside other()
796+
grep "check.c:3" actual &&
797+
! grep "check.c:8" actual
798+
'
799+
728800
test_done

0 commit comments

Comments
 (0)