aboutsummaryrefslogtreecommitdiffstats
path: root/wt-status.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2024-03-12 05:17:45 -0400
committerJunio C Hamano <gitster@pobox.com>2024-03-12 13:28:10 -0700
commit78275b08e3d3ea7921a44a1a764fead1c2e252a3 (patch)
treec22ffd09844257d4c0368b3ae57b646aff1a2f15 /wt-status.c
parent7eb35e07c6f5616ea25601d6055c58f1220447da (diff)
downloadgit-78275b08e3d3ea7921a44a1a764fead1c2e252a3.tar.gz
wt-status: drop custom comment-char stringification
In wt_longstatus_print_tracking() we may conditionally show a comment prefix based on the wt_status->display_comment_prefix flag. We handle that by creating a local "comment_line_string" that is either the empty string or the comment character followed by a space. For a single-byte comment, the maximum length of this string is 2 (plus a NUL byte). But to handle multi-byte comment characters, it can be arbitrarily large. One way to handle this is to just call xstrfmt("%s ", comment_line_str), and then free it when we're done. But we can simplify things further by just conditionally switching between our prefix string and an empty string when formatting. We couldn't just do that with the previous code, because the comment character was a single byte. There's no way to have a "%c" format switch between some character and "no character at all". Whereas with "%s" you can switch between some string and the empty string. So now that we have a comment string and not a comment char, we can just use it directly when formatting. Do note that we have to also conditionally add the trailing space at the same time. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/wt-status.c b/wt-status.c
index 084bfc584f..823e8e81b0 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1176,8 +1176,6 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
struct strbuf sb = STRBUF_INIT;
const char *cp, *ep, *branch_name;
struct branch *branch;
- char comment_line_string[3];
- int i;
uint64_t t_begin = 0;
assert(s->branch && !s->is_initial);
@@ -1202,16 +1200,11 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
}
}
- i = 0;
- if (s->display_comment_prefix) {
- comment_line_string[i++] = comment_line_char;
- comment_line_string[i++] = ' ';
- }
- comment_line_string[i] = '\0';
-
for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
- "%s%.*s", comment_line_string,
+ "%s%s%.*s",
+ s->display_comment_prefix ? comment_line_str : "",
+ s->display_comment_prefix ? " " : "",
(int)(ep - cp), cp);
if (s->display_comment_prefix)
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%s",