{"thread":{"id":"66852","subject":"[PATCH] pretty: fix lost and leaked colors at line breaks","startedAt":"2026-11-15T21:35:03Z","lastAt":"2026-11-17T09:10:17Z","messageCount":5,"participants":["Andy Koppe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558509","messageId":"2f9f835e3f99d7de5bbf51be2e8ef4dc0485a46e.1794778250.git.andy.koppe@gmail.com","threadId":"66852","inReplyTo":null,"subject":"[PATCH] pretty: fix lost and leaked colors at line breaks","fromName":"Andy Koppe","fromEmail":"andy.koppe@gmail.com","sentAt":"2026-11-15T21:35:03Z","receivedAt":"2026-11-15T21:35:03Z","isPatch":true,"sender":{"key":"andy.koppe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223411?v=4"},"body":"Colors in custom log formats remain in effect until reset, including\nacross line breaks. Lines therefore don't necessarily set their own\ncolors, nor reset them at their end, which leads to two problems.\n\nFirstly, lines that continue colors from preceding lines lose them when\nshown without that context. Notably, --graph and color-aware pagers such\nas less reset colors at line breaks, so for example \"%C(bold)%w(72)%s\"\nonly makes the first line of a wrapped subject bold, and \"%C(cyan)%b\"\nonly colors the first line of the message body. The same can happen to\nlines picked out by grepping colored output.\n\nSecondly, colors that are still active at the end of a line can leak\ninto what follows. For example, with --graph, \"%C(red)%s\" also colors a\n'*' commit marker at the start of the next line, because the graph does\nnot reset colors before drawing. Attributes such as bold also leak into\nthe '|', '/' and '\\' edges, as their colors don't override them. When\ngrepping colored output, colors can similarly leak into unrelated lines.\n\nThe default log formats as well as git grep and diff avoid both problems\nby ensuring that the coloring of each line is self-contained: they do\nnot rely on colors carrying across line breaks and always reset colors\nat the end of each line.\n\nFix both problems by taking the same approach for custom formats. When\ncolor output is enabled, scan their output for color escape sequences,\ncollecting those since the last reset. If any are active at a newline,\ninsert a reset before it, and replay them at the start of the next\nnon-empty line, unless that begins with a reset. Also append a reset at\nthe end if any colors are still active there.\n\nDoing this in repo_format_commit_message() covers all color sequences\nand line breaks, whether they come from placeholders, auto colors,\nmanual %x1b sequences, or message content.\n\nResets are only recognized as the first code of a sequence, which is\nwhere git puts them. A reset later in a sequence would cancel the codes\nbefore it, so it is unlikely to be used deliberately, and missing one\nmerely adds to the replayed sequences.\n\nTo keep overhead to a minimum, avoid buffer inserts and use memchr() and\nstrcspn() to skip to escapes and newlines. If there are no escapes, the\nonly cost is an unsuccessful memchr() call. The buffer is only copied if\ncolors are active at a line break.\n\nFormats that have come to rely on --graph or a pager resetting colors at\nline breaks will need explicit resets, which they already require when\nneither is used.\n\nSigned-off-by: Andy Koppe <andy.koppe@gmail.com>\n---\n pretty.c                      | 98 +++++++++++++++++++++++++++++++++++\n t/t4205-log-pretty-formats.sh | 70 +++++++++++++++++++++++++\n 2 files changed, 168 insertions(+)\n\ndiff --git a/pretty.c b/pretty.c\nindex d8a9f370f6..58ccf304be 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1997,6 +1997,100 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)\n \t}\n }\n \n+/*\n+ * Make the coloring of each line in 'sb' from offset 'start' onwards\n+ * self-contained, so that it survives --graph and color-aware pagers such as\n+ * 'less -R' resetting colors at line breaks, and doesn't leak into what\n+ * follows, for example the graph.\n+ *\n+ * Color escape sequences since the last reset are collected, and if any are\n+ * active at a newline, a reset is inserted before it. They are replayed at the\n+ * start of the next non-empty line, unless that begins with a reset. A reset is\n+ * also appended at the end if colors are still active there.\n+ *\n+ * Resets, which have a zero or empty code, are only recognized at the start of\n+ * a sequence. They make little sense elsewhere, and missing one merely adds to\n+ * the replayed sequences.\n+ */\n+static void make_line_colors_self_contained(struct strbuf *sb, size_t start)\n+{\n+\tstruct strbuf colors = STRBUF_INIT; /* colors since last reset */\n+\tstruct strbuf tmp = STRBUF_INIT;\n+\n+\tconst char *copied = sb->buf;\n+\tconst char *sb_end = sb->buf + sb->len;\n+\tconst char *p = sb->buf + start;\n+\n+\twhile (p < sb_end) {\n+\t\tsize_t esc_len;\n+\t\tchar *end;\n+\t\tbool replay = false, is_reset, is_reset_only;\n+\n+\t\tif (!colors.len) {\n+\t\t\t/* look for colors to collect */\n+\t\t\tp = memchr(p, '\\033', sb_end - p);\n+\t\t\tif (!p)\n+\t\t\t\tbreak;\n+\t\t} else {\n+\t\t\t/* look for more colors or the line end */\n+\t\t\tp += strcspn(p, \"\\033\\n\");\n+\t\t}\n+\n+\t\tif (*p == '\\n') {\n+\t\t\t/* leave room for added resets and colors */\n+\t\t\tif (!tmp.len)\n+\t\t\t\tstrbuf_grow(&tmp, sb->len * 3 / 2);\n+\n+\t\t\t/* reset active colors at line end */\n+\t\t\tstrbuf_add(&tmp, copied, p - copied);\n+\t\t\tcopied = p;\n+\t\t\tstrbuf_addstr(&tmp, GIT_COLOR_RESET);\n+\n+\t\t\twhile (*++p == '\\n')\n+\t\t\t\t; /* skip empty lines */\n+\n+\t\t\tif (p == sb_end) {\n+\t\t\t\t/* no line left to replay colors on */\n+\t\t\t\tstrbuf_reset(&colors);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\treplay = true;\n+\t\t}\n+\n+\t\tesc_len = display_mode_esc_sequence_len(p);\n+\t\tis_reset = esc_len && !strtoul(p + 2, &end, 10);\n+\t\tis_reset_only = is_reset && *end == 'm';\n+\n+\t\tif (replay && !is_reset) {\n+\t\t\tstrbuf_add(&tmp, copied, p - copied);\n+\t\t\tcopied = p;\n+\t\t\tstrbuf_addbuf(&tmp, &colors);\n+\t\t}\n+\n+\t\tif (esc_len) {\n+\t\t\tif (is_reset)\n+\t\t\t\tstrbuf_reset(&colors);\n+\t\t\tif (!is_reset_only)\n+\t\t\t\tstrbuf_add(&colors, p, esc_len);\n+\t\t\tp += esc_len;\n+\t\t} else {\n+\t\t\tp++;\n+\t\t}\n+\t}\n+\n+\tif (tmp.len) {\n+\t\tstrbuf_add(&tmp, copied, sb_end - copied);\n+\t\tstrbuf_swap(sb, &tmp);\n+\t}\n+\n+\t/* reset active colors at buffer end */\n+\tif (colors.len)\n+\t\tstrbuf_addstr(sb, GIT_COLOR_RESET);\n+\n+\tstrbuf_release(&tmp);\n+\tstrbuf_release(&colors);\n+}\n+\n void repo_format_commit_message(struct repository *r,\n \t\t\t\tconst struct commit *commit,\n \t\t\t\tconst char *format, struct strbuf *sb,\n@@ -2010,6 +2104,7 @@ void repo_format_commit_message(struct repository *r,\n \t};\n \tconst char *output_enc = pretty_ctx->output_encoding;\n \tconst char *utf8 = \"UTF-8\";\n+\tsize_t orig_len = sb->len;\n \n \twhile (strbuf_expand_step(sb, &format)) {\n \t\tsize_t len;\n@@ -2023,6 +2118,9 @@ void repo_format_commit_message(struct repository *r,\n \t}\n \trewrap_message_tail(sb, &context, 0, 0, 0);\n \n+\tif (want_color(pretty_ctx->color))\n+\t\tmake_line_colors_self_contained(sb, orig_len);\n+\n \t/*\n \t * Convert output to an actual output encoding; note that\n \t * format_commit_item() will always use UTF-8, so we don't\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex 01b97c8888..43a7de3f37 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -538,6 +538,76 @@ test_expect_success 'strbuf_utf8_replace() not producing NUL' '\n \ttest_grep ! Q actual\n '\n \n+test_expect_success 'colors carry across lines' '\n+\tgit log -1 --color=always \\\n+\t\t--format=\"%C(bold)%C(red)a%n%C(green)b\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<BOLD><RED>a<RESET>\n+\t<BOLD><RED><GREEN>b<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors carry across wrapped lines' '\n+\tcommit=$(echo \"one two three\" | git commit-tree HEAD^{tree}) &&\n+\tgit log -1 --color=always --format=\"%C(bold)%w(7)%s\" $commit >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<BOLD>one two<RESET>\n+\t<BOLD>three<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors are reset at the end of each commit' '\n+\tgit log -2 --color=always --format=\"%C(red)a\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED>a<RESET>\n+\t<RED>a<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors are not replayed on empty lines or before resets' '\n+\tgit log -1 --color=always \\\n+\t\t--format=\"%C(red)a%n%n%C(reset)b%C(green)%nc%n\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED>a<RESET>\n+\n+\t<RESET>b<GREEN><RESET>\n+\t<GREEN>c<RESET>\n+\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'resets followed by colors carry across lines' '\n+\tgit log -1 --color=always \\\n+\t\t--format=\"%C(red)%C(blue reset)a%nb%x1b[0;31m%nc%x1b[0m%nd\" \\\n+\t\t>raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED><;BLUE>a<RESET>\n+\t<;BLUE>b<RESET;RED><RESET>\n+\t<RESET;RED>c<RESET>\n+\td\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors carry across lines with --graph' '\n+\tgit log -1 --graph --color=always --format=\"%C(red)a%nb\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t* <RED>a<RESET>\n+\t<RED>|<RESET> <RED>b<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n # --date=[XXX] and corresponding %a[X] %c[X] format equivalency\n test_expect_success '--date=iso-strict %ad%cd is the same as %aI%cI' '\n \tgit log --format=%ad%n%cd --date=iso-strict >expected &&\n\nbase-commit: 7fb6055e678f800320d8ab8cd8f201d9493d1ba0\n-- \n2.56.GIT\n\n\n"},{"id":"558560","messageId":"xmqq4idgn3py.fsf@gitster.g","threadId":"66852","inReplyTo":"2f9f835e3f99d7de5bbf51be2e8ef4dc0485a46e.1794778250.git.andy.koppe@gmail.com","subject":"Re: [PATCH] pretty: fix lost and leaked colors at line breaks","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-16T16:25:13Z","receivedAt":"2026-11-16T16:25:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Koppe <andy.koppe@gmail.com> writes:\n\n> Colors in custom log formats remain in effect until reset, including\n> across line breaks. Lines therefore don't necessarily set their own\n> colors, nor reset them at their end, which leads to two problems.\n>\n> Firstly, lines that continue colors from preceding lines lose them when\n> shown without that context. Notably, --graph and color-aware pagers such\n> as less reset colors at line breaks, so for example \"%C(bold)%w(72)%s\"\n> only makes the first line of a wrapped subject bold, and \"%C(cyan)%b\"\n> only colors the first line of the message body.\n\nAnd custom format writers have no way to control what happens at the\n(artificial) line boundary that wrapping at 72 columns %w(72)\nintroduces, %b may include many lines but there is nothing for them\nto say \"at the end of each and every line, do this\".  And that is\nwhy you decided that runtime detection is the only way to do this to\nhelp custom formats?\n\nOK.  My initial reaction to the \"let's do the same as the default\nformat output\" was \"isn't that the responsibility of those who write\ntheir own custom format?\", but there clearly is a gap in the custom\nformat feature that makes it impossible for them to do so.\n\n> The same can happen to\n> lines picked out by grepping colored output.\n\nI am not sure if that is a problem.\n\n> Secondly, colors that are still active at the end of a line can leak\n> into what follows.\n\nThat somehow feels contradictory with the previous point, though.\n\n\n"},{"id":"558580","messageId":"845c622dc7fd33306beca5488a74a89dee8a2e38.1794872505.git.andy.koppe@gmail.com","threadId":"66852","inReplyTo":"2f9f835e3f99d7de5bbf51be2e8ef4dc0485a46e.1794778250.git.andy.koppe@gmail.com","subject":"[PATCH v2] pretty: fix lost and leaked colors at line breaks","fromName":"Andy Koppe","fromEmail":"andy.koppe@gmail.com","sentAt":"2026-11-17T00:00:36Z","receivedAt":"2026-11-17T00:00:36Z","isPatch":true,"sender":{"key":"andy.koppe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223411?v=4"},"body":"Colors in custom log formats remain in effect until reset, including\nacross line breaks. Lines therefore don't necessarily set their own\ncolors, nor reset them at their end, which leads to two problems.\n\nFirstly, lines that continue colors from preceding lines lose them when\n--graph edges or color-aware pagers such as less reset colors at line\nbreaks. For example, \"%C(bold)%w(72)%s\" then only makes the first line\nof a wrapped subject bold, and \"%C(cyan)%b\" only colors the first line\nof the message body.\n\nSecondly, colors that are still active at the end of a line can leak\ninto what follows. For example, with --graph, \"%C(red)%s\" also colors a\n'*' commit marker at the start of the next line, because unlike the '|',\n'/' and '\\' edges, it isn't colored. Attributes such as bold still leak\ninto the edges, though, as the graph only resets colors after each one.\n\nThe default log formats as well as git grep and diff avoid both problems\nby ensuring that the coloring of each line is self-contained: they do\nnot rely on colors carrying across line breaks and always reset colors\nat the end of each line. Custom formats can do the same at %n line\nbreaks, but not within placeholders that expand to multiple lines.\n\nFix both problems by automating this for custom formats. When color\noutput is enabled, scan their output for color escape sequences,\ncollecting those since the last reset. If any are active at a newline,\ninsert a reset before it, and replay them at the start of the next\nnon-empty line, unless that begins with a reset. Also append a reset at\nthe end if any colors are still active there.\n\nDoing this in repo_format_commit_message() covers all color sequences\nand line breaks, whether they come from placeholders, auto colors,\nmanual %x1b sequences, or message content.\n\nResets are only recognized as the first code of a sequence, which is\nwhere git puts them. A reset later in a sequence would cancel the codes\nbefore it, so it is unlikely to be used deliberately, and missing one\nmerely adds to the replayed sequences.\n\nTo keep overhead to a minimum, avoid buffer inserts and use memchr() and\nstrcspn() to skip to escapes and newlines. If there are no escapes, the\nonly cost is an unsuccessful memchr() call. The buffer is only copied if\ncolors are active at a line break.\n\nFormats that have come to rely on --graph or a pager resetting colors at\nline breaks will need explicit resets, which they already require when\nneither is used.\n\nSigned-off-by: Andy Koppe <andy.koppe@gmail.com>\n---\nChanges since v1 in response to Junio's review:\n\n- Point out that custom formats cannot make lines self-contained within\n  placeholders that expand to multiple lines, which is why the formatted\n  output is processed instead.\n- Drop the mentions of grepping colored output.\n- Clarify the --graph examples, which looked contradictory: the graph\n  only resets colors after its colored edges, so colors carried across\n  a line break are lost after an edge, yet leak into an uncolored '*'\n  commit marker.\n- Rebase onto maint, where v1 was queued.\n\nOther changes, from looking at the code with fresh eyes again:\n\n- Move the line break handling into the branch for active colors, as\n  it can't trigger otherwise.\n- Comment on the handling of NULs, which also stop strcspn().\n- Add a test with embedded and trailing NULs.\n\n pretty.c                      | 101 ++++++++++++++++++++++++++++++++++\n t/t4205-log-pretty-formats.sh |  80 +++++++++++++++++++++++++++\n 2 files changed, 181 insertions(+)\n\ndiff --git a/pretty.c b/pretty.c\nindex d8a9f370f6..983bd4fc71 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1997,6 +1997,103 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)\n \t}\n }\n \n+/*\n+ * Make the coloring of each line in 'sb' from offset 'start' onwards\n+ * self-contained, so that it survives --graph and color-aware pagers such as\n+ * 'less -R' resetting colors at line breaks, and doesn't leak into what\n+ * follows, for example the graph.\n+ *\n+ * Color escape sequences since the last reset are collected, and if any are\n+ * active at a newline, a reset is inserted before it. They are replayed at the\n+ * start of the next non-empty line, unless that begins with a reset. A reset is\n+ * also appended at the end if colors are still active there.\n+ *\n+ * Resets, which have a zero or empty code, are only recognized at the start of\n+ * a sequence. They make little sense elsewhere, and missing one merely adds to\n+ * the replayed sequences.\n+ */\n+static void make_line_colors_self_contained(struct strbuf *sb, size_t start)\n+{\n+\tstruct strbuf colors = STRBUF_INIT; /* colors since last reset */\n+\tstruct strbuf tmp = STRBUF_INIT;\n+\n+\tconst char *copied = sb->buf;\n+\tconst char *sb_end = sb->buf + sb->len;\n+\tconst char *p = sb->buf + start;\n+\n+\twhile (p < sb_end) {\n+\t\tsize_t esc_len;\n+\t\tchar *end;\n+\t\tbool replay = false, is_reset, is_reset_only;\n+\n+\t\tif (!colors.len) {\n+\t\t\t/* look for colors to collect */\n+\t\t\tp = memchr(p, '\\033', sb_end - p);\n+\t\t\tif (!p)\n+\t\t\t\tbreak;\n+\t\t} else {\n+\t\t\t/* look for more colors, the line end, or a NUL */\n+\t\t\tp += strcspn(p, \"\\033\\n\");\n+\n+\t\t\tif (*p == '\\n') {\n+\t\t\t\tif (!tmp.len) {\n+\t\t\t\t\t/* make room for resets and replays */\n+\t\t\t\t\tstrbuf_grow(&tmp, sb->len * 3 / 2);\n+\t\t\t\t}\n+\n+\t\t\t\t/* reset active colors at line end */\n+\t\t\t\tstrbuf_add(&tmp, copied, p - copied);\n+\t\t\t\tcopied = p;\n+\t\t\t\tstrbuf_addstr(&tmp, GIT_COLOR_RESET);\n+\n+\t\t\t\twhile (*++p == '\\n')\n+\t\t\t\t\t; /* skip empty lines */\n+\n+\t\t\t\tif (p == sb_end) {\n+\t\t\t\t\t/* no line left to replay colors on */\n+\t\t\t\t\tstrbuf_reset(&colors);\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\n+\t\t\t\treplay = true;\n+\t\t\t}\n+\t\t}\n+\n+\t\tesc_len = display_mode_esc_sequence_len(p);\n+\t\tis_reset = esc_len && !strtoul(p + 2, &end, 10);\n+\t\tis_reset_only = is_reset && *end == 'm';\n+\n+\t\tif (replay && !is_reset) {\n+\t\t\tstrbuf_add(&tmp, copied, p - copied);\n+\t\t\tcopied = p;\n+\t\t\tstrbuf_addbuf(&tmp, &colors);\n+\t\t}\n+\n+\t\tif (esc_len) {\n+\t\t\tif (is_reset)\n+\t\t\t\tstrbuf_reset(&colors);\n+\t\t\tif (!is_reset_only)\n+\t\t\t\tstrbuf_add(&colors, p, esc_len);\n+\t\t\tp += esc_len;\n+\t\t} else {\n+\t\t\t/* skip anything else, including NULs */\n+\t\t\tp++;\n+\t\t}\n+\t}\n+\n+\tif (tmp.len) {\n+\t\tstrbuf_add(&tmp, copied, sb_end - copied);\n+\t\tstrbuf_swap(sb, &tmp);\n+\t}\n+\n+\t/* reset active colors at buffer end */\n+\tif (colors.len)\n+\t\tstrbuf_addstr(sb, GIT_COLOR_RESET);\n+\n+\tstrbuf_release(&tmp);\n+\tstrbuf_release(&colors);\n+}\n+\n void repo_format_commit_message(struct repository *r,\n \t\t\t\tconst struct commit *commit,\n \t\t\t\tconst char *format, struct strbuf *sb,\n@@ -2010,6 +2107,7 @@ void repo_format_commit_message(struct repository *r,\n \t};\n \tconst char *output_enc = pretty_ctx->output_encoding;\n \tconst char *utf8 = \"UTF-8\";\n+\tsize_t orig_len = sb->len;\n \n \twhile (strbuf_expand_step(sb, &format)) {\n \t\tsize_t len;\n@@ -2023,6 +2121,9 @@ void repo_format_commit_message(struct repository *r,\n \t}\n \trewrap_message_tail(sb, &context, 0, 0, 0);\n \n+\tif (want_color(pretty_ctx->color))\n+\t\tmake_line_colors_self_contained(sb, orig_len);\n+\n \t/*\n \t * Convert output to an actual output encoding; note that\n \t * format_commit_item() will always use UTF-8, so we don't\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex 01b97c8888..7a3a3a4639 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -538,6 +538,86 @@ test_expect_success 'strbuf_utf8_replace() not producing NUL' '\n \ttest_grep ! Q actual\n '\n \n+test_expect_success 'colors carry across lines' '\n+\tgit log -1 --color=always \\\n+\t\t--format=\"%C(bold)%C(red)a%n%C(green)b\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<BOLD><RED>a<RESET>\n+\t<BOLD><RED><GREEN>b<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors carry across wrapped lines' '\n+\tcommit=$(echo \"one two three\" | git commit-tree HEAD^{tree}) &&\n+\tgit log -1 --color=always --format=\"%C(bold)%w(7)%s\" $commit >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<BOLD>one two<RESET>\n+\t<BOLD>three<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors are reset at the end of each commit' '\n+\tgit log -2 --color=always --format=\"%C(red)a\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED>a<RESET>\n+\t<RED>a<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors are not replayed on empty lines or before resets' '\n+\tgit log -1 --color=always \\\n+\t\t--format=\"%C(red)a%n%n%C(reset)b%C(green)%nc%n\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED>a<RESET>\n+\n+\t<RESET>b<GREEN><RESET>\n+\t<GREEN>c<RESET>\n+\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'resets followed by colors carry across lines' '\n+\tgit log -1 --color=always \\\n+\t\t--format=\"%C(red)%C(blue reset)a%nb%x1b[0;31m%nc%x1b[0m%nd\" \\\n+\t\t>raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED><;BLUE>a<RESET>\n+\t<;BLUE>b<RESET;RED><RESET>\n+\t<RESET;RED>c<RESET>\n+\td\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors carry across lines with NULs' '\n+\tgit log -1 --color=always --format=\"%C(red)a%x00%x00b%nc%x00\" >raw &&\n+\tnul_to_q <raw | test_decode_color >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED>aQQb<RESET>\n+\t<RED>cQ<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors carry across lines with --graph' '\n+\tgit log -1 --graph --color=always --format=\"%C(red)a%nb\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t* <RED>a<RESET>\n+\t<RED>|<RESET> <RED>b<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n # --date=[XXX] and corresponding %a[X] %c[X] format equivalency\n test_expect_success '--date=iso-strict %ad%cd is the same as %aI%cI' '\n \tgit log --format=%ad%n%cd --date=iso-strict >expected &&\n\nRange-diff against v1:\n1:  1e5e3188cd ! 1:  845c622dc7 pretty: fix lost and leaked colors at line breaks\n    @@ Commit message\n         colors, nor reset them at their end, which leads to two problems.\n     \n         Firstly, lines that continue colors from preceding lines lose them when\n    -    shown without that context. Notably, --graph and color-aware pagers such\n    -    as less reset colors at line breaks, so for example \"%C(bold)%w(72)%s\"\n    -    only makes the first line of a wrapped subject bold, and \"%C(cyan)%b\"\n    -    only colors the first line of the message body. The same can happen to\n    -    lines picked out by grepping colored output.\n    +    --graph edges or color-aware pagers such as less reset colors at line\n    +    breaks. For example, \"%C(bold)%w(72)%s\" then only makes the first line\n    +    of a wrapped subject bold, and \"%C(cyan)%b\" only colors the first line\n    +    of the message body.\n     \n         Secondly, colors that are still active at the end of a line can leak\n         into what follows. For example, with --graph, \"%C(red)%s\" also colors a\n    -    '*' commit marker at the start of the next line, because the graph does\n    -    not reset colors before drawing. Attributes such as bold also leak into\n    -    the '|', '/' and '\\' edges, as their colors don't override them. When\n    -    grepping colored output, colors can similarly leak into unrelated lines.\n    +    '*' commit marker at the start of the next line, because unlike the '|',\n    +    '/' and '\\' edges, it isn't colored. Attributes such as bold still leak\n    +    into the edges, though, as the graph only resets colors after each one.\n     \n         The default log formats as well as git grep and diff avoid both problems\n         by ensuring that the coloring of each line is self-contained: they do\n         not rely on colors carrying across line breaks and always reset colors\n    -    at the end of each line.\n    +    at the end of each line. Custom formats can do the same at %n line\n    +    breaks, but not within placeholders that expand to multiple lines.\n     \n    -    Fix both problems by taking the same approach for custom formats. When\n    -    color output is enabled, scan their output for color escape sequences,\n    +    Fix both problems by automating this for custom formats. When color\n    +    output is enabled, scan their output for color escape sequences,\n         collecting those since the last reset. If any are active at a newline,\n         insert a reset before it, and replay them at the start of the next\n         non-empty line, unless that begins with a reset. Also append a reset at\n    @@ pretty.c: void userformat_find_requirements(const char *fmt, struct userformat_w\n     +\t\t\tif (!p)\n     +\t\t\t\tbreak;\n     +\t\t} else {\n    -+\t\t\t/* look for more colors or the line end */\n    ++\t\t\t/* look for more colors, the line end, or a NUL */\n     +\t\t\tp += strcspn(p, \"\\033\\n\");\n    -+\t\t}\n     +\n    -+\t\tif (*p == '\\n') {\n    -+\t\t\t/* leave room for added resets and colors */\n    -+\t\t\tif (!tmp.len)\n    -+\t\t\t\tstrbuf_grow(&tmp, sb->len * 3 / 2);\n    ++\t\t\tif (*p == '\\n') {\n    ++\t\t\t\tif (!tmp.len) {\n    ++\t\t\t\t\t/* make room for resets and replays */\n    ++\t\t\t\t\tstrbuf_grow(&tmp, sb->len * 3 / 2);\n    ++\t\t\t\t}\n     +\n    -+\t\t\t/* reset active colors at line end */\n    -+\t\t\tstrbuf_add(&tmp, copied, p - copied);\n    -+\t\t\tcopied = p;\n    -+\t\t\tstrbuf_addstr(&tmp, GIT_COLOR_RESET);\n    ++\t\t\t\t/* reset active colors at line end */\n    ++\t\t\t\tstrbuf_add(&tmp, copied, p - copied);\n    ++\t\t\t\tcopied = p;\n    ++\t\t\t\tstrbuf_addstr(&tmp, GIT_COLOR_RESET);\n     +\n    -+\t\t\twhile (*++p == '\\n')\n    -+\t\t\t\t; /* skip empty lines */\n    ++\t\t\t\twhile (*++p == '\\n')\n    ++\t\t\t\t\t; /* skip empty lines */\n     +\n    -+\t\t\tif (p == sb_end) {\n    -+\t\t\t\t/* no line left to replay colors on */\n    -+\t\t\t\tstrbuf_reset(&colors);\n    -+\t\t\t\tbreak;\n    ++\t\t\t\tif (p == sb_end) {\n    ++\t\t\t\t\t/* no line left to replay colors on */\n    ++\t\t\t\t\tstrbuf_reset(&colors);\n    ++\t\t\t\t\tbreak;\n    ++\t\t\t\t}\n    ++\n    ++\t\t\t\treplay = true;\n     +\t\t\t}\n    -+\t\t\treplay = true;\n     +\t\t}\n     +\n     +\t\tesc_len = display_mode_esc_sequence_len(p);\n    @@ pretty.c: void userformat_find_requirements(const char *fmt, struct userformat_w\n     +\t\t\t\tstrbuf_add(&colors, p, esc_len);\n     +\t\t\tp += esc_len;\n     +\t\t} else {\n    ++\t\t\t/* skip anything else, including NULs */\n     +\t\t\tp++;\n     +\t\t}\n     +\t}\n    @@ t/t4205-log-pretty-formats.sh: test_expect_success 'strbuf_utf8_replace() not pr\n     +\ttest_cmp expect actual\n     +'\n     +\n    ++test_expect_success 'colors carry across lines with NULs' '\n    ++\tgit log -1 --color=always --format=\"%C(red)a%x00%x00b%nc%x00\" >raw &&\n    ++\tnul_to_q <raw | test_decode_color >actual &&\n    ++\tcat >expect <<-\\EOF &&\n    ++\t<RED>aQQb<RESET>\n    ++\t<RED>cQ<RESET>\n    ++\tEOF\n    ++\ttest_cmp expect actual\n    ++'\n    ++\n     +test_expect_success 'colors carry across lines with --graph' '\n     +\tgit log -1 --graph --color=always --format=\"%C(red)a%nb\" >raw &&\n     +\ttest_decode_color <raw >actual &&\n\nbase-commit: 03b41523c576f26ad34085378717a0c1b287470f\n-- \n2.56.GIT\n\n\n"},{"id":"558582","messageId":"CAHWeT-Z=pKMtGN7GU-UP_yrygTsihn-cwYoLPzjo9=3J_SjJ8Q@mail.gmail.com","threadId":"66852","inReplyTo":"xmqq4idgn3py.fsf@gitster.g","subject":"Re: [PATCH] pretty: fix lost and leaked colors at line breaks","fromName":"Andy Koppe","fromEmail":"andy.koppe@gmail.com","sentAt":"2026-11-17T00:12:16Z","receivedAt":"2026-11-17T00:12:16Z","isPatch":true,"sender":{"key":"andy.koppe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223411?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> And custom format writers have no way to control what happens at the\n> (artificial) line boundary that wrapping at 72 columns %w(72)\n> introduces, %b may include many lines but there is nothing for them\n> to say \"at the end of each and every line, do this\".  And that is\n> why you decided that runtime detection is the only way to do this to\n> help custom formats?\n\nYes, exactly. I've tried to make that clearer in the commit message of v2.\n\n> > The same can happen to\n> > lines picked out by grepping colored output.\n>\n> I am not sure if that is a problem.\n\nFair enough. It's a minor point, so I've dropped it.\n\n> > Secondly, colors that are still active at the end of a line can leak\n> > into what follows.\n>\n> That somehow feels contradictory with the previous point, though.\n\nYou're right, I didn't put that well. The graph doesn't reset colors\nat the start of a line, but after each of its colored edges. So a\ncolor carried across a line break is lost once an edge has been drawn,\nbut it leaks into anything drawn before that, notably the uncolored\n'*' commit marker. Attributes such as bold even leak into the edges\nthemselves, as their colors only replace the foreground color. v2\nrewords this.\n\nThanks,\nAndy\n\n"},{"id":"558598","messageId":"e9f88b533dfbd10528c9151e2e87207419d0253d.1794905511.git.andy.koppe@gmail.com","threadId":"66852","inReplyTo":"2f9f835e3f99d7de5bbf51be2e8ef4dc0485a46e.1794778250.git.andy.koppe@gmail.com","subject":"[PATCH v3] pretty: fix lost and leaked colors at line breaks","fromName":"Andy Koppe","fromEmail":"andy.koppe@gmail.com","sentAt":"2026-11-17T09:10:17Z","receivedAt":"2026-11-17T09:10:17Z","isPatch":true,"sender":{"key":"andy.koppe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223411?v=4"},"body":"Colors in custom log formats remain in effect until reset, including\nacross line breaks. Lines therefore don't necessarily set their own\ncolors, nor reset them at their end, which leads to two problems.\n\nFirstly, lines that continue colors from preceding lines lose them when\n--graph edges or color-aware pagers such as less reset colors at line\nbreaks. For example, \"%C(bold)%w(72)%s\" then only makes the first line\nof a wrapped subject bold, and \"%C(cyan)%b\" only colors the first line\nof the message body.\n\nSecondly, colors that are still active at the end of a line can leak\ninto what follows. For example, with --graph, \"%C(red)%s\" also colors a\n'*' commit marker at the start of the next line, because unlike the '|',\n'/' and '\\' edges, it isn't colored. Attributes such as bold still leak\ninto the edges, though, as the graph only resets colors after each one.\n\nThe default log formats as well as git grep and diff avoid both problems\nby ensuring that the coloring of each line is self-contained: they do\nnot rely on colors carrying across line breaks and always reset colors\nat the end of each line. Custom formats can do the same at %n line\nbreaks, but not within placeholders that expand to multiple lines.\n\nFix both problems by automating this for custom formats. When color\noutput is enabled, scan their output for color escape sequences,\ncollecting those since the last reset. If any are active at a newline,\ninsert a reset before it, and replay them at the start of the next\nnon-empty line, unless that begins with a reset. Also append a reset at\nthe end if any colors are still active there.\n\nDoing this in repo_format_commit_message() covers all color sequences\nand line breaks, whether they come from placeholders, auto colors,\nmanual %x1b sequences, or message content.\n\nResets are only recognized as the first code of a sequence, which is\nwhere git puts them. A reset later in a sequence would cancel the codes\nbefore it, so it is unlikely to be used deliberately, and missing one\nmerely adds to the replayed sequences.\n\nTo keep overhead to a minimum, avoid buffer inserts and use memchr() and\nstrcspn() to skip to escapes and newlines. If there are no escapes, the\nonly cost is an unsuccessful memchr() call. The buffer is only copied if\ncolors are active at a line break.\n\nFormats that have come to rely on --graph or a pager resetting colors at\nline breaks will need explicit resets, which they already require when\nneither is used.\n\nSigned-off-by: Andy Koppe <andy.koppe@gmail.com>\n---\nSorry, this code keeps on bouncing around my head, so here's one more\ntweak to try to make it clearer. (The algorithm has been annoyingly\ndifficult to pin down considering it's a pretty simple idea.)\n\n- Combine the reset and replay conditionals.\n- Rename the reset variables, for consistency with 'replay'.\n\n pretty.c                      | 102 ++++++++++++++++++++++++++++++++++\n t/t4205-log-pretty-formats.sh |  80 ++++++++++++++++++++++++++\n 2 files changed, 182 insertions(+)\n\ndiff --git a/pretty.c b/pretty.c\nindex d8a9f370f6..78be2ae034 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1997,6 +1997,104 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)\n \t}\n }\n \n+/*\n+ * Make the coloring of each line in 'sb' from offset 'start' onwards\n+ * self-contained, so that it survives --graph and color-aware pagers such as\n+ * 'less -R' resetting colors at line breaks, and doesn't leak into what\n+ * follows, for example the graph.\n+ *\n+ * Color escape sequences since the last reset are collected, and if any are\n+ * active at a newline, a reset is inserted before it. They are replayed at the\n+ * start of the next non-empty line, unless that begins with a reset. A reset is\n+ * also appended at the end if colors are still active there.\n+ *\n+ * Resets, which have a zero or empty code, are only recognized at the start of\n+ * a sequence. They make little sense elsewhere, and missing one merely adds to\n+ * the replayed sequences.\n+ */\n+static void make_line_colors_self_contained(struct strbuf *sb, size_t start)\n+{\n+\tstruct strbuf colors = STRBUF_INIT; /* colors since last reset */\n+\tstruct strbuf tmp = STRBUF_INIT;\n+\n+\tconst char *copied = sb->buf;\n+\tconst char *sb_end = sb->buf + sb->len;\n+\tconst char *p = sb->buf + start;\n+\n+\twhile (p < sb_end) {\n+\t\tsize_t esc_len;\n+\t\tbool replay = false, reset, reset_only;\n+\t\tchar *reset_end;\n+\n+\t\tif (!colors.len) {\n+\t\t\t/* look for colors to collect */\n+\t\t\tp = memchr(p, '\\033', sb_end - p);\n+\t\t\tif (!p)\n+\t\t\t\tbreak;\n+\t\t} else {\n+\t\t\t/* look for more colors, the line end, or a NUL */\n+\t\t\tp += strcspn(p, \"\\033\\n\");\n+\n+\t\t\tif (*p == '\\n') {\n+\t\t\t\tif (!tmp.len) {\n+\t\t\t\t\t/* make room for resets and replays */\n+\t\t\t\t\tstrbuf_grow(&tmp, sb->len * 3 / 2);\n+\t\t\t\t}\n+\n+\t\t\t\t/* reset active colors at line end */\n+\t\t\t\tstrbuf_add(&tmp, copied, p - copied);\n+\t\t\t\tcopied = p;\n+\t\t\t\tstrbuf_addstr(&tmp, GIT_COLOR_RESET);\n+\n+\t\t\t\twhile (*++p == '\\n')\n+\t\t\t\t\t; /* skip empty lines */\n+\n+\t\t\t\tif (p == sb_end) {\n+\t\t\t\t\t/* no line left to replay colors on */\n+\t\t\t\t\tstrbuf_reset(&colors);\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\n+\t\t\t\treplay = true;\n+\t\t\t}\n+\t\t}\n+\n+\t\tesc_len = display_mode_esc_sequence_len(p);\n+\t\treset = esc_len && !strtoul(p + 2, &reset_end, 10);\n+\t\treset_only = reset && *reset_end == 'm';\n+\n+\t\tif (reset) {\n+\t\t\tstrbuf_reset(&colors);\n+\t\t} else if (replay) {\n+\t\t\tstrbuf_add(&tmp, copied, p - copied);\n+\t\t\tcopied = p;\n+\t\t\tstrbuf_addbuf(&tmp, &colors);\n+\t\t}\n+\n+\t\tif (esc_len) {\n+\t\t\t/* collect the sequence if it's more than a reset */\n+\t\t\tif (!reset_only)\n+\t\t\t\tstrbuf_add(&colors, p, esc_len);\n+\t\t\tp += esc_len;\n+\t\t} else {\n+\t\t\t/* skip anything else, including NULs */\n+\t\t\tp++;\n+\t\t}\n+\t}\n+\n+\tif (tmp.len) {\n+\t\tstrbuf_add(&tmp, copied, sb_end - copied);\n+\t\tstrbuf_swap(sb, &tmp);\n+\t}\n+\n+\t/* reset active colors at buffer end */\n+\tif (colors.len)\n+\t\tstrbuf_addstr(sb, GIT_COLOR_RESET);\n+\n+\tstrbuf_release(&tmp);\n+\tstrbuf_release(&colors);\n+}\n+\n void repo_format_commit_message(struct repository *r,\n \t\t\t\tconst struct commit *commit,\n \t\t\t\tconst char *format, struct strbuf *sb,\n@@ -2010,6 +2108,7 @@ void repo_format_commit_message(struct repository *r,\n \t};\n \tconst char *output_enc = pretty_ctx->output_encoding;\n \tconst char *utf8 = \"UTF-8\";\n+\tsize_t orig_len = sb->len;\n \n \twhile (strbuf_expand_step(sb, &format)) {\n \t\tsize_t len;\n@@ -2023,6 +2122,9 @@ void repo_format_commit_message(struct repository *r,\n \t}\n \trewrap_message_tail(sb, &context, 0, 0, 0);\n \n+\tif (want_color(pretty_ctx->color))\n+\t\tmake_line_colors_self_contained(sb, orig_len);\n+\n \t/*\n \t * Convert output to an actual output encoding; note that\n \t * format_commit_item() will always use UTF-8, so we don't\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex 01b97c8888..7a3a3a4639 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -538,6 +538,86 @@ test_expect_success 'strbuf_utf8_replace() not producing NUL' '\n \ttest_grep ! Q actual\n '\n \n+test_expect_success 'colors carry across lines' '\n+\tgit log -1 --color=always \\\n+\t\t--format=\"%C(bold)%C(red)a%n%C(green)b\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<BOLD><RED>a<RESET>\n+\t<BOLD><RED><GREEN>b<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors carry across wrapped lines' '\n+\tcommit=$(echo \"one two three\" | git commit-tree HEAD^{tree}) &&\n+\tgit log -1 --color=always --format=\"%C(bold)%w(7)%s\" $commit >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<BOLD>one two<RESET>\n+\t<BOLD>three<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors are reset at the end of each commit' '\n+\tgit log -2 --color=always --format=\"%C(red)a\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED>a<RESET>\n+\t<RED>a<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors are not replayed on empty lines or before resets' '\n+\tgit log -1 --color=always \\\n+\t\t--format=\"%C(red)a%n%n%C(reset)b%C(green)%nc%n\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED>a<RESET>\n+\n+\t<RESET>b<GREEN><RESET>\n+\t<GREEN>c<RESET>\n+\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'resets followed by colors carry across lines' '\n+\tgit log -1 --color=always \\\n+\t\t--format=\"%C(red)%C(blue reset)a%nb%x1b[0;31m%nc%x1b[0m%nd\" \\\n+\t\t>raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED><;BLUE>a<RESET>\n+\t<;BLUE>b<RESET;RED><RESET>\n+\t<RESET;RED>c<RESET>\n+\td\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors carry across lines with NULs' '\n+\tgit log -1 --color=always --format=\"%C(red)a%x00%x00b%nc%x00\" >raw &&\n+\tnul_to_q <raw | test_decode_color >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t<RED>aQQb<RESET>\n+\t<RED>cQ<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'colors carry across lines with --graph' '\n+\tgit log -1 --graph --color=always --format=\"%C(red)a%nb\" >raw &&\n+\ttest_decode_color <raw >actual &&\n+\tcat >expect <<-\\EOF &&\n+\t* <RED>a<RESET>\n+\t<RED>|<RESET> <RED>b<RESET>\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n # --date=[XXX] and corresponding %a[X] %c[X] format equivalency\n test_expect_success '--date=iso-strict %ad%cd is the same as %aI%cI' '\n \tgit log --format=%ad%n%cd --date=iso-strict >expected &&\n\nRange-diff against v2:\n1:  845c622dc7 ! 1:  e9f88b533d pretty: fix lost and leaked colors at line breaks\n    @@ pretty.c: void userformat_find_requirements(const char *fmt, struct userformat_w\n     +\n     +\twhile (p < sb_end) {\n     +\t\tsize_t esc_len;\n    -+\t\tchar *end;\n    -+\t\tbool replay = false, is_reset, is_reset_only;\n    ++\t\tbool replay = false, reset, reset_only;\n    ++\t\tchar *reset_end;\n     +\n     +\t\tif (!colors.len) {\n     +\t\t\t/* look for colors to collect */\n    @@ pretty.c: void userformat_find_requirements(const char *fmt, struct userformat_w\n     +\t\t}\n     +\n     +\t\tesc_len = display_mode_esc_sequence_len(p);\n    -+\t\tis_reset = esc_len && !strtoul(p + 2, &end, 10);\n    -+\t\tis_reset_only = is_reset && *end == 'm';\n    ++\t\treset = esc_len && !strtoul(p + 2, &reset_end, 10);\n    ++\t\treset_only = reset && *reset_end == 'm';\n     +\n    -+\t\tif (replay && !is_reset) {\n    ++\t\tif (reset) {\n    ++\t\t\tstrbuf_reset(&colors);\n    ++\t\t} else if (replay) {\n     +\t\t\tstrbuf_add(&tmp, copied, p - copied);\n     +\t\t\tcopied = p;\n     +\t\t\tstrbuf_addbuf(&tmp, &colors);\n     +\t\t}\n     +\n     +\t\tif (esc_len) {\n    -+\t\t\tif (is_reset)\n    -+\t\t\t\tstrbuf_reset(&colors);\n    -+\t\t\tif (!is_reset_only)\n    ++\t\t\t/* collect the sequence if it's more than a reset */\n    ++\t\t\tif (!reset_only)\n     +\t\t\t\tstrbuf_add(&colors, p, esc_len);\n     +\t\t\tp += esc_len;\n     +\t\t} else {\n\nbase-commit: 03b41523c576f26ad34085378717a0c1b287470f\n-- \n2.56.GIT\n\n\n"}]}