Padding ("%<" and "%>") involves three fields of `struct format_commit_context`. This goes all the way back to commits a57523428b (pretty: support padding placeholders, %< %> and %><, 2013-04-19) and 1640632b4f (pretty: support %>> that steal trailing spaces, 2013-04-19). These fields are not used for anything else. Make that clearer by collecting them into their own little struct. Let our parser populate just that struct to make it obvious that the rest of the big struct does not influence the parsing. Signed-off-by: Martin Ågren <martin.agren@xxxxxxxxx> --- pretty.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/pretty.c b/pretty.c index 6a4264dd01..e5e8ef24fa 100644 --- a/pretty.c +++ b/pretty.c @@ -887,6 +887,12 @@ enum trunc_type { trunc_right }; +struct padding_args { + enum flush_type flush_type; + enum trunc_type truncate; + int padding; +}; + struct format_commit_context { struct repository *repository; const struct commit *commit; @@ -894,13 +900,11 @@ struct format_commit_context { unsigned commit_header_parsed:1; unsigned commit_message_parsed:1; struct signature_check signature_check; - enum flush_type flush_type; - enum trunc_type truncate; const char *message; char *commit_encoding; size_t width, indent1, indent2; int auto_color; - int padding; + struct padding_args pad; /* These offsets are relative to the start of the commit message. */ struct chunk author; @@ -1112,7 +1116,7 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */ } static size_t parse_padding_placeholder(const char *placeholder, - struct format_commit_context *c) + struct padding_args *p) { const char *ch = placeholder; enum flush_type flush_type; @@ -1167,8 +1171,8 @@ static size_t parse_padding_placeholder(const char *placeholder, if (width < 0) return 0; } - c->padding = to_column ? -width : width; - c->flush_type = flush_type; + p->padding = to_column ? -width : width; + p->flush_type = flush_type; if (*end == ',') { start = end + 1; @@ -1176,15 +1180,15 @@ static size_t parse_padding_placeholder(const char *placeholder, if (!end || end == start) return 0; if (starts_with(start, "trunc)")) - c->truncate = trunc_right; + p->truncate = trunc_right; else if (starts_with(start, "ltrunc)")) - c->truncate = trunc_left; + p->truncate = trunc_left; else if (starts_with(start, "mtrunc)")) - c->truncate = trunc_middle; + p->truncate = trunc_middle; else return 0; } else - c->truncate = trunc_none; + p->truncate = trunc_none; return end - placeholder + 1; } @@ -1504,7 +1508,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ case '<': case '>': - return parse_padding_placeholder(placeholder, c); + return parse_padding_placeholder(placeholder, &c->pad); } if (skip_prefix(placeholder, "(describe", &arg)) { @@ -1788,7 +1792,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */ { struct strbuf local_sb = STRBUF_INIT; size_t total_consumed = 0; - int len, padding = c->padding; + int len, padding = c->pad.padding; if (padding < 0) { const char *start = strrchr(sb->buf, '\n'); @@ -1815,7 +1819,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */ } len = utf8_strnwidth(local_sb.buf, local_sb.len, 1); - if (c->flush_type == flush_left_and_steal) { + if (c->pad.flush_type == flush_left_and_steal) { const char *ch = sb->buf + sb->len - 1; while (len > padding && ch > sb->buf) { const char *p; @@ -1841,11 +1845,11 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */ ch = p - 1; } strbuf_setlen(sb, ch + 1 - sb->buf); - c->flush_type = flush_left; + c->pad.flush_type = flush_left; } if (len > padding) { - switch (c->truncate) { + switch (c->pad.truncate) { case trunc_left: strbuf_utf8_replace(&local_sb, 0, len - (padding - 2), @@ -1868,9 +1872,9 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */ strbuf_addbuf(sb, &local_sb); } else { size_t sb_len = sb->len, offset = 0; - if (c->flush_type == flush_left) + if (c->pad.flush_type == flush_left) offset = padding - len; - else if (c->flush_type == flush_both) + else if (c->pad.flush_type == flush_both) offset = (padding - len) / 2; /* * we calculate padding in columns, now @@ -1882,7 +1886,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */ local_sb.len); } strbuf_release(&local_sb); - c->flush_type = no_flush; + c->pad.flush_type = no_flush; return total_consumed; } @@ -1927,7 +1931,7 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */ } orig_len = sb->len; - if (context->flush_type == no_flush) + if (context->pad.flush_type == no_flush) consumed = format_commit_one(sb, placeholder, context); else consumed = format_and_pad_commit(sb, placeholder, context); -- 2.49.0.472.ge94155a9ec