]> git.ipfire.org Git - thirdparty/git.git/commitdiff
line-log: allow non-patch diff formats with -L
authorMichael Montalbo <mmontalbo@gmail.com>
Mon, 25 May 2026 19:40:58 +0000 (19:40 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 May 2026 22:57:50 +0000 (07:57 +0900)
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>
Documentation/line-range-options.adoc
revision.c
t/t4211-line-log.sh

index ecb2c79fb9bde86d199a1cc7fffb0f13920e7f81..72f639b5e79ea4d15ea0e0b71ce86eadbb80dba4 100644 (file)
@@ -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[]
index c903f7a1b4c4c8fe80d3574a7829042b5e0d6f34..f26fc1f4d5e48e244768cd44e4337f10ea84d845 100644 (file)
@@ -3181,7 +3181,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
        if (revs->line_level_traverse &&
            (revs->full_diff ||
             (revs->diffopt.output_format &
-             ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT))))
+             ~(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->expand_tabs_in_log < 0)
index e3937138a94055fbfec5d1ebf4cfa95c9d4543e5..4722ec3e2917559e1eba2d504dd361ad2ac2ce1c 100755 (executable)
@@ -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 &&
+       test_grep "^:100644 100644 [0-9a-f]\{7\} [0-9a-f]\{7\} M        b.c$" actual &&
+       ! test_grep "^diff --git" actual &&
+       ! test_grep "^@@" actual
+'
+
+test_expect_success '--name-only shows path' '
+       git log -L1,24:b.c --name-only --format= >actual &&
+       test_grep "^b.c$" actual &&
+       ! test_grep "^diff --git" actual &&
+       ! test_grep "^@@" actual
+'
+
+test_expect_success '--name-status shows status and path' '
+       git log -L1,24:b.c --name-status --format= >actual &&
+       test_grep "^M   b.c$" actual &&
+       ! test_grep "^diff --git" actual &&
+       ! test_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' '
@@ -738,4 +775,10 @@ test_expect_success '-L --oneline has no extra blank line before diff' '
        test_grep "^diff --git" line2
 '
 
+test_expect_success '--summary shows new file on root commit' '
+       git checkout parent-oids &&
+       git log -L:func2:file.c --summary --format= >actual &&
+       test_grep "create mode 100644 file.c" actual
+'
+
 test_done