Skip to content

Commit f1f8a25

Browse files
ak2gitster
authored andcommitted
pretty: add pointer and tag options to %(decorate)
Add pointer and tag options to %(decorate) format, to allow to override the " -> " string used to show where HEAD points and the "tag: " string used to mark tags. Document in pretty-formats.txt and test in t4205-log-pretty-formats.sh. Signed-off-by: Andy Koppe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a58dd83 commit f1f8a25

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

Documentation/pretty-formats.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ parentheses (`%x29`), due to their role in the option syntax.
233233
** 'prefix=<value>': Shown before the list of ref names. Defaults to "{nbsp}`(`".
234234
** 'suffix=<value>': Shown after the list of ref names. Defaults to "`)`".
235235
** 'separator=<value>': Shown between ref names. Defaults to "`,`{nbsp}".
236+
** 'pointer=<value>': Shown between HEAD and the branch it points to, if any.
237+
Defaults to "{nbsp}`->`{nbsp}".
238+
** 'tag=<value>': Shown before tag names. Defaults to "`tag:`{nbsp}".
239+
240+
+
241+
For example, to produce decorations with no wrapping
242+
or tag annotations, and spaces as separators:
243+
+
244+
`%(decorate:prefix=,suffix=,tag=,separator= )`
236245

237246
'%(describe[:<options>])'::
238247
human-readable name, like linkgit:git-describe[1]; empty string for

log-tree.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ void format_decorations(struct strbuf *sb,
317317
const char *prefix = " (";
318318
const char *suffix = ")";
319319
const char *separator = ", ";
320+
const char *pointer = " -> ";
321+
const char *tag = "tag: ";
320322

321323
decoration = get_name_decoration(&commit->object);
322324
if (!decoration)
@@ -329,6 +331,10 @@ void format_decorations(struct strbuf *sb,
329331
suffix = opts->suffix;
330332
if (opts->separator)
331333
separator = opts->separator;
334+
if (opts->pointer)
335+
pointer = opts->pointer;
336+
if (opts->tag)
337+
tag = opts->tag;
332338
}
333339

334340
color_commit = diff_get_color(use_color, DIFF_COMMIT);
@@ -351,9 +357,9 @@ void format_decorations(struct strbuf *sb,
351357
strbuf_addstr(sb, color_reset);
352358
}
353359

354-
if (decoration->type == DECORATION_REF_TAG) {
360+
if (*tag && decoration->type == DECORATION_REF_TAG) {
355361
strbuf_addstr(sb, color);
356-
strbuf_addstr(sb, "tag: ");
362+
strbuf_addstr(sb, tag);
357363
strbuf_addstr(sb, color_reset);
358364
}
359365

@@ -364,7 +370,7 @@ void format_decorations(struct strbuf *sb,
364370
if (current_and_HEAD &&
365371
decoration->type == DECORATION_REF_HEAD) {
366372
strbuf_addstr(sb, color);
367-
strbuf_addstr(sb, " -> ");
373+
strbuf_addstr(sb, pointer);
368374
strbuf_addstr(sb, color_reset);
369375
strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type));
370376
show_name(sb, current_and_HEAD);

log-tree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ struct decoration_options {
1717
char *prefix;
1818
char *suffix;
1919
char *separator;
20+
char *pointer;
21+
char *tag;
2022
};
2123

2224
int parse_decorate_color_config(const char *var, const char *slot_name, const char *value);

pretty.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,9 @@ static void parse_decoration_options(const char **arg,
14071407
{
14081408
while (parse_decoration_option(arg, "prefix", &opts->prefix) ||
14091409
parse_decoration_option(arg, "suffix", &opts->suffix) ||
1410-
parse_decoration_option(arg, "separator", &opts->separator))
1410+
parse_decoration_option(arg, "separator", &opts->separator) ||
1411+
parse_decoration_option(arg, "pointer", &opts->pointer) ||
1412+
parse_decoration_option(arg, "tag", &opts->tag))
14111413
;
14121414
}
14131415

@@ -1416,6 +1418,8 @@ static void free_decoration_options(const struct decoration_options *opts)
14161418
free(opts->prefix);
14171419
free(opts->suffix);
14181420
free(opts->separator);
1421+
free(opts->pointer);
1422+
free(opts->tag);
14191423
}
14201424

14211425
static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */

t/t4205-log-pretty-formats.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,12 @@ test_expect_success 'pretty format %decorate' '
600600
echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 &&
601601
git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \
602602
-1 >actual4 &&
603-
test_cmp expect4 actual4
603+
test_cmp expect4 actual4 &&
604+
605+
echo "HEAD->foo bar qux" >expect5 &&
606+
git log --format="%(decorate:prefix=,suffix=,separator= ,tag=,pointer=->)" \
607+
-1 >actual5 &&
608+
test_cmp expect5 actual5
604609
'
605610

606611
cat >trailers <<EOF

0 commit comments

Comments
 (0)