Skip to contentSkip to conversation

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

PATCH In review Alex Henrie 5 participants 10 messages Mar 23, 2019 – Apr 1, 2019 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 In `git log --graph`, default to --pretty=oneline --abbrev-commit

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

---
 builtin/log.c          |  5 +++++
 t/t4052-stat-output.sh | 14 +++++++-------
 t/t4202-log.sh         | 14 ++++++++++++++
 3 files changed, 26 insertions(+), 7 deletions(-)
builtin/log.c +5 -0
index ab859f5904..4fca910fee 100644
@@ -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)
t/t4052-stat-output.sh +7 -7
index 28c053849a..b44776efe3 100755
@@ -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'
t/t4202-log.sh +14 -0
index 819c24d10e..7cf9f15cec 100755
@@ -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' '
 
Signature · 1 line
2.21.0
#2 lore raw
In reply to Alex Henrie
Quoted 5 lines · Alex Henrie

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

---

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.

#3 lore raw
Quoted 15 lines · Junio C Hamano
Quoted 5 lines · Alex Henrie

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

---

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.

Quoted 3 lines

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.

#4 lore raw
In reply to Junio C Hamano
Quoted 16 lines · Junio C Hamano
Quoted 5 lines · Alex Henrie

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

---

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.

Quoted 3 lines

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

#5 lore raw

Hi Alex,

Quoted 3 lines · Alex Henrie

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

#6 lore raw
Quoted 11 lines · Rafael Ascensão

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.

Quoted 5 lines · Ævar Arnfjörð Bjarmason

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

#7 lore raw
Quoted 6 lines · Alex Henrie

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

A message that is not in the archive (sent off-list or not yet received): CACUQV59x-W+fCz_O5EnbZhjZ1CB2NhEQbkR8dAYMizAQGQ2SFA@mail.gmail.com

#9 lore raw
Quoted 2 lines · Rafael Ascensão

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

#10 lore raw
In reply to Rafael Ascensão
Quoted 7 lines · Rafael Ascensão

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/[email protected]/