line-log: suppress diff output with "-s"
authorJeff King <peff@peff.net>
Thu, 7 Mar 2019 19:45:15 +0000 (14:45 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Mar 2019 01:27:01 +0000 (10:27 +0900)
When "-L" is in use, we ignore any diff output format that the user
provides to us, and just always print a patch (with extra context lines
covering the whole area of interest). It's not entirely clear what we
should do with all formats (e.g., should "--stat" show just the diffstat
of the touched lines, or the stat for the whole file?).

But "-s" is pretty clear: the user probably wants to see just the
commits that touched those lines, without any diff at all. Let's at
least make that work.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
line-log.c
t/t4211-line-log.sh
index 24e21731c4315f414578b33178a7b784176bb24d..59248e37cc3cec8fd309df77fb58b09c8612f336 100644 (file)
@@ -1103,10 +1103,12 @@ static int process_all_files(struct line_log_data **range_out,
 
 int line_log_print(struct rev_info *rev, struct commit *commit)
 {
-       struct line_log_data *range = lookup_line_range(rev, commit);
 
        show_log(rev);
-       dump_diff_hacky(rev, range);
+       if (!(rev->diffopt.output_format & DIFF_FORMAT_NO_OUTPUT)) {
+               struct line_log_data *range = lookup_line_range(rev, commit);
+               dump_diff_hacky(rev, range);
+       }
        return 1;
 }
 
index bd5fe4d1483005175d9c2211dee1901c2b132573..c9f2036f6881467a727104d62d126594b08aab8b 100755 (executable)
@@ -115,4 +115,11 @@ test_expect_success 'range_set_union' '
        git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c; done)
 '
 
+test_expect_success '-s shows only line-log commits' '
+       git log --format="commit %s" -L1,24:b.c >expect.raw &&
+       grep ^commit expect.raw >expect &&
+       git log --format="commit %s" -L1,24:b.c -s >actual &&
+       test_cmp expect actual
+'
+
 test_done