1252
return 0;
1253
}
1254
1255
-static struct strbuf *expand_separator(struct strbuf *sb,
1256
- const char *argval, size_t arglen)
1255
+static struct strbuf *expand_string_arg(struct strbuf *sb,
1256
+ const char *argval, size_t arglen)
1257
{
1258
char *fmt = xstrndup(argval, arglen);
1259
const char *format = fmt;
1301
opts->filter_data = filter_list;
1302
opts->only_trailers = 1;
1303
} else if (match_placeholder_arg_value(*arg, "separator", arg, &argval, &arglen)) {
1304
- opts->separator = expand_separator(sepbuf, argval, arglen);
1304
+ opts->separator = expand_string_arg(sepbuf, argval, arglen);
1305
} else if (match_placeholder_arg_value(*arg, "key_value_separator", arg, &argval, &arglen)) {
1306
- opts->key_value_separator = expand_separator(kvsepbuf, argval, arglen);
1306
+ opts->key_value_separator = expand_string_arg(kvsepbuf, argval, arglen);
1307
} else if (!match_placeholder_bool_arg(*arg, "only", arg, &opts->only_trailers) &&
1308
!match_placeholder_bool_arg(*arg, "unfold", arg, &opts->unfold) &&
1309
!match_placeholder_bool_arg(*arg, "keyonly", arg, &opts->key_only) &&
1384
return arg - start;
1385
}
1386
1387
+
1388
+static int parse_decoration_option(const char **arg,
1389
+ const char *name,
1390
+ char **opt)
1391
+{
1392
+ const char *argval;
1393
+ size_t arglen;
1394
+
1395
+ if (match_placeholder_arg_value(*arg, name, arg, &argval, &arglen)) {
1396
+ struct strbuf sb = STRBUF_INIT;
1397
+
1398
+ expand_string_arg(&sb, argval, arglen);
1399
+ *opt = strbuf_detach(&sb, NULL);
1400
+ return 1;
1401
+ }
1402
+ return 0;
1403
+}
1404
+
1405
+static void parse_decoration_options(const char **arg,
1406
+ struct decoration_options *opts)
1407
+{
1408
+ while (parse_decoration_option(arg, "prefix", &opts->prefix) ||
1409
+ parse_decoration_option(arg, "suffix", &opts->suffix) ||
1410
+ parse_decoration_option(arg, "separator", &opts->separator))
1411
+ ;
1412
+}
1413
+
1414
+static void free_decoration_options(const struct decoration_options *opts)
1415
+{
1416
+ free(opts->prefix);
1417
+ free(opts->suffix);
1418
+ free(opts->separator);
1419
+}
1420
+
1421
static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1422
const char *placeholder,
1423
void *context)
1679
return 2;
1680
}
1681
1682
+ if (skip_prefix(placeholder, "(decorate", &arg)) {
1683
+ struct decoration_options opts = { NULL };
1684
+ size_t ret = 0;
1685
+
1686
+ if (*arg == ':') {
1687
+ arg++;
1688
+ parse_decoration_options(&arg, &opts);
1689
+ }
1690
+ if (*arg == ')') {
1691
+ format_decorations(sb, commit, c->auto_color, &opts);
1692
+ ret = arg - placeholder + 1;
1693
+ }
1694
+
1695
+ free_decoration_options(&opts);
1696
+ return ret;
1697
+ }
1698
+
1699
/* For the rest we have to parse the commit header. */
1700
if (!c->commit_header_parsed) {
1701
msg = c->message =