Skip to content

Commit d6d994d

Browse files
committed
Merge branch 'lh/short-decorate'
* lh/short-decorate: git-log: allow --decorate[=short|full]
2 parents b91069a + 33e7018 commit d6d994d

File tree

9 files changed

+65
-10
lines changed

9 files changed

+65
-10
lines changed

Documentation/git-log.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ include::diff-options.txt[]
3737
and <until>, see "SPECIFYING REVISIONS" section in
3838
linkgit:git-rev-parse[1].
3939

40-
--decorate::
41-
Print out the ref names of any commits that are shown.
40+
--decorate[=short|full]::
41+
Print out the ref names of any commits that are shown. If 'short' is
42+
specified, the ref name prefixes 'refs/heads/', 'refs/tags/' and
43+
'refs/remotes/' will not be printed. If 'full' is specified, the
44+
full ref name (including prefix) will be printed. The default option
45+
is 'short'.
4246

4347
--source::
4448
Print out the ref name given on the command line by which each

builtin-log.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
3535
struct rev_info *rev)
3636
{
3737
int i;
38+
int decoration_style = 0;
3839

3940
rev->abbrev = DEFAULT_ABBREV;
4041
rev->commit_format = CMIT_FMT_DEFAULT;
@@ -61,15 +62,26 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
6162
for (i = 1; i < argc; i++) {
6263
const char *arg = argv[i];
6364
if (!strcmp(arg, "--decorate")) {
64-
load_ref_decorations();
65-
rev->show_decorations = 1;
65+
decoration_style = DECORATE_SHORT_REFS;
66+
} else if (!prefixcmp(arg, "--decorate=")) {
67+
const char *v = skip_prefix(arg, "--decorate=");
68+
if (!strcmp(v, "full"))
69+
decoration_style = DECORATE_FULL_REFS;
70+
else if (!strcmp(v, "short"))
71+
decoration_style = DECORATE_SHORT_REFS;
72+
else
73+
die("invalid --decorate option: %s", arg);
6674
} else if (!strcmp(arg, "--source")) {
6775
rev->show_source = 1;
6876
} else if (!strcmp(arg, "-h")) {
6977
usage(builtin_log_usage);
7078
} else
7179
die("unrecognized argument: %s", arg);
7280
}
81+
if (decoration_style) {
82+
rev->show_decorations = 1;
83+
load_ref_decorations(decoration_style);
84+
}
7385
}
7486

7587
/*

log-tree.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
2525
struct object *obj = parse_object(sha1);
2626
if (!obj)
2727
return 0;
28-
refname = prettify_refname(refname);
28+
if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
29+
refname = prettify_refname(refname);
2930
add_name_decoration("", refname, obj);
3031
while (obj->type == OBJ_TAG) {
3132
obj = ((struct tag *)obj)->tagged;
@@ -36,12 +37,12 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
3637
return 0;
3738
}
3839

39-
void load_ref_decorations(void)
40+
void load_ref_decorations(int flags)
4041
{
4142
static int loaded;
4243
if (!loaded) {
4344
loaded = 1;
44-
for_each_ref(add_ref_decoration, NULL);
45+
for_each_ref(add_ref_decoration, &flags);
4546
}
4647
}
4748

log-tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
1717
const char **subject_p,
1818
const char **extra_headers_p,
1919
int *need_8bit_cte_p);
20-
void load_ref_decorations(void);
20+
void load_ref_decorations(int flags);
2121

2222
#define FORMAT_PATCH_NAME_MAX 64
2323
void get_patch_filename(struct commit *commit, int nr, const char *suffix,

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ static void format_decoration(struct strbuf *sb, const struct commit *commit)
583583
struct name_decoration *d;
584584
const char *prefix = " (";
585585

586-
load_ref_decorations();
586+
load_ref_decorations(DECORATE_SHORT_REFS);
587587
d = lookup_decoration(&name_decoration, &commit->object);
588588
while (d) {
589589
strbuf_addstr(sb, prefix);

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
10521052
revs->simplify_by_decoration = 1;
10531053
revs->limited = 1;
10541054
revs->prune = 1;
1055-
load_ref_decorations();
1055+
load_ref_decorations(DECORATE_SHORT_REFS);
10561056
} else if (!strcmp(arg, "--date-order")) {
10571057
revs->lifo = 0;
10581058
revs->topo_order = 1;

revision.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#define SYMMETRIC_LEFT (1u<<8)
1616
#define ALL_REV_FLAGS ((1u<<9)-1)
1717

18+
#define DECORATE_SHORT_REFS 1
19+
#define DECORATE_FULL_REFS 2
20+
1821
struct rev_info;
1922
struct log_info;
2023

t/t4013-diff-various.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ log --root --cc --patch-with-stat --summary master
207207
log -SF master
208208
log -SF -p master
209209
log --decorate --all
210+
log --decorate=full --all
210211
211212
rev-list --parents HEAD
212213
rev-list --children HEAD
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
$ git log --decorate=full --all
2+
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (refs/heads/master)
3+
Merge: 9a6d494 c7a2ab9
4+
Author: A U Thor <[email protected]>
5+
Date: Mon Jun 26 00:04:00 2006 +0000
6+
7+
Merge branch 'side'
8+
9+
commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side)
10+
Author: A U Thor <[email protected]>
11+
Date: Mon Jun 26 00:03:00 2006 +0000
12+
13+
Side
14+
15+
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
16+
Author: A U Thor <[email protected]>
17+
Date: Mon Jun 26 00:02:00 2006 +0000
18+
19+
Third
20+
21+
commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
22+
Author: A U Thor <[email protected]>
23+
Date: Mon Jun 26 00:01:00 2006 +0000
24+
25+
Second
26+
27+
This is the second commit.
28+
29+
commit 444ac553ac7612cc88969031b02b3767fb8a353a (refs/heads/initial)
30+
Author: A U Thor <[email protected]>
31+
Date: Mon Jun 26 00:00:00 2006 +0000
32+
33+
Initial
34+
$

0 commit comments

Comments
 (0)