Skip to content

Commit 78275b0

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7eb35e0 commit 78275b0

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

wt-status.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,8 +1176,6 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
11761176
struct strbuf sb = STRBUF_INIT;
11771177
const char *cp, *ep, *branch_name;
11781178
struct branch *branch;
1179-
char comment_line_string[3];
1180-
int i;
11811179
uint64_t t_begin = 0;
11821180

11831181
assert(s->branch && !s->is_initial);
@@ -1202,16 +1200,11 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
12021200
}
12031201
}
12041202

1205-
i = 0;
1206-
if (s->display_comment_prefix) {
1207-
comment_line_string[i++] = comment_line_char;
1208-
comment_line_string[i++] = ' ';
1209-
}
1210-
comment_line_string[i] = '\0';
1211-
12121203
for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
12131204
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
1214-
"%s%.*s", comment_line_string,
1205+
"%s%s%.*s",
1206+
s->display_comment_prefix ? comment_line_str : "",
1207+
s->display_comment_prefix ? " " : "",
12151208
(int)(ep - cp), cp);
12161209
if (s->display_comment_prefix)
12171210
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%s",

0 commit comments

Comments
 (0)