Skip to content

Commit 3c3d0c4

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7d8841 commit 3c3d0c4

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

pretty.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,17 @@ static int format_trailer_match_cb(const struct strbuf *key, void *ud)
12501250
return 0;
12511251
}
12521252

1253+
static struct strbuf *expand_separator(struct strbuf *sb,
1254+
const char *argval, size_t arglen)
1255+
{
1256+
char *fmt = xstrndup(argval, arglen);
1257+
1258+
strbuf_reset(sb);
1259+
strbuf_expand(sb, fmt, strbuf_expand_literal_cb, NULL);
1260+
free(fmt);
1261+
return sb;
1262+
}
1263+
12531264
int format_set_trailers_options(struct process_trailer_options *opts,
12541265
struct string_list *filter_list,
12551266
struct strbuf *sepbuf,
@@ -1278,21 +1289,9 @@ int format_set_trailers_options(struct process_trailer_options *opts,
12781289
opts->filter_data = filter_list;
12791290
opts->only_trailers = 1;
12801291
} else if (match_placeholder_arg_value(*arg, "separator", arg, &argval, &arglen)) {
1281-
char *fmt;
1282-
1283-
strbuf_reset(sepbuf);
1284-
fmt = xstrndup(argval, arglen);
1285-
strbuf_expand(sepbuf, fmt, strbuf_expand_literal_cb, NULL);
1286-
free(fmt);
1287-
opts->separator = sepbuf;
1292+
opts->separator = expand_separator(sepbuf, argval, arglen);
12881293
} else if (match_placeholder_arg_value(*arg, "key_value_separator", arg, &argval, &arglen)) {
1289-
char *fmt;
1290-
1291-
strbuf_reset(kvsepbuf);
1292-
fmt = xstrndup(argval, arglen);
1293-
strbuf_expand(kvsepbuf, fmt, strbuf_expand_literal_cb, NULL);
1294-
free(fmt);
1295-
opts->key_value_separator = kvsepbuf;
1294+
opts->key_value_separator = expand_separator(kvsepbuf, argval, arglen);
12961295
} else if (!match_placeholder_bool_arg(*arg, "only", arg, &opts->only_trailers) &&
12971296
!match_placeholder_bool_arg(*arg, "unfold", arg, &opts->unfold) &&
12981297
!match_placeholder_bool_arg(*arg, "keyonly", arg, &opts->key_only) &&

0 commit comments

Comments
 (0)