git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: Matthew Booth <mbooth@redhat.com>, git@vger.kernel.org
Subject: Re: [PATCH] line-log: suppress diff output with "-s"
Date: Mon, 25 Feb 2019 13:55:19 -0500	[thread overview]
Message-ID: <20190225185519.GA31135@sigill.intra.peff.net> (raw)
In-Reply-To: <20190225175918.GV1622@szeder.dev>

On Mon, Feb 25, 2019 at 06:59:18PM +0100, SZEDER Gábor wrote:

> On Mon, Feb 25, 2019 at 12:32:49PM -0500, Jeff King wrote:
> > diff --git a/line-log.c b/line-log.c
> > index 24e21731c4..863f5cbe0f 100644
> > --- a/line-log.c
> > +++ b/line-log.c
> > @@ -1106,7 +1106,8 @@ int line_log_print(struct rev_info *rev, struct commit *commit)
> >  	struct line_log_data *range = lookup_line_range(rev, commit);
> 
> Note that the result of this lookup_line_range() call is only used
> when we do show the diff below; if we don't, there is no use calling
> it.

Thanks. I think sometimes we can depend on an optimizing compiler to
delay the initialization until use, but in this case the function call
is much too complex to be reordered. Here's a v2 which bumps it down.

-- >8 --
Subject: [PATCH v2] 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 <peff@peff.net>
---
 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
-- 
2.21.0.674.ga8a7ac9a24


  reply	other threads:[~2019-02-25 18:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25 17:03 [BUG] git log -L ... -s does not suppress diff output Matthew Booth
2019-02-25 17:18 ` Jeff King
2019-02-25 17:32   ` [PATCH] line-log: suppress diff output with "-s" Jeff King
2019-02-25 17:59     ` SZEDER Gábor
2019-02-25 18:55       ` Jeff King [this message]
2019-02-25 18:46   ` [BUG] git log -L ... -s does not suppress diff output Randall S. Becker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190225185519.GA31135@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=mbooth@redhat.com \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).