diff options
author | René Scharfe <l.s.r@web.de> | 2023-06-17 20:40:57 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-06-18 19:55:29 (GMT) |
commit | 3c3d0c4242d834c49d77da321425819c175df61c (patch) | |
tree | b2f38ee8c7d53f81c7866ff0e87c6e9e07cf919c /pretty.c | |
parent | d7d8841f67f29e6ecbad85a11805c907d0f00d5d (diff) | |
download | git-3c3d0c4242d834c49d77da321425819c175df61c.zip git-3c3d0c4242d834c49d77da321425819c175df61c.tar.gz git-3c3d0c4242d834c49d77da321425819c175df61c.tar.bz2 |
pretty: factor out expand_separator()
Deduplicate the code for setting the options "separator" and
"key_value_separator" by moving it into a new helper function,
expand_separator().
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pretty.c')
-rw-r--r-- | pretty.c | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -1250,6 +1250,17 @@ static int format_trailer_match_cb(const struct strbuf *key, void *ud) return 0; } +static struct strbuf *expand_separator(struct strbuf *sb, + const char *argval, size_t arglen) +{ + char *fmt = xstrndup(argval, arglen); + + strbuf_reset(sb); + strbuf_expand(sb, fmt, strbuf_expand_literal_cb, NULL); + free(fmt); + return sb; +} + int format_set_trailers_options(struct process_trailer_options *opts, struct string_list *filter_list, struct strbuf *sepbuf, @@ -1278,21 +1289,9 @@ int format_set_trailers_options(struct process_trailer_options *opts, opts->filter_data = filter_list; opts->only_trailers = 1; } else if (match_placeholder_arg_value(*arg, "separator", arg, &argval, &arglen)) { - char *fmt; - - strbuf_reset(sepbuf); - fmt = xstrndup(argval, arglen); - strbuf_expand(sepbuf, fmt, strbuf_expand_literal_cb, NULL); - free(fmt); - opts->separator = sepbuf; + opts->separator = expand_separator(sepbuf, argval, arglen); } else if (match_placeholder_arg_value(*arg, "key_value_separator", arg, &argval, &arglen)) { - char *fmt; - - strbuf_reset(kvsepbuf); - fmt = xstrndup(argval, arglen); - strbuf_expand(kvsepbuf, fmt, strbuf_expand_literal_cb, NULL); - free(fmt); - opts->key_value_separator = kvsepbuf; + opts->key_value_separator = expand_separator(kvsepbuf, argval, arglen); } else if (!match_placeholder_bool_arg(*arg, "only", arg, &opts->only_trailers) && !match_placeholder_bool_arg(*arg, "unfold", arg, &opts->unfold) && !match_placeholder_bool_arg(*arg, "keyonly", arg, &opts->key_only) && |