* [BUG] git log -L ... -s does not suppress diff output @ 2019-02-25 17:03 Matthew Booth 2019-02-25 17:18 ` Jeff King 0 siblings, 1 reply; 6+ messages in thread From: Matthew Booth @ 2019-02-25 17:03 UTC (permalink / raw) To: git Example output: ========= $ git --version git version 2.20.1 $ git log -L 2957,3107:nova/compute/manager.py -s commit 35ce77835bb271bad3c18eaf22146edac3a42ea0 <snip> diff --git a/nova/compute/manager.py b/nova/compute/manager.py --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2937,152 +2921,151 @@ def rebuild_instance(self, context, instance, orig_image_ref, image_ref, injected_files, new_pass, orig_sys_metadata, <snip> ========= git log docs suggest it should not do this: -s, --no-patch Suppress diff output. Useful for commands like git show that show the patch by default, or to cancel the effect of --patch. Couldn't find anything in a search of the archives of this mailing list, although that's obviously far from conclusive. Seems to be longstanding, as it was mentioned on StackOverflow back in 2015: https://stackoverflow.com/questions/31709785/git-line-log-git-l-suppress-diff Matt -- Matthew Booth Red Hat OpenStack Engineer, Compute DFG Phone: +442070094448 (UK) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [BUG] git log -L ... -s does not suppress diff output 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 18:46 ` [BUG] git log -L ... -s does not suppress diff output Randall S. Becker 0 siblings, 2 replies; 6+ messages in thread From: Jeff King @ 2019-02-25 17:18 UTC (permalink / raw) To: Matthew Booth; +Cc: git On Mon, Feb 25, 2019 at 05:03:50PM +0000, Matthew Booth wrote: > Example output: > > ========= > $ git --version > git version 2.20.1 > > $ git log -L 2957,3107:nova/compute/manager.py -s > commit 35ce77835bb271bad3c18eaf22146edac3a42ea0 > <snip> > > diff --git a/nova/compute/manager.py b/nova/compute/manager.py > --- a/nova/compute/manager.py > +++ b/nova/compute/manager.py > @@ -2937,152 +2921,151 @@ > def rebuild_instance(self, context, instance, orig_image_ref, image_ref, > injected_files, new_pass, orig_sys_metadata, > <snip> > ========= At first I wondered why you would want to do this, since the point of -L is to walk through that diff. But I suppose you might want to see just the commits, without the actual patch, and that's what "-s" ought to do. > git log docs suggest it should not do this: > > -s, --no-patch > Suppress diff output. Useful for commands like git show > that show the patch by default, or to cancel > the effect of --patch. > > Couldn't find anything in a search of the archives of this mailing > list, although that's obviously far from conclusive. Seems to be > longstanding, as it was mentioned on StackOverflow back in 2015: I think the issue is just that "-L" follows a very different code path than the normal diff generator. Perhaps something like this helps? diff --git a/line-log.c b/line-log.c index 63df51a08f..ed46a3a493 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); show_log(rev); - dump_diff_hacky(rev, range); + if (!(rev->diffopt.output_format & DIFF_FORMAT_NO_OUTPUT)) + dump_diff_hacky(rev, range); return 1; } -Peff ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] line-log: suppress diff output with "-s" 2019-02-25 17:18 ` Jeff King @ 2019-02-25 17:32 ` Jeff King 2019-02-25 17:59 ` SZEDER Gábor 2019-02-25 18:46 ` [BUG] git log -L ... -s does not suppress diff output Randall S. Becker 1 sibling, 1 reply; 6+ messages in thread From: Jeff King @ 2019-02-25 17:32 UTC (permalink / raw) To: Matthew Booth; +Cc: git On Mon, Feb 25, 2019 at 12:18:17PM -0500, Jeff King wrote: > > git log docs suggest it should not do this: > > > > -s, --no-patch > > Suppress diff output. Useful for commands like git show > > that show the patch by default, or to cancel > > the effect of --patch. > > > > Couldn't find anything in a search of the archives of this mailing > > list, although that's obviously far from conclusive. Seems to be > > longstanding, as it was mentioned on StackOverflow back in 2015: > > I think the issue is just that "-L" follows a very different code path > than the normal diff generator. Perhaps something like this helps? Here it is with a test and a commit message (I don't think any doc update is necessary; as you noted, the docs already imply this is what should happen). -- >8 -- Subject: [PATCH] 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> --- This punts completely on the larger question of what should happen with other formats like "--stat", "--raw", etc. They'll continue to be ignored entirely and we'll generate the line-log patch. Possibly we should detect and complain? line-log.c | 3 ++- t/t4211-line-log.sh | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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); show_log(rev); - dump_diff_hacky(rev, range); + if (!(rev->diffopt.output_format & DIFF_FORMAT_NO_OUTPUT)) + 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.672.g12e864cee7 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] line-log: suppress diff output with "-s" 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 0 siblings, 1 reply; 6+ messages in thread From: SZEDER Gábor @ 2019-02-25 17:59 UTC (permalink / raw) To: Jeff King; +Cc: Matthew Booth, git 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. > show_log(rev); > - dump_diff_hacky(rev, range); > + if (!(rev->diffopt.output_format & DIFF_FORMAT_NO_OUTPUT)) > + dump_diff_hacky(rev, range); > return 1; > } > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] line-log: suppress diff output with "-s" 2019-02-25 17:59 ` SZEDER Gábor @ 2019-02-25 18:55 ` Jeff King 0 siblings, 0 replies; 6+ messages in thread From: Jeff King @ 2019-02-25 18:55 UTC (permalink / raw) To: SZEDER Gábor; +Cc: Matthew Booth, git 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 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* RE: [BUG] git log -L ... -s does not suppress diff output 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 18:46 ` Randall S. Becker 1 sibling, 0 replies; 6+ messages in thread From: Randall S. Becker @ 2019-02-25 18:46 UTC (permalink / raw) To: 'Jeff King', 'Matthew Booth'; +Cc: git On February 25, 2019 12:18, Jeff King wrote: > To: Matthew Booth <mbooth@redhat.com> > Cc: git@vger.kernel.org > Subject: Re: [BUG] git log -L ... -s does not suppress diff output > > On Mon, Feb 25, 2019 at 05:03:50PM +0000, Matthew Booth wrote: > > > Example output: > > > > ========= > > $ git --version > > git version 2.20.1 > > > > $ git log -L 2957,3107:nova/compute/manager.py -s commit > > 35ce77835bb271bad3c18eaf22146edac3a42ea0 > > <snip> > > > > diff --git a/nova/compute/manager.py b/nova/compute/manager.py > > --- a/nova/compute/manager.py > > +++ b/nova/compute/manager.py > > @@ -2937,152 +2921,151 @@ > > def rebuild_instance(self, context, instance, orig_image_ref, image_ref, > > injected_files, new_pass, orig_sys_metadata, > > <snip> ========= > > At first I wondered why you would want to do this, since the point of -L is to > walk through that diff. But I suppose you might want to see just the commits, > without the actual patch, and that's what "-s" ought to do. > > > git log docs suggest it should not do this: > > > > -s, --no-patch > > Suppress diff output. Useful for commands like git show > > that show the patch by default, or to cancel > > the effect of --patch. > > > > Couldn't find anything in a search of the archives of this mailing > > list, although that's obviously far from conclusive. Seems to be > > longstanding, as it was mentioned on StackOverflow back in 2015: > > I think the issue is just that "-L" follows a very different code path than the > normal diff generator. Perhaps something like this helps? > > diff --git a/line-log.c b/line-log.c > index 63df51a08f..ed46a3a493 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); > > show_log(rev); > - dump_diff_hacky(rev, range); > + if (!(rev->diffopt.output_format & DIFF_FORMAT_NO_OUTPUT)) > + dump_diff_hacky(rev, range); > return 1; > } I hit this about 6 months ago while trying to show off git to some colleagues - it was on 2.8.5. Sadly I forgot about it. Glad it came back. Thanks. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-02-25 18:55 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 2019-02-25 18:46 ` [BUG] git log -L ... -s does not suppress diff output Randall S. Becker
Code repositories for project(s) associated with this public inbox https://80x24.org/mirrors/git.git 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 read-only IMAP folder(s) and NNTP newsgroup(s).