Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Koppe <andy.koppe@gmail.com>2023-08-20 21:50:04 +0300
committerJunio C Hamano <gitster@pobox.com>2023-08-21 21:40:09 +0300
commita3883a6532163f0a53a7b202f32bf8fe565af056 (patch)
treeeba20122b493f942aeff9bb9b12fbcf44bb7cbbe /log-tree.c
parent31a922f8383ea75b5757d2f9d0615c85b2083b5a (diff)
decorate: refactor format_decorations()
Rename the format_decorations_extended function to format_decorations and drop the format_decorations wrapper macro. Pass the prefix, suffix and separator strings as a single 'struct format_decorations' pointer argument instead of separate arguments. Use default values defined in the function when either the struct pointer or any of the struct fields are NULL. This is to ease extension with additional options. Signed-off-by: Andy Koppe <andy.koppe@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'log-tree.c')
-rw-r--r--log-tree.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/log-tree.c b/log-tree.c
index 208c69cbb7..cd12c26c29 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -303,14 +303,12 @@ static void show_name(struct strbuf *sb, const struct name_decoration *decoratio
/*
* The caller makes sure there is no funny color before calling.
- * format_decorations_extended makes sure the same after return.
+ * format_decorations ensures the same after return.
*/
-void format_decorations_extended(struct strbuf *sb,
+void format_decorations(struct strbuf *sb,
const struct commit *commit,
int use_color,
- const char *prefix,
- const char *separator,
- const char *suffix)
+ const struct decoration_options *opts)
{
const struct name_decoration *decoration;
const struct name_decoration *current_and_HEAD;
@@ -319,10 +317,23 @@ void format_decorations_extended(struct strbuf *sb,
const char *color_reset =
decorate_get_color(use_color, DECORATION_NONE);
+ const char *prefix = " (";
+ const char *suffix = ")";
+ const char *separator = ", ";
+
decoration = get_name_decoration(&commit->object);
if (!decoration)
return;
+ if (opts) {
+ if (opts->prefix)
+ prefix = opts->prefix;
+ if (opts->suffix)
+ suffix = opts->suffix;
+ if (opts->separator)
+ separator = opts->separator;
+ }
+
current_and_HEAD = current_pointed_by_HEAD(decoration);
while (decoration) {
/*
@@ -370,7 +381,7 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
}
if (!opt->show_decorations)
return;
- format_decorations(&sb, commit, opt->diffopt.use_color);
+ format_decorations(&sb, commit, opt->diffopt.use_color, NULL);
fputs(sb.buf, opt->diffopt.file);
strbuf_release(&sb);
}