git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH v2] line-log: suppress diff output with "-s"
@ 2019-03-07 19:45 Jeff King
  2019-03-08 15:38 ` Johannes Schindelin
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2019-03-07 19:45 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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>
---
This is a repost from the thread at:

  https://public-inbox.org/git/CAEkQehdFu5zM4AY3ihN0pn1aCNEomY0WV07pryfAB45JN-tDDA@mail.gmail.com/

 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.787.g929e938557

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] line-log: suppress diff output with "-s"
  2019-03-07 19:45 [PATCH v2] line-log: suppress diff output with "-s" Jeff King
@ 2019-03-08 15:38 ` Johannes Schindelin
  2019-03-08 16:20   ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Schindelin @ 2019-03-08 15:38 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Junio C Hamano

Hi Peff,

On Thu, 7 Mar 2019, Jeff King wrote:

> 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.

Agree. The patch looks obviously good.

Thank you,
Dscho

> 
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> This is a repost from the thread at:
> 
>   https://public-inbox.org/git/CAEkQehdFu5zM4AY3ihN0pn1aCNEomY0WV07pryfAB45JN-tDDA@mail.gmail.com/
> 
>  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.787.g929e938557
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] line-log: suppress diff output with "-s"
  2019-03-08 15:38 ` Johannes Schindelin
@ 2019-03-08 16:20   ` Jeff King
  2019-03-08 18:44     ` Johannes Schindelin
  2019-03-11  1:49     ` Junio C Hamano
  0 siblings, 2 replies; 6+ messages in thread
From: Jeff King @ 2019-03-08 16:20 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, Junio C Hamano

On Fri, Mar 08, 2019 at 04:38:44PM +0100, Johannes Schindelin wrote:

> On Thu, 7 Mar 2019, Jeff King wrote:
> 
> > 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.
> 
> Agree. The patch looks obviously good.

Thanks. This leaves the other formats as silently ignored. Do we want to
do something like this:

diff --git a/revision.c b/revision.c
index eb8e51bc63..a1b4fe2aa6 100644
--- a/revision.c
+++ b/revision.c
@@ -2689,6 +2689,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;
 

?

-Peff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] line-log: suppress diff output with "-s"
  2019-03-08 16:20   ` Jeff King
@ 2019-03-08 18:44     ` Johannes Schindelin
  2019-03-11  3:54       ` Jeff King
  2019-03-11  1:49     ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: Johannes Schindelin @ 2019-03-08 18:44 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Junio C Hamano

Hi Peff,

On Fri, 8 Mar 2019, Jeff King wrote:

> On Fri, Mar 08, 2019 at 04:38:44PM +0100, Johannes Schindelin wrote:
> 
> > On Thu, 7 Mar 2019, Jeff King wrote:
> > 
> > > 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.
> > 
> > Agree. The patch looks obviously good.
> 
> Thanks. This leaves the other formats as silently ignored.

I'd be fine with that... but...

> Do we want to do something like this:
> 
> diff --git a/revision.c b/revision.c
> index eb8e51bc63..a1b4fe2aa6 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -2689,6 +2689,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;

Since you already have that patch, why not go wild and apply it, too? ;-)

I guess you copy-edited the code from somewhere because you usually do
leave spaces around the `|`... I don't care, though ;-)

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] line-log: suppress diff output with "-s"
  2019-03-08 16:20   ` Jeff King
  2019-03-08 18:44     ` Johannes Schindelin
@ 2019-03-11  1:49     ` Junio C Hamano
  1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2019-03-11  1:49 UTC (permalink / raw)
  To: Jeff King; +Cc: Johannes Schindelin, git

Jeff King <peff@peff.net> writes:

> On Fri, Mar 08, 2019 at 04:38:44PM +0100, Johannes Schindelin wrote:
>
>> On Thu, 7 Mar 2019, Jeff King wrote:
>> 
>> > 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.
>> 
>> Agree. The patch looks obviously good.
>
> Thanks. This leaves the other formats as silently ignored. Do we want to
> do something like this:

It probably would make sense to do this if only to avoid surprises.

>
> diff --git a/revision.c b/revision.c
> index eb8e51bc63..a1b4fe2aa6 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -2689,6 +2689,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;
>  
>
> ?
>
> -Peff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] line-log: suppress diff output with "-s"
  2019-03-08 18:44     ` Johannes Schindelin
@ 2019-03-11  3:54       ` Jeff King
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2019-03-11  3:54 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, Junio C Hamano

On Fri, Mar 08, 2019 at 07:44:22PM +0100, Johannes Schindelin wrote:

> > Do we want to do something like this:
> > 
> > diff --git a/revision.c b/revision.c
> > index eb8e51bc63..a1b4fe2aa6 100644
> > --- a/revision.c
> > +++ b/revision.c
> > @@ -2689,6 +2689,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;
> 
> Since you already have that patch, why not go wild and apply it, too? ;-)

OK, then. Here it is as a real patch.

> I guess you copy-edited the code from somewhere because you usually do
> leave spaces around the `|`... I don't care, though ;-)

Heh, nope, I wrote it by hand.

I actually wondered if there was a better way to write this. One of the
things that bugs me about the patch is that this policy check is so far
from actual line-log code, which means the two may drift apart over
time. We could put a LINE_LOG_SUPPORTED_FORMATS into line-log.h, but
that's also pretty far from the actual code. We could just make the
output logic in the line-log code something like:

  if (NO_OUTPUT)
	...do no output...
  else if (PATCH || DEFAULT)
        ...show normal patch...
  else
	die("unsupported output format");

but it's probably a little friendlier to diagnose the problem up front,
not after we did a bunch of computation.  And most of these other
"incompatible" checks in setup_revisions() suffer from the same
maintainability problem. So instead, I went with the code above (with
spaces!) and protected it with some tests.

-- >8 --
Subject: [PATCH] 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 <peff@peff.net>
---
On top of the other patch, naturally.

 revision.c          |  4 ++++
 t/t4211-line-log.sh | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/revision.c b/revision.c
index eb8e51bc63..cb69a227d5 100644
--- a/revision.c
+++ b/revision.c
@@ -2689,6 +2689,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
-- 
2.21.0.787.gbeacff058d


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-03-11  3:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-07 19:45 [PATCH v2] line-log: suppress diff output with "-s" Jeff King
2019-03-08 15:38 ` Johannes Schindelin
2019-03-08 16:20   ` Jeff King
2019-03-08 18:44     ` Johannes Schindelin
2019-03-11  3:54       ` Jeff King
2019-03-11  1:49     ` Junio C Hamano

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git