* [PATCH 0/1] log: make the --oneline option work with -L
@ 2024-03-13 9:08 James Liu
2024-03-13 9:08 ` [PATCH 1/1] log: ensure diffs are omitted with --oneline James Liu
2024-03-13 17:31 ` [PATCH 0/1] log: make the --oneline option work with -L Junio C Hamano
0 siblings, 2 replies; 7+ messages in thread
From: James Liu @ 2024-03-13 9:08 UTC (permalink / raw)
To: git; +Cc: James Liu
Hey folks,
This is a small patch to fix an issue I've experienced with git-log(1)
when certain combinations of flags are provided. This is also my very
first patch submission, so I've tried to limit the blast radius as much
as possible. I'm also unsure if this is the best place to implement the
change, so any feedback is welcome!
I'd like to ideally add a test as well, but I'm unsure where this should
slot in.
git-log accepts the --oneline option to display the short commit SHA and
title only. This is a convenient option when searching through Git
history, as it gives a rough idea of the changes introduced in each
commit. git-log also accepts the -L flag, which lets us provide a line
range for a given file. This is handy for limiting the search to a given
area of interest.
However, when --oneline is used in combination with -L, Git actually
outputs the single line commit information _as well_ as the full diff.
For example:
git log --oneline -L 660:Documentation/MyFirstObjectWalk.txt
will incorrectly display the diffs too.
This patch aims to fix this behaviour by respecting the --oneline option
when used in conjunction with -L.
James Liu (1):
log: ensure diffs are omitted with --oneline
builtin/log.c | 4 ++++
1 file changed, 4 insertions(+)
--
2.43.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/1] log: ensure diffs are omitted with --oneline
2024-03-13 9:08 [PATCH 0/1] log: make the --oneline option work with -L James Liu
@ 2024-03-13 9:08 ` James Liu
2024-03-13 17:31 ` [PATCH 0/1] log: make the --oneline option work with -L Junio C Hamano
1 sibling, 0 replies; 7+ messages in thread
From: James Liu @ 2024-03-13 9:08 UTC (permalink / raw)
To: git; +Cc: James Liu
Currently when `git log --oneline` is invoked with the -L flag, the
full diffs are displayed along with the single line commit message.
It appears that within the log_tree_commit() function, the special
case that executes when opt->line_level_traverse is enabled (as in
the case when -L is provided) doesn't respect the --oneline option.
Ensure the --oneline option is respected by explicitly setting
DIFF_FORMAT_NO_OUTPUT if required.
Signed-off-by: James Liu <james@jamesliu.io>
---
builtin/log.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/builtin/log.c b/builtin/log.c
index e5da0d1043..dd77ede00c 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -279,6 +279,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
rev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;
argc = setup_revisions(argc, argv, rev, opt);
+ /* Ensure that we don't output diffs if the --oneline flag is provided */
+ if (rev->commit_format == CMIT_FMT_ONELINE)
+ rev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;
+
/* Any arguments at this point are not recognized */
if (argc > 1)
die(_("unrecognized argument: %s"), argv[1]);
--
2.43.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/1] log: make the --oneline option work with -L
2024-03-13 9:08 [PATCH 0/1] log: make the --oneline option work with -L James Liu
2024-03-13 9:08 ` [PATCH 1/1] log: ensure diffs are omitted with --oneline James Liu
@ 2024-03-13 17:31 ` Junio C Hamano
2024-03-13 18:08 ` Beat Bolli
2024-03-13 22:24 ` James Liu
1 sibling, 2 replies; 7+ messages in thread
From: Junio C Hamano @ 2024-03-13 17:31 UTC (permalink / raw)
To: James Liu; +Cc: git
James Liu <james@jamesliu.io> writes:
> git-log accepts the --oneline option to display the short commit SHA and
> title only. This is a convenient option when searching through Git
> history, as it gives a rough idea of the changes introduced in each
> commit. git-log also accepts the -L flag, which lets us provide a line
> range for a given file. This is handy for limiting the search to a given
> area of interest.
>
> However, when --oneline is used in combination with -L, Git actually
> outputs the single line commit information _as well_ as the full diff.
> For example:
>
> git log --oneline -L 660:Documentation/MyFirstObjectWalk.txt
>
> will incorrectly display the diffs too.
Why is it incorrect?
* "git log" takes options to tweak formatting of the commit log,
options to tweak what commits are chosen, and options to tweak
how the diff are shown.
* "--oneline" tweaks how the log message gets shown. Others in the
family are --pretty=fuller, --format='%h %s', etc.
* "-L" tweaks how the diff gets shown (e.g. limits which part of
the diff is shown) and what commits are shown (e.g. limits to
commits that touch the specified area).
So, just like "git log -L <range>:<file>" shows the commit log for
each commit that touches the specified area of the file, followed by
the diff that shows how the commit modified the range, it is natural
to expect "git log --oneline -L <range>:<file>" to show the same diff
after showing the commit log for these commits in the specified format,
namely, with just a one-line description.
It is not limited to "-L"; "git log --oneline -p" is expected to
show the patch after a one-line description for the commit.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/1] log: make the --oneline option work with -L
2024-03-13 17:31 ` [PATCH 0/1] log: make the --oneline option work with -L Junio C Hamano
@ 2024-03-13 18:08 ` Beat Bolli
2024-03-13 22:25 ` James Liu
2024-03-13 22:24 ` James Liu
1 sibling, 1 reply; 7+ messages in thread
From: Beat Bolli @ 2024-03-13 18:08 UTC (permalink / raw)
To: Junio C Hamano, James Liu; +Cc: git
On 13.03.24 18:31, Junio C Hamano wrote:
> James Liu <james@jamesliu.io> writes:
>
>> git-log accepts the --oneline option to display the short commit SHA and
>> title only. This is a convenient option when searching through Git
>> history, as it gives a rough idea of the changes introduced in each
>> commit. git-log also accepts the -L flag, which lets us provide a line
>> range for a given file. This is handy for limiting the search to a given
>> area of interest.
>>
>> However, when --oneline is used in combination with -L, Git actually
>> outputs the single line commit information _as well_ as the full diff.
>> For example:
>>
>> git log --oneline -L 660:Documentation/MyFirstObjectWalk.txt
>>
>> will incorrectly display the diffs too.
>
> Why is it incorrect?
>
> * "git log" takes options to tweak formatting of the commit log,
> options to tweak what commits are chosen, and options to tweak
> how the diff are shown.
>
> * "--oneline" tweaks how the log message gets shown. Others in the
> family are --pretty=fuller, --format='%h %s', etc.
>
> * "-L" tweaks how the diff gets shown (e.g. limits which part of
> the diff is shown) and what commits are shown (e.g. limits to
> commits that touch the specified area).
>
> So, just like "git log -L <range>:<file>" shows the commit log for
> each commit that touches the specified area of the file, followed by
> the diff that shows how the commit modified the range, it is natural
> to expect "git log --oneline -L <range>:<file>" to show the same diff
> after showing the commit log for these commits in the specified format,
> namely, with just a one-line description.
>
> It is not limited to "-L"; "git log --oneline -p" is expected to
> show the patch after a one-line description for the commit.
>
There's also "--no-patch" to suppress the patch. It combines well with
"--oneline".
--
Cheers, Beat
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/1] log: make the --oneline option work with -L
2024-03-13 17:31 ` [PATCH 0/1] log: make the --oneline option work with -L Junio C Hamano
2024-03-13 18:08 ` Beat Bolli
@ 2024-03-13 22:24 ` James Liu
2024-03-13 22:47 ` Junio C Hamano
1 sibling, 1 reply; 7+ messages in thread
From: James Liu @ 2024-03-13 22:24 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Thu Mar 14, 2024 at 4:31 AM AEDT, Junio C Hamano wrote:
> James Liu <james@jamesliu.io> writes:
>
> > However, when --oneline is used in combination with -L, Git actually
> > outputs the single line commit information _as well_ as the full diff.
> > For example:
> >
> > git log --oneline -L 660:Documentation/MyFirstObjectWalk.txt
> >
> > will incorrectly display the diffs too.
>
> Why is it incorrect?
>
> * "git log" takes options to tweak formatting of the commit log,
> options to tweak what commits are chosen, and options to tweak
> how the diff are shown.
>
> * "--oneline" tweaks how the log message gets shown. Others in the
> family are --pretty=fuller, --format='%h %s', etc.
>
> * "-L" tweaks how the diff gets shown (e.g. limits which part of
> the diff is shown) and what commits are shown (e.g. limits to
> commits that touch the specified area).
I suppose it isn't intuitive to me which options affect how the commits
are presented, and which affect the diffs. The help entry for -L states
that it will "Trace the evolution of the line range", which doesn't
immediately suggest that it tweaks how the log message is shown. As a
user of this option, I'm more interested in using it as a filter for how
commits are chosen.
-S feels like a similar option to -L, but will omit the diff when used
with --oneline. I think I was probably experimenting with "--oneline -S"
and then was surprised to see diffs after trying "--oneline -L".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/1] log: make the --oneline option work with -L
2024-03-13 18:08 ` Beat Bolli
@ 2024-03-13 22:25 ` James Liu
0 siblings, 0 replies; 7+ messages in thread
From: James Liu @ 2024-03-13 22:25 UTC (permalink / raw)
To: Beat Bolli, Junio C Hamano; +Cc: git
On Thu Mar 14, 2024 at 5:08 AM AEDT, Beat Bolli wrote:
> There's also "--no-patch" to suppress the patch. It combines well with
> "--oneline".
Thanks! That's a good one to keep handy.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/1] log: make the --oneline option work with -L
2024-03-13 22:24 ` James Liu
@ 2024-03-13 22:47 ` Junio C Hamano
0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2024-03-13 22:47 UTC (permalink / raw)
To: James Liu; +Cc: git
"James Liu" <james@jamesliu.io> writes:
> I suppose it isn't intuitive to me which options affect how the commits
> are presented, and which affect the diffs. The help entry for -L states
> that it will "Trace the evolution of the line range", which doesn't
> immediately suggest that it tweaks how the log message is shown.
Sorry, but you lost me. I do not understand this remark.
The documentation for "-L" does not talk about tweaking how the
message is shown at all, because "-L" does not have a say in how the
log message gets shown at all. And the documentation for
"--oneline", "--format", "--pretty" all should talk about how the
log message gets shown.
Anyway, if you are happy with "--no-patch", that's good.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-03-13 22:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-13 9:08 [PATCH 0/1] log: make the --oneline option work with -L James Liu
2024-03-13 9:08 ` [PATCH 1/1] log: ensure diffs are omitted with --oneline James Liu
2024-03-13 17:31 ` [PATCH 0/1] log: make the --oneline option work with -L Junio C Hamano
2024-03-13 18:08 ` Beat Bolli
2024-03-13 22:25 ` James Liu
2024-03-13 22:24 ` James Liu
2024-03-13 22:47 ` Junio C Hamano
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).