pretty: share code between format_decoration and show_decorations

This also adds color support to format_decorations()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy
2013-04-19 09:08:43 +10:00
committed by Junio C Hamano
parent d2ea4afb03
commit 9d3f002f21
4 changed files with 39 additions and 38 deletions

View File

@ -908,23 +908,6 @@ static void parse_commit_message(struct format_commit_context *c)
c->commit_message_parsed = 1;
}
static void format_decoration(struct strbuf *sb, const struct commit *commit)
{
struct name_decoration *d;
const char *prefix = " (";
load_ref_decorations(DECORATE_SHORT_REFS);
d = lookup_decoration(&name_decoration, &commit->object);
while (d) {
strbuf_addstr(sb, prefix);
prefix = ", ";
strbuf_addstr(sb, d->name);
d = d->next;
}
if (prefix[0] == ',')
strbuf_addch(sb, ')');
}
static void strbuf_wrap(struct strbuf *sb, size_t pos,
size_t width, size_t indent1, size_t indent2)
{
@ -1103,7 +1086,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
strbuf_addstr(sb, get_revision_mark(NULL, commit));
return 1;
case 'd':
format_decoration(sb, commit);
load_ref_decorations(DECORATE_SHORT_REFS);
format_decorations(sb, commit, 0);
return 1;
case 'g': /* reflog info */
switch(placeholder[1]) {