Skip to content

Commit 748706d

Browse files
derrickstoleegitster
authored andcommitted
log: add --clear-decorations option
The previous changes introduced a new default ref filter for decorations in the 'git log' command. This can be overridden using --decorate-refs=HEAD and --decorate-refs=refs/, but that is cumbersome for users. Instead, add a --clear-decorations option that resets all previous filters to a blank filter that accepts all refs. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9215629 commit 748706d

8 files changed

+371
-7
lines changed

Documentation/git-log.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ If none of these options or config settings are given, then references are
5656
used as decoration if they match `HEAD`, `refs/heads/`, `refs/remotes/`,
5757
`refs/stash/`, or `refs/tags/`.
5858

59+
--clear-decorations::
60+
When specified, this option clears all previous `--decorate-refs`
61+
or `--decorate-refs-exclude` options and relaxes the default
62+
decoration filter to include all references.
63+
5964
--source::
6065
Print out the ref name given on the command line by which each
6166
commit was reached.

builtin/log.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ static int parse_decoration_style(const char *value)
101101
return -1;
102102
}
103103

104+
static int use_default_decoration_filter = 1;
105+
static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
106+
static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
107+
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
108+
109+
static int clear_decorations_callback(const struct option *opt,
110+
const char *arg, int unset)
111+
{
112+
string_list_clear(&decorate_refs_include, 0);
113+
string_list_clear(&decorate_refs_exclude, 0);
114+
use_default_decoration_filter = 0;
115+
return 0;
116+
}
117+
104118
static int decorate_callback(const struct option *opt, const char *arg, int unset)
105119
{
106120
if (unset)
@@ -176,7 +190,8 @@ static void set_default_decoration_filter(struct decoration_filter *decoration_f
176190
item->string);
177191
}
178192

179-
if (decoration_filter->exclude_ref_pattern->nr ||
193+
if (!use_default_decoration_filter ||
194+
decoration_filter->exclude_ref_pattern->nr ||
180195
decoration_filter->include_ref_pattern->nr ||
181196
decoration_filter->exclude_ref_config_pattern->nr)
182197
return;
@@ -199,9 +214,6 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
199214
struct userformat_want w;
200215
int quiet = 0, source = 0, mailmap;
201216
static struct line_opt_callback_data line_cb = {NULL, NULL, STRING_LIST_INIT_DUP};
202-
static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
203-
static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
204-
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
205217
struct decoration_filter decoration_filter = {
206218
.exclude_ref_pattern = &decorate_refs_exclude,
207219
.include_ref_pattern = &decorate_refs_include,
@@ -214,6 +226,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
214226
OPT_BOOL(0, "source", &source, N_("show source")),
215227
OPT_BOOL(0, "use-mailmap", &mailmap, N_("use mail map file")),
216228
OPT_ALIAS(0, "mailmap", "use-mailmap"),
229+
OPT_CALLBACK_F(0, "clear-decorations", NULL, NULL,
230+
N_("clear all previously-defined decoration filters"),
231+
PARSE_OPT_NOARG | PARSE_OPT_NONEG,
232+
clear_decorations_callback),
217233
OPT_STRING_LIST(0, "decorate-refs", &decorate_refs_include,
218234
N_("pattern"), N_("only decorate refs that match <pattern>")),
219235
OPT_STRING_LIST(0, "decorate-refs-exclude", &decorate_refs_exclude,

t/t4013-diff-various.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ log -GF -p --pickaxe-all master
352352
log -IA -IB -I1 -I2 -p master
353353
log --decorate --all
354354
log --decorate=full --all
355+
log --decorate --clear-decorations --all
356+
log --decorate=full --clear-decorations --all
355357
356358
rev-list --parents HEAD
357359
rev-list --children HEAD
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
$ git log --decorate=full --clear-decorations --all
2+
commit b7e0bc69303b488b47deca799a7d723971dfa6cd (refs/heads/mode)
3+
Author: A U Thor <[email protected]>
4+
Date: Mon Jun 26 00:06:00 2006 +0000
5+
6+
update mode
7+
8+
commit a6f364368ca320bc5a92e18912e16fa6b3dff598 (refs/heads/note)
9+
Author: A U Thor <[email protected]>
10+
Date: Mon Jun 26 00:06:00 2006 +0000
11+
12+
update mode (file2)
13+
14+
Notes:
15+
note
16+
17+
commit cd4e72fd96faed3f0ba949dc42967430374e2290 (refs/heads/rearrange)
18+
Author: A U Thor <[email protected]>
19+
Date: Mon Jun 26 00:06:00 2006 +0000
20+
21+
Rearranged lines in dir/sub
22+
23+
commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits)
24+
Author: A U Thor <[email protected]>
25+
Date: Mon Jun 26 00:06:00 2006 +0000
26+
27+
Notes added by 'git notes add'
28+
29+
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> refs/heads/master)
30+
Merge: 9a6d494 c7a2ab9
31+
Author: A U Thor <[email protected]>
32+
Date: Mon Jun 26 00:04:00 2006 +0000
33+
34+
Merge branch 'side'
35+
36+
commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side)
37+
Author: A U Thor <[email protected]>
38+
Date: Mon Jun 26 00:03:00 2006 +0000
39+
40+
Side
41+
42+
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
43+
Author: A U Thor <[email protected]>
44+
Date: Mon Jun 26 00:02:00 2006 +0000
45+
46+
Third
47+
48+
commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
49+
Author: A U Thor <[email protected]>
50+
Date: Mon Jun 26 00:01:00 2006 +0000
51+
52+
Second
53+
54+
This is the second commit.
55+
56+
commit 444ac553ac7612cc88969031b02b3767fb8a353a (refs/heads/initial)
57+
Author: A U Thor <[email protected]>
58+
Date: Mon Jun 26 00:00:00 2006 +0000
59+
60+
Initial
61+
$
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
$ git log --decorate=full --decorate-all --all
2+
commit b7e0bc69303b488b47deca799a7d723971dfa6cd (refs/heads/mode)
3+
Author: A U Thor <[email protected]>
4+
Date: Mon Jun 26 00:06:00 2006 +0000
5+
6+
update mode
7+
8+
commit a6f364368ca320bc5a92e18912e16fa6b3dff598 (refs/heads/note)
9+
Author: A U Thor <[email protected]>
10+
Date: Mon Jun 26 00:06:00 2006 +0000
11+
12+
update mode (file2)
13+
14+
Notes:
15+
note
16+
17+
commit cd4e72fd96faed3f0ba949dc42967430374e2290 (refs/heads/rearrange)
18+
Author: A U Thor <[email protected]>
19+
Date: Mon Jun 26 00:06:00 2006 +0000
20+
21+
Rearranged lines in dir/sub
22+
23+
commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits)
24+
Author: A U Thor <[email protected]>
25+
Date: Mon Jun 26 00:06:00 2006 +0000
26+
27+
Notes added by 'git notes add'
28+
29+
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> refs/heads/master)
30+
Merge: 9a6d494 c7a2ab9
31+
Author: A U Thor <[email protected]>
32+
Date: Mon Jun 26 00:04:00 2006 +0000
33+
34+
Merge branch 'side'
35+
36+
commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side)
37+
Author: A U Thor <[email protected]>
38+
Date: Mon Jun 26 00:03:00 2006 +0000
39+
40+
Side
41+
42+
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
43+
Author: A U Thor <[email protected]>
44+
Date: Mon Jun 26 00:02:00 2006 +0000
45+
46+
Third
47+
48+
commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
49+
Author: A U Thor <[email protected]>
50+
Date: Mon Jun 26 00:01:00 2006 +0000
51+
52+
Second
53+
54+
This is the second commit.
55+
56+
commit 444ac553ac7612cc88969031b02b3767fb8a353a (refs/heads/initial)
57+
Author: A U Thor <[email protected]>
58+
Date: Mon Jun 26 00:00:00 2006 +0000
59+
60+
Initial
61+
$
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
$ git log --decorate --clear-decorations --all
2+
commit b7e0bc69303b488b47deca799a7d723971dfa6cd (mode)
3+
Author: A U Thor <[email protected]>
4+
Date: Mon Jun 26 00:06:00 2006 +0000
5+
6+
update mode
7+
8+
commit a6f364368ca320bc5a92e18912e16fa6b3dff598 (note)
9+
Author: A U Thor <[email protected]>
10+
Date: Mon Jun 26 00:06:00 2006 +0000
11+
12+
update mode (file2)
13+
14+
Notes:
15+
note
16+
17+
commit cd4e72fd96faed3f0ba949dc42967430374e2290 (rearrange)
18+
Author: A U Thor <[email protected]>
19+
Date: Mon Jun 26 00:06:00 2006 +0000
20+
21+
Rearranged lines in dir/sub
22+
23+
commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits)
24+
Author: A U Thor <[email protected]>
25+
Date: Mon Jun 26 00:06:00 2006 +0000
26+
27+
Notes added by 'git notes add'
28+
29+
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> master)
30+
Merge: 9a6d494 c7a2ab9
31+
Author: A U Thor <[email protected]>
32+
Date: Mon Jun 26 00:04:00 2006 +0000
33+
34+
Merge branch 'side'
35+
36+
commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (side)
37+
Author: A U Thor <[email protected]>
38+
Date: Mon Jun 26 00:03:00 2006 +0000
39+
40+
Side
41+
42+
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
43+
Author: A U Thor <[email protected]>
44+
Date: Mon Jun 26 00:02:00 2006 +0000
45+
46+
Third
47+
48+
commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
49+
Author: A U Thor <[email protected]>
50+
Date: Mon Jun 26 00:01:00 2006 +0000
51+
52+
Second
53+
54+
This is the second commit.
55+
56+
commit 444ac553ac7612cc88969031b02b3767fb8a353a (initial)
57+
Author: A U Thor <[email protected]>
58+
Date: Mon Jun 26 00:00:00 2006 +0000
59+
60+
Initial
61+
$
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
$ git log --decorate --decorate-all --all
2+
commit b7e0bc69303b488b47deca799a7d723971dfa6cd (mode)
3+
Author: A U Thor <[email protected]>
4+
Date: Mon Jun 26 00:06:00 2006 +0000
5+
6+
update mode
7+
8+
commit a6f364368ca320bc5a92e18912e16fa6b3dff598 (note)
9+
Author: A U Thor <[email protected]>
10+
Date: Mon Jun 26 00:06:00 2006 +0000
11+
12+
update mode (file2)
13+
14+
Notes:
15+
note
16+
17+
commit cd4e72fd96faed3f0ba949dc42967430374e2290 (rearrange)
18+
Author: A U Thor <[email protected]>
19+
Date: Mon Jun 26 00:06:00 2006 +0000
20+
21+
Rearranged lines in dir/sub
22+
23+
commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits)
24+
Author: A U Thor <[email protected]>
25+
Date: Mon Jun 26 00:06:00 2006 +0000
26+
27+
Notes added by 'git notes add'
28+
29+
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> master)
30+
Merge: 9a6d494 c7a2ab9
31+
Author: A U Thor <[email protected]>
32+
Date: Mon Jun 26 00:04:00 2006 +0000
33+
34+
Merge branch 'side'
35+
36+
commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (side)
37+
Author: A U Thor <[email protected]>
38+
Date: Mon Jun 26 00:03:00 2006 +0000
39+
40+
Side
41+
42+
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
43+
Author: A U Thor <[email protected]>
44+
Date: Mon Jun 26 00:02:00 2006 +0000
45+
46+
Third
47+
48+
commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
49+
Author: A U Thor <[email protected]>
50+
Date: Mon Jun 26 00:01:00 2006 +0000
51+
52+
Second
53+
54+
This is the second commit.
55+
56+
commit 444ac553ac7612cc88969031b02b3767fb8a353a (initial)
57+
Author: A U Thor <[email protected]>
58+
Date: Mon Jun 26 00:00:00 2006 +0000
59+
60+
Initial
61+
$

0 commit comments

Comments
 (0)