OSDN Git Service

Merge branch 'rs/c-auto-resets-attributes' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 28 Oct 2016 16:01:11 +0000 (09:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 28 Oct 2016 16:01:11 +0000 (09:01 -0700)
When "%C(auto)" appears at the very beginning of the pretty format
string, it did not need to issue the reset sequence, but it did.
This is a small optimization to already graduated topic.

* rs/c-auto-resets-attributes:
  pretty: avoid adding reset for %C(auto) if output is empty
  pretty: let %C(auto) reset all attributes

pretty.c

index 9788bd8..25efbca 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1072,6 +1072,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
        case 'C':
                if (starts_with(placeholder + 1, "(auto)")) {
                        c->auto_color = want_color(c->pretty_ctx->color);
+                       if (c->auto_color && sb->len)
+                               strbuf_addstr(sb, GIT_COLOR_RESET);
                        return 7; /* consumed 7 bytes, "C(auto)" */
                } else {
                        int ret = parse_color(sb, placeholder, c);