From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Jeff King" <peff@peff.net>, "Junio C Hamano" <gitster@pobox.com>,
"Felipe Contreras" <felipe.contreras@gmail.com>
Subject: [PATCH] branch: make -v useful
Date: Fri, 4 Jun 2021 20:13:39 -0500 [thread overview]
Message-ID: <20210605011339.2202-1-felipe.contreras@gmail.com> (raw)
Currently `git branch -v` shows something like "[ahead 10]", but ahead
of what?
We git experts know ahead of what, but not what that what is set to. Just
like "[@{upstream}: ahead 10]" would not be particularly useful to
anyone that doesn't know, or remembers, what @{upstream} is set to.
On the other hand "[master: ahead 10]" is perfectly clear to anyone.
This confusion only gets worse when you see "[ahead 10, behind 100]". Is
it master? Is it next? Is it
john/experimental-feature-i-based-my-branch-on?
Inevitably most users will need to know what @{upstream} is.
So let's make `git branch -v` output what is most useful:
[master]
Before:
* fc/branch/sane-colors b2489a3735 [ahead 1] branch: make -v useful
After:
* fc/branch/sane-colors b2489a3735 [master] branch: make -v useful
An additional benefit is that `git branch -v` is slightly faster: 30ms
vs. 60ms on my system.
`git branch -vv` is unaffected.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
This is a reboot of my old patch series [1].
Every time I use git without this feature I miss it.
[1] https://lore.kernel.org/git/1398027514-19399-1-git-send-email-felipe.contreras@gmail.com/
builtin/branch.c | 9 ++++-----
t/t3201-branch-contains.sh | 2 +-
t/t6040-tracking-info.sh | 12 ++++++------
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index b23b1d1752..7c0d3f7e4e 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -375,16 +375,15 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
strbuf_addstr(&local, branch_get_color(BRANCH_COLOR_RESET));
strbuf_addf(&local, " %s ", obname.buf);
+ strbuf_addf(&local, "%%(if:notequals=*)%%(HEAD)%%(then)%%(if)%%(worktreepath)%%(then)(%s%%(worktreepath)%s) %%(end)%%(end)",
+ branch_get_color(BRANCH_COLOR_WORKTREE), branch_get_color(BRANCH_COLOR_RESET));
if (filter->verbose > 1)
- {
- strbuf_addf(&local, "%%(if:notequals=*)%%(HEAD)%%(then)%%(if)%%(worktreepath)%%(then)(%s%%(worktreepath)%s) %%(end)%%(end)",
- branch_get_color(BRANCH_COLOR_WORKTREE), branch_get_color(BRANCH_COLOR_RESET));
strbuf_addf(&local, "%%(if)%%(upstream)%%(then)[%s%%(upstream:short)%s%%(if)%%(upstream:track)"
"%%(then): %%(upstream:track,nobracket)%%(end)] %%(end)%%(contents:subject)",
branch_get_color(BRANCH_COLOR_UPSTREAM), branch_get_color(BRANCH_COLOR_RESET));
- }
else
- strbuf_addf(&local, "%%(if)%%(upstream:track)%%(then)%%(upstream:track) %%(end)%%(contents:subject)");
+ strbuf_addf(&local, "%%(if)%%(upstream)%%(then)[%s%%(upstream:short)%s] %%(end)%%(contents:subject)",
+ branch_get_color(BRANCH_COLOR_UPSTREAM), branch_get_color(BRANCH_COLOR_RESET));
strbuf_addf(&remote, "%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s"
"%%(if)%%(symref)%%(then) -> %%(symref:short)"
diff --git a/t/t3201-branch-contains.sh b/t/t3201-branch-contains.sh
index 349a810cee..53e2d65e67 100755
--- a/t/t3201-branch-contains.sh
+++ b/t/t3201-branch-contains.sh
@@ -261,7 +261,7 @@ test_expect_success 'branch --merged with --verbose' '
git branch --verbose --merged topic >actual &&
cat >expect <<-EOF &&
main $(git rev-parse --short main) second on main
- * topic $(git rev-parse --short topic ) [ahead 1] foo
+ * topic $(git rev-parse --short topic ) [main] foo
zzz $(git rev-parse --short zzz ) second on main
EOF
test_cmp expect actual
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index a313849406..30f80ad61b 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -43,12 +43,12 @@ test_expect_success setup '
t6040_script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
cat >expect <<\EOF
-b1 [ahead 1, behind 1] d
-b2 [ahead 1, behind 1] d
-b3 [behind 1] b
-b4 [ahead 2] f
-b5 [gone] g
-b6 c
+b1 [origin/main] d
+b2 [origin/main] d
+b3 [origin/main] b
+b4 [origin/main] f
+b5 [brokenbase] g
+b6 [origin/main] c
EOF
test_expect_success 'branch -v' '
--
2.32.0.rc2
next reply other threads:[~2021-06-05 1:15 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-05 1:13 Felipe Contreras [this message]
2021-06-05 20:18 ` [PATCH] branch: make -v useful Ævar Arnfjörð Bjarmason
2021-06-05 22:35 ` Jeff King
2021-06-07 15:57 ` Felipe Contreras
2021-06-08 6:13 ` Jeff King
2021-06-08 7:17 ` Felipe Contreras
2021-06-08 7:27 ` Jeff King
2021-06-08 8:28 ` Felipe Contreras
2021-06-08 9:06 ` Kerry, Richard
2021-06-08 9:22 ` Felipe Contreras
2021-06-08 11:32 ` Kerry, Richard
2021-06-10 3:26 ` Felipe Contreras
2021-06-25 15:03 ` Kerry, Richard
2021-06-25 16:03 ` Felipe Contreras
2021-06-07 15:28 ` Felipe Contreras
2021-06-07 16:05 ` Ævar Arnfjörð Bjarmason
2021-06-07 18:00 ` Felipe Contreras
2021-06-07 18:37 ` Felipe Contreras
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210605011339.2202-1-felipe.contreras@gmail.com \
--to=felipe.contreras@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).