threads / patch / 50809

patchIn `git log --graph`, default to --pretty=oneline --abbrev-commit

Subject: [PATCH] In `git log --graph`, default to --pretty=oneline --abbrev-commit

## tl;dr

10 messages between Mar 23, 2019 and Apr 1, 2019. Diffs are folded; open one to read it.

replies: 9people: 5as markdown or json

Alex Henrie· Mar 23, 2019, 04:13 UTC · lore

Having --pretty=medium as the default almost always makes the graph too difficult to follow.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 builtin/log.c          |  5 +++++
 t/t4052-stat-output.sh | 14 +++++++-------
 t/t4202-log.sh         | 14 ++++++++++++++
 3 files changed, 26 insertions(+), 7 deletions(-)
Show changes to 3 files +26 −7

builtin/log.c, t/t4052-stat-output.sh, t/t4202-log.sh

diff --git a/builtin/log.c b/builtin/log.c
index ab859f5904..4fca910fee 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -199,6 +199,11 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 	memset(&w, 0, sizeof(w));
 	userformat_find_requirements(NULL, &w);
 
+	if (rev->graph && !fmt_pretty && !rev->pretty_given && !rev->show_signature) {
+		rev->abbrev_commit = 1;
+		rev->commit_format = CMIT_FMT_ONELINE;
+	}
+
 	if (!rev->show_notes_given && (!rev->pretty_given || w.notes))
 		rev->show_notes = 1;
 	if (rev->show_notes)
diff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh
index 28c053849a..b44776efe3 100755
--- a/t/t4052-stat-output.sh
+++ b/t/t4052-stat-output.sh
@@ -144,7 +144,7 @@ done <<\EOF
 ignores expect72 format-patch -1 --stdout
 respects expect200 diff HEAD^ HEAD --stat
 respects expect200 show --stat
-respects expect200 log -1 --stat
+respects expect200 log -1 --pretty=medium --stat
 EOF
 
 cat >expect40 <<'EOF'
@@ -172,7 +172,7 @@ done <<\EOF
 ignores expect72 format-patch -1 --stdout
 respects expect40 diff HEAD^ HEAD --stat
 respects expect40 show --stat
-respects expect40 log -1 --stat
+respects expect40 log -1 --pretty=medium --stat
 EOF
 
 cat >expect40 <<'EOF'
@@ -200,7 +200,7 @@ done <<\EOF
 ignores expect72 format-patch -1 --stdout
 respects expect40 diff HEAD^ HEAD --stat
 respects expect40 show --stat
-respects expect40 log -1 --stat
+respects expect40 log -1 --pretty=medium --stat
 EOF
 
 
@@ -247,7 +247,7 @@ done <<\EOF
 format-patch -1 --stdout
 diff HEAD^ HEAD --stat
 show --stat
-log -1 --stat
+log -1 --pretty=medium --stat
 EOF
 
 test_expect_success 'preparation for long filename tests' '
@@ -281,7 +281,7 @@ done <<\EOF
 format-patch -1 --stdout
 diff HEAD^ HEAD --stat
 show --stat
-log -1 --stat
+log -1 --pretty=medium --stat
 EOF
 
 cat >expect72 <<'EOF'
@@ -315,7 +315,7 @@ done <<\EOF
 ignores expect72 format-patch -1 --stdout
 respects expect200 diff HEAD^ HEAD --stat
 respects expect200 show --stat
-respects expect200 log -1 --stat
+respects expect200 log -1 --pretty=medium --stat
 EOF
 
 cat >expect1 <<'EOF'
@@ -345,7 +345,7 @@ done <<\EOF
 ignores expect72 format-patch -1 --stdout
 respects expect1 diff HEAD^ HEAD --stat
 respects expect1 show --stat
-respects expect1 log -1 --stat
+respects expect1 log -1 --pretty=medium --stat
 EOF
 
 cat >expect <<'EOF'
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 819c24d10e..7cf9f15cec 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -39,6 +39,20 @@ test_expect_success setup '
 
 '
 
+test_expect_success 'default log format' '
+
+	git log --pretty=medium > expect &&
+	git log > actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'default log --graph format' '
+
+	git log --graph --pretty=oneline --abbrev-commit > expect &&
+	git log --graph > actual &&
+	test_cmp expect actual
+'
+
 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
 test_expect_success 'pretty' '
 
-- 
2.21.0
Junio C Hamano· Mar 24, 2019, 13:03 UTC · re: Alex Henrie · lore

Re: [PATCH] In `git log --graph`, default to --pretty=oneline --abbrev-commit

Alex Henrie <alexhenrie24@gmail.com> writes:
Show 5 quoted lines
> Having --pretty=medium as the default almost always makes the graph too
> difficult to follow.
>
> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---

I too thought that "--graph" should make "--oneline" the default back when I originally accepted the patch series that introduced the "--graph" feature, but with frequent use of "--graph" myself, I stopped being sure that "--oneline" should be the default long time ago. I find that the default level of prettiness goes reasonably well with the "--graph" option.

This would be something that needs a long transition period if somebody really wants to force people to adapt to it. I am not sure if the complication is worth it.

Ævar Arnfjörð Bjarmason· Mar 24, 2019, 18:58 UTC · re: Junio C Hamano · lore

Re: [PATCH] In `git log --graph`, default to --pretty=oneline --abbrev-commit

On Sun, Mar 24 2019, Junio C Hamano wrote:
Show 18 quoted lines
> Alex Henrie <alexhenrie24@gmail.com> writes:
>
>> Having --pretty=medium as the default almost always makes the graph too
>> difficult to follow.
>>
>> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
>> ---
>
> I too thought that "--graph" should make "--oneline" the default
> back when I originally accepted the patch series that introduced the
> "--graph" feature, but with frequent use of "--graph" myself, I
> stopped being sure that "--oneline" should be the default long time
> ago.  I find that the default level of prettiness goes reasonably
> well with the "--graph" option.
>
> This would be something that needs a long transition period if
> somebody really wants to force people to adapt to it.  I am not sure
> if the complication is worth it.

Aside from historical/backcompat concerns I think the current rendering makes sense. One could also argue that e.g. --stat benefits from --oneline.

We shouldn't have unrelated options implying one another, except stuff like "--compact-summary" implying "--stat" (makes no sense otherwise...).

I use --graph without --oneline more frequently than not. It gives you a glance at how deep in a merge hierarchy some log range is, whereas with --oneline you're most involved in the shape of that graph to the exclusion of other things.

But maybe a built-in "git-graph" is in order? E.g. one can imagine that once we have a dedicated command for that (similar to range-diff) you could really focus on the UX of that, e.g. going further than --oneline and truncating a N+ divergence as "...and N more.." or something.

Alex Henrie· Mar 24, 2019, 22:37 UTC · re: Junio C Hamano · lore

Re: [PATCH] In `git log --graph`, default to --pretty=oneline --abbrev-commit

On Sun, Mar 24, 2019 at 7:03 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 19 quoted lines
>
> Alex Henrie <alexhenrie24@gmail.com> writes:
>
> > Having --pretty=medium as the default almost always makes the graph too
> > difficult to follow.
> >
> > Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> > ---
>
> I too thought that "--graph" should make "--oneline" the default
> back when I originally accepted the patch series that introduced the
> "--graph" feature, but with frequent use of "--graph" myself, I
> stopped being sure that "--oneline" should be the default long time
> ago.  I find that the default level of prettiness goes reasonably
> well with the "--graph" option.
>
> This would be something that needs a long transition period if
> somebody really wants to force people to adapt to it.  I am not sure
> if the complication is worth it.
Can we compromise and make --pretty=short the default for --graph?
-Alex
Rafael Ascensão· Mar 25, 2019, 01:17 UTC · re: Alex Henrie · lore

Re: [PATCH] In `git log --graph`, default to --pretty=oneline --abbrev-commit

Hi Alex,
On Sun, Mar 24, 2019 at 04:37:25PM -0600, Alex Henrie wrote:
> 
> Can we compromise and make --pretty=short the default for --graph?
> 

I agree that `pretty=medium` is sometimes hard to read and, as of now, `pretty=oneline` can be very misleading:

    $ git log --graph --oneline todo~2..todo master~2..master

This will look like you have a sequence of commits when in fact they are completely unrelated.

But If we make the default to 'short' (or anything else), what should be done if the user has `format.pretty=` defined to something? Is `--graph` special to be allowed to not follow said configuration?

It's inconsistent itself, and introduces inconsistencies on other things like the configuration above.

In my opinion, a better alternative could be having a configuration like log.graphFormat, similarly how we have log.graphColors for colors, to determine which format should be used with --graph.

This would still require user configuration which may be what you were trying to avoid by proposing the change in default behaviour.

Settling for a compromise feels like giving up on the strengths from both.

Cheers, Rafael Ascensão

Alex Henrie· Mar 25, 2019, 05:10 UTC · re: Rafael Ascensão · lore

Re: [PATCH] In `git log --graph`, default to --pretty=oneline --abbrev-commit

On Sun, Mar 24, 2019 at 7:18 PM Rafael Ascensão <rafa.almas@gmail.com> wrote:
Show 11 quoted lines
>
> But If we make the default to 'short' (or anything else), what should be
> done if the user has `format.pretty=` defined to something? Is `--graph`
> special to be allowed to not follow said configuration?
>
> It's inconsistent itself, and introduces inconsistencies on other things
> like the configuration above.
>
> In my opinion, a better alternative could be having a configuration like
> log.graphFormat, similarly how we have log.graphColors for colors, to
> determine which format should be used with --graph.

The way that I wrote the patch, if format.pretty is not defined then `git log` will default to one format and `git log --graph` will default to another. I admit that it is a bit of a hack.

On Sun, Mar 24, 2019 at 12:58 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 5 quoted lines
>
> But maybe a built-in "git-graph" is in order? E.g. one can imagine that
> once we have a dedicated command for that (similar to range-diff) you
> could really focus on the UX of that, e.g. going further than --oneline
> and truncating a N+ divergence as "...and N more.." or something.

I like the idea of a completely separate `git graph` command. This command would simply be a builtin alias for `git log --abbrev-commit --pretty=oneline`, like how `git reflog` is a builtin alias for `git log -g --abbrev-commit --pretty=oneline`. Junio, would you be on board with that?

-Alex
Alex Henrie· Mar 25, 2019, 05:16 UTC · re: Alex Henrie · lore

Re: [PATCH] In `git log --graph`, default to --pretty=oneline --abbrev-commit

On Sun, Mar 24, 2019 at 11:10 PM Alex Henrie <alexhenrie24@gmail.com> wrote:
Show 6 quoted lines
>
> I like the idea of a completely separate `git graph` command. This
> command would simply be a builtin alias for `git log --abbrev-commit
> --pretty=oneline`, like how `git reflog` is a builtin alias for `git
> log -g --abbrev-commit --pretty=oneline`. Junio, would you be on board
> with that?

Sorry, I left off the --graph parameter. You can set up what I'm proposing as a personal alias with the following command:

git config --global alias.graph 'log --graph --abbrev-commit --pretty=oneline'
-Alex
Junio C Hamano· Apr 1, 2019, 10:45 UTC · re: Rafael Ascensão · lore

Re: [PATCH] In `git log --graph`, default to --pretty=oneline --abbrev-commit

Rafael Ascensão <rafa.almas@gmail.com> writes:
Show 7 quoted lines
> I agree that `pretty=medium` is sometimes hard to read and, as of now,
> `pretty=oneline` can be very misleading:
>
>     $ git log --graph --oneline todo~2..todo master~2..master
>
> This will look like you have a sequence of commits when in fact they are
> completely unrelated.

This is pretty much unrelated to which level of details should be the default, isn't it?

I do agree that --graph should be more intelligent around the root commits when showing two or more unrelated lines of histories.

Something like [*1*] from discussion in 2013 (not the patch that started the thread, for reasons stated in the thread, but ideas offered as alternative design in the discussion) would be the right way to solve it and it would work with all the log formatting options, whether --oneline, --pretty=medium, etc.

[Reference]
*1* http://public-inbox.org/git/1382717268-21884-1-git-send-email-milton.soares.filho@gmail.com/
Alex Henrie· Mar 27, 2019, 17:49 UTC · lore

Re: [PATCH] In `git log --graph`, default to --pretty=oneline --abbrev-commit

On Sun, Mar 24, 2019 at 11:27 PM Rafael Ascensão <rafa.almas@gmail.com> wrote:
>
> Or just $git log --graph --oneline, since --oneline is a shortcut for the longer --pretty=oneline --abbrev-commit.

Thanks for the tip! I didn't know about the --oneline option, but now that I do, I suppose I don't really need an alias.

-Alex

← back to recent threads