From 9f607cd09c4c953d76de4bd18ba1c9bf6cf383cd Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 7 Mar 2019 14:45:15 -0500 Subject: [PATCH 1/2] line-log: suppress diff output with "-s" 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 Signed-off-by: Junio C Hamano --- line-log.c | 6 ++++-- t/t4211-line-log.sh | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/line-log.c b/line-log.c index 24e21731c4..59248e37cc 100644 --- a/line-log.c +++ b/line-log.c @@ -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; } diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh index bd5fe4d148..c9f2036f68 100755 --- a/t/t4211-line-log.sh +++ b/t/t4211-line-log.sh @@ -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 From 05314efaeaa0ae7cb0aa26d6347eabfe7cd8fc43 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 10 Mar 2019 23:54:33 -0400 Subject: [PATCH 2/2] line-log: detect unsupported formats If you use "log -L" with an output format like "--raw" or "--stat", we'll silently ignore the format and just output the normal patch. Let's detect and complain about this, which at least tells the user what's going on. The tests here aren't exhaustive over the set of all formats, but it should at least let us know if somebody breaks the format-checking. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- revision.c | 4 ++++ t/t4211-line-log.sh | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/revision.c b/revision.c index 162d511d46..fc4f33fdd5 100644 --- a/revision.c +++ b/revision.c @@ -2683,6 +2683,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s if (revs->first_parent_only && revs->bisect) die(_("--first-parent is incompatible with --bisect")); + 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")); + if (revs->expand_tabs_in_log < 0) revs->expand_tabs_in_log = revs->expand_tabs_in_log_default; diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh index c9f2036f68..1db7bd0f59 100755 --- a/t/t4211-line-log.sh +++ b/t/t4211-line-log.sh @@ -122,4 +122,14 @@ test_expect_success '-s shows only line-log commits' ' test_cmp expect actual ' +test_expect_success '-p shows the default patch output' ' + git log -L1,24:b.c >expect && + git log -L1,24:b.c -p >actual && + test_cmp expect actual +' + +test_expect_success '--raw is forbidden' ' + test_must_fail git log -L1,24:b.c --raw +' + test_done