git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] branch: only perform HEAD check for local branches

From
Jeff King <peff@peff.net>
Date
Jul 9, 2017, 09:58 UTC
Message-ID
<20170709095810.vtwclyvqbayit2u6@sigill.intra.peff.net>
In-Reply-To
<20170709095708.moymrozmqdv2oixx@sigill.intra.peff.net>

When assembling the ref-filter format to show "git branch" output, we put the "%(if)%(HEAD)" conditional at the start of the overall format. But there's no point in checking whether a remote branch matches HEAD, as it never will. The check should go inside the local conditional; we assemble that format inside the "local" strbuf.

By itself, this is just a minor optimization. But in a future patch, we'll need this refactoring to fix local-branch coloring.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/branch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index c958e9325..a849373b7 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -335,8 +335,9 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
 	struct strbuf local = STRBUF_INIT;
 	struct strbuf remote = STRBUF_INIT;
 
-	strbuf_addf(&fmt, "%%(if)%%(HEAD)%%(then)* %s%%(else)  %%(end)",
+	strbuf_addf(&local, "%%(if)%%(HEAD)%%(then)* %s%%(else)  %%(end)",
 		    branch_get_color(BRANCH_COLOR_CURRENT));
+	strbuf_addf(&remote, "  ");
 
 	if (filter->verbose) {
 		struct strbuf obname = STRBUF_INIT;
-- 
2.13.2.1066.gabaed60bd
Previous: Jeff KingNext: Jeff King
Message 4 of 6 in “git-2.13.2: color.branch.local problem”
  1. Leo RazoumovJul 8, 2017
  2. Jeff KingJul 9, 2017
  3. Jeff KingJul 9, 2017
  4. 1/3 branch: only perform HEAD check for local branchesJeff King, Jul 9, 2017
  5. 2/3 branch: use BRANCH_COLOR_LOCAL in ref-filter formatJeff King, Jul 9, 2017
  6. 3/3 branch: set remote color in ref-filter branch immediatelyJeff King, Jul 9, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.