OSDN Git Service

branch: only perform HEAD check for local branches
authorJeff King <peff@peff.net>
Sun, 9 Jul 2017 09:58:10 +0000 (05:58 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sun, 9 Jul 2017 16:24:42 +0000 (09:24 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c

index 64d3e7d..5f8b5ad 100644 (file)
@@ -331,8 +331,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;