git-log: allow --decorate[=short|full]
Commit de435ac0 changed the behavior of --decorate from printing the full ref (e.g., "refs/heads/master") to a shorter, more human-readable version (e.g., just "master"). While this is nice for human readers, external tools using the output from "git log" may prefer the full version. This patch introduces an extension to --decorate to allow the caller to specify either the short or the full versions. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Hjemli committed
Aug 15, 2009 at 16:23 UTC
d8526a4c3b31d91b623f698be6ed7552ed4fdc52
9 files changed
+65
-10
Documentation/git-log.txt
+6
-2
@@ -37,8 +37,12 @@ include::diff-options.txt[]
37
and <until>, see "SPECIFYING REVISIONS" section in
38
linkgit:git-rev-parse[1].
39
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'.
46
47
--source::
48
Print out the ref name given on the command line by which each
builtin-log.c
+14
-2
@@ -31,6 +31,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
31
struct rev_info *rev)
32
{
33
int i;
34
+ int decoration_style = 0;
35
36
rev->abbrev = DEFAULT_ABBREV;
37
rev->commit_format = CMIT_FMT_DEFAULT;
@@ -57,13 +58,24 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
58
for (i = 1; i < argc; i++) {
59
const char *arg = argv[i];
60
if (!strcmp(arg, "--decorate")) {
60
- load_ref_decorations();
61
- rev->show_decorations = 1;
61
+ decoration_style = DECORATE_SHORT_REFS;
62
+ } else if (!prefixcmp(arg, "--decorate=")) {
63
+ const char *v = skip_prefix(arg, "--decorate=");
64
+ if (!strcmp(v, "full"))
65
+ decoration_style = DECORATE_FULL_REFS;
66
+ else if (!strcmp(v, "short"))
67
+ decoration_style = DECORATE_SHORT_REFS;
68
+ else
69
+ die("invalid --decorate option: %s", arg);
70
} else if (!strcmp(arg, "--source")) {
71
rev->show_source = 1;
72
} else
73
die("unrecognized argument: %s", arg);
74
}
75
+ if (decoration_style) {
76
+ rev->show_decorations = 1;
77
+ load_ref_decorations(decoration_style);
78
+ }
79
}
80
81
/*
log-tree.c
+4
-3
@@ -25,7 +25,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
25
struct object *obj = parse_object(sha1);
26
if (!obj)
27
return 0;
28
- refname = prettify_refname(refname);
28
+ if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
29
+ refname = prettify_refname(refname);
30
add_name_decoration("", refname, obj);
31
while (obj->type == OBJ_TAG) {
32
obj = ((struct tag *)obj)->tagged;
@@ -36,12 +37,12 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
37
return 0;
38
}
39
39
-void load_ref_decorations(void)
40
+void load_ref_decorations(int flags)
41
{
42
static int loaded;
43
if (!loaded) {
44
loaded = 1;
44
- for_each_ref(add_ref_decoration, NULL);
45
+ for_each_ref(add_ref_decoration, &flags);
46
}
47
}
48
log-tree.h
+1
-1
@@ -17,7 +17,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
17
const char **subject_p,
18
const char **extra_headers_p,
19
int *need_8bit_cte_p);
20
-void load_ref_decorations(void);
20
+void load_ref_decorations(int flags);
21
22
#define FORMAT_PATCH_NAME_MAX 64
23
void get_patch_filename(struct commit *commit, int nr, const char *suffix,
pretty.c
+1
-1
@@ -583,7 +583,7 @@ static void format_decoration(struct strbuf *sb, const struct commit *commit)
583
struct name_decoration *d;
584
const char *prefix = " (";
585
586
- load_ref_decorations();
586
+ load_ref_decorations(DECORATE_SHORT_REFS);
587
d = lookup_decoration(&name_decoration, &commit->object);
588
while (d) {
589
strbuf_addstr(sb, prefix);
revision.c
+1
-1
@@ -1052,7 +1052,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1052
revs->simplify_by_decoration = 1;
1053
revs->limited = 1;
1054
revs->prune = 1;
1055
- load_ref_decorations();
1055
+ load_ref_decorations(DECORATE_SHORT_REFS);
1056
} else if (!strcmp(arg, "--date-order")) {
1057
revs->lifo = 0;
1058
revs->topo_order = 1;
revision.h
+3
@@ -15,6 +15,9 @@
15
#define SYMMETRIC_LEFT (1u<<8)
16
#define ALL_REV_FLAGS ((1u<<9)-1)
17
18
+#define DECORATE_SHORT_REFS 1
19
+#define DECORATE_FULL_REFS 2
20
+
21
struct rev_info;
22
struct log_info;
23
t/t4013-diff-various.sh
+1
@@ -207,6 +207,7 @@ log --root --cc --patch-with-stat --summary master
207
log -SF master
208
log -SF -p master
209
log --decorate --all
210
+log --decorate=full --all
211
212
rev-list --parents HEAD
213
rev-list --children HEAD
t/t4013/diff.log_--decorate=full_--all
new
+34
@@ -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 <author@example.com>
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 <author@example.com>
11
+Date: Mon Jun 26 00:03:00 2006 +0000
12
+
13
+ Side
14
+
15
+commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
16
+Author: A U Thor <author@example.com>
17
+Date: Mon Jun 26 00:02:00 2006 +0000
18
+
19
+ Third
20
+
21
+commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
22
+Author: A U Thor <author@example.com>
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 <author@example.com>
31
+Date: Mon Jun 26 00:00:00 2006 +0000
32
+
33
+ Initial
34
+$