Skip to content

Commit d3fc8dc

Browse files
committed
Merge branch 'ds/log-exclude-decoration-config'
The "--decorate-refs" and "--decorate-refs-exclude" options "git log" takes have learned a companion configuration variable log.excludeDecoration that sits at the lowest priority in the family. * ds/log-exclude-decoration-config: log: add log.excludeDecoration config option log-tree: make ref_filter_match() a helper method
2 parents 93d1f19 + a6be5e6 commit d3fc8dc

File tree

8 files changed

+132
-63
lines changed

8 files changed

+132
-63
lines changed

Documentation/config/log.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ log.decorate::
1818
names are shown. This is the same as the `--decorate` option
1919
of the `git log`.
2020

21+
log.excludeDecoration::
22+
Exclude the specified patterns from the log decorations. This is
23+
similar to the `--decorate-refs-exclude` command-line option, but
24+
the config option can be overridden by the `--decorate-refs`
25+
option.
26+
2127
log.follow::
2228
If `true`, `git log` will act as if the `--follow` option was used when
2329
a single <path> is given. This has the same limitations as `--follow`,

Documentation/git-log.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ OPTIONS
4343
If no `--decorate-refs` is given, pretend as if all refs were
4444
included. For each candidate, do not use it for decoration if it
4545
matches any patterns given to `--decorate-refs-exclude` or if it
46-
doesn't match any of the patterns given to `--decorate-refs`.
46+
doesn't match any of the patterns given to `--decorate-refs`. The
47+
`log.excludeDecoration` config option allows excluding refs from
48+
the decorations, but an explicit `--decorate-refs` pattern will
49+
override a match in `log.excludeDecoration`.
4750

4851
--source::
4952
Print out the ref name given on the command line by which each

builtin/log.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
166166
int quiet = 0, source = 0, mailmap;
167167
static struct line_opt_callback_data line_cb = {NULL, NULL, STRING_LIST_INIT_DUP};
168168
static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
169+
static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
169170
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
170171
struct decoration_filter decoration_filter = {&decorate_refs_include,
171-
&decorate_refs_exclude};
172+
&decorate_refs_exclude,
173+
&decorate_refs_exclude_config};
172174
static struct revision_sources revision_sources;
173175

174176
const struct option builtin_log_options[] = {
@@ -239,7 +241,19 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
239241
}
240242

241243
if (decoration_style) {
244+
const struct string_list *config_exclude =
245+
repo_config_get_value_multi(the_repository,
246+
"log.excludeDecoration");
247+
248+
if (config_exclude) {
249+
struct string_list_item *item;
250+
for_each_string_list_item(item, config_exclude)
251+
string_list_append(&decorate_refs_exclude_config,
252+
item->string);
253+
}
254+
242255
rev->show_decorations = 1;
256+
243257
load_ref_decorations(&decoration_filter, decoration_style);
244258
}
245259

log-tree.c

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,64 @@ const struct name_decoration *get_name_decoration(const struct object *obj)
8181
return lookup_decoration(&name_decoration, obj);
8282
}
8383

84+
static int match_ref_pattern(const char *refname,
85+
const struct string_list_item *item)
86+
{
87+
int matched = 0;
88+
if (item->util == NULL) {
89+
if (!wildmatch(item->string, refname, 0))
90+
matched = 1;
91+
} else {
92+
const char *rest;
93+
if (skip_prefix(refname, item->string, &rest) &&
94+
(!*rest || *rest == '/'))
95+
matched = 1;
96+
}
97+
return matched;
98+
}
99+
100+
static int ref_filter_match(const char *refname,
101+
const struct decoration_filter *filter)
102+
{
103+
struct string_list_item *item;
104+
const struct string_list *exclude_patterns = filter->exclude_ref_pattern;
105+
const struct string_list *include_patterns = filter->include_ref_pattern;
106+
const struct string_list *exclude_patterns_config =
107+
filter->exclude_ref_config_pattern;
108+
109+
if (exclude_patterns && exclude_patterns->nr) {
110+
for_each_string_list_item(item, exclude_patterns) {
111+
if (match_ref_pattern(refname, item))
112+
return 0;
113+
}
114+
}
115+
116+
if (include_patterns && include_patterns->nr) {
117+
for_each_string_list_item(item, include_patterns) {
118+
if (match_ref_pattern(refname, item))
119+
return 1;
120+
}
121+
return 0;
122+
}
123+
124+
if (exclude_patterns_config && exclude_patterns_config->nr) {
125+
for_each_string_list_item(item, exclude_patterns_config) {
126+
if (match_ref_pattern(refname, item))
127+
return 0;
128+
}
129+
}
130+
131+
return 1;
132+
}
133+
84134
static int add_ref_decoration(const char *refname, const struct object_id *oid,
85135
int flags, void *cb_data)
86136
{
87137
struct object *obj;
88138
enum decoration_type type = DECORATION_NONE;
89139
struct decoration_filter *filter = (struct decoration_filter *)cb_data;
90140

91-
if (filter && !ref_filter_match(refname,
92-
filter->include_ref_pattern,
93-
filter->exclude_ref_pattern))
141+
if (filter && !ref_filter_match(refname, filter))
94142
return 0;
95143

96144
if (starts_with(refname, git_replace_ref_base)) {
@@ -155,6 +203,9 @@ void load_ref_decorations(struct decoration_filter *filter, int flags)
155203
for_each_string_list_item(item, filter->include_ref_pattern) {
156204
normalize_glob_ref(item, NULL, item->string);
157205
}
206+
for_each_string_list_item(item, filter->exclude_ref_config_pattern) {
207+
normalize_glob_ref(item, NULL, item->string);
208+
}
158209
}
159210
decoration_loaded = 1;
160211
decoration_flags = flags;

log-tree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ struct log_info {
88
};
99

1010
struct decoration_filter {
11-
struct string_list *include_ref_pattern, *exclude_ref_pattern;
11+
struct string_list *include_ref_pattern;
12+
struct string_list *exclude_ref_pattern;
13+
struct string_list *exclude_ref_config_pattern;
1214
};
1315

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

refs.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -321,50 +321,6 @@ int ref_exists(const char *refname)
321321
return refs_ref_exists(get_main_ref_store(the_repository), refname);
322322
}
323323

324-
static int match_ref_pattern(const char *refname,
325-
const struct string_list_item *item)
326-
{
327-
int matched = 0;
328-
if (item->util == NULL) {
329-
if (!wildmatch(item->string, refname, 0))
330-
matched = 1;
331-
} else {
332-
const char *rest;
333-
if (skip_prefix(refname, item->string, &rest) &&
334-
(!*rest || *rest == '/'))
335-
matched = 1;
336-
}
337-
return matched;
338-
}
339-
340-
int ref_filter_match(const char *refname,
341-
const struct string_list *include_patterns,
342-
const struct string_list *exclude_patterns)
343-
{
344-
struct string_list_item *item;
345-
346-
if (exclude_patterns && exclude_patterns->nr) {
347-
for_each_string_list_item(item, exclude_patterns) {
348-
if (match_ref_pattern(refname, item))
349-
return 0;
350-
}
351-
}
352-
353-
if (include_patterns && include_patterns->nr) {
354-
int found = 0;
355-
for_each_string_list_item(item, include_patterns) {
356-
if (match_ref_pattern(refname, item)) {
357-
found = 1;
358-
break;
359-
}
360-
}
361-
362-
if (!found)
363-
return 0;
364-
}
365-
return 1;
366-
}
367-
368324
static int filter_refs(const char *refname, const struct object_id *oid,
369325
int flags, void *data)
370326
{

refs.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,6 @@ int for_each_rawref(each_ref_fn fn, void *cb_data);
361361
void normalize_glob_ref(struct string_list_item *item, const char *prefix,
362362
const char *pattern);
363363

364-
/*
365-
* Returns 0 if refname matches any of the exclude_patterns, or if it doesn't
366-
* match any of the include_patterns. Returns 1 otherwise.
367-
*
368-
* If pattern list is NULL or empty, matching against that list is skipped.
369-
* This has the effect of matching everything by default, unless the user
370-
* specifies rules otherwise.
371-
*/
372-
int ref_filter_match(const char *refname,
373-
const struct string_list *include_patterns,
374-
const struct string_list *exclude_patterns);
375-
376364
static inline const char *has_glob_specials(const char *pattern)
377365
{
378366
return strpbrk(pattern, "?*[");

t/t4202-log.sh

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,23 @@ test_expect_success 'decorate-refs with glob' '
742742
octopus-a (octopus-a)
743743
reach
744744
EOF
745+
cat >expect.no-decorate <<-\EOF &&
746+
Merge-tag-reach
747+
Merge-tags-octopus-a-and-octopus-b
748+
seventh
749+
octopus-b
750+
octopus-a
751+
reach
752+
EOF
753+
git log -n6 --decorate=short --pretty="tformat:%f%d" \
754+
--decorate-refs="heads/octopus*" >actual &&
755+
test_cmp expect.decorate actual &&
745756
git log -n6 --decorate=short --pretty="tformat:%f%d" \
757+
--decorate-refs-exclude="heads/octopus*" \
758+
--decorate-refs="heads/octopus*" >actual &&
759+
test_cmp expect.no-decorate actual &&
760+
git -c log.excludeDecoration="heads/octopus*" log \
761+
-n6 --decorate=short --pretty="tformat:%f%d" \
746762
--decorate-refs="heads/octopus*" >actual &&
747763
test_cmp expect.decorate actual
748764
'
@@ -787,6 +803,9 @@ test_expect_success 'decorate-refs-exclude with glob' '
787803
EOF
788804
git log -n6 --decorate=short --pretty="tformat:%f%d" \
789805
--decorate-refs-exclude="heads/octopus*" >actual &&
806+
test_cmp expect.decorate actual &&
807+
git -c log.excludeDecoration="heads/octopus*" log \
808+
-n6 --decorate=short --pretty="tformat:%f%d" >actual &&
790809
test_cmp expect.decorate actual
791810
'
792811

@@ -801,6 +820,9 @@ test_expect_success 'decorate-refs-exclude without globs' '
801820
EOF
802821
git log -n6 --decorate=short --pretty="tformat:%f%d" \
803822
--decorate-refs-exclude="tags/reach" >actual &&
823+
test_cmp expect.decorate actual &&
824+
git -c log.excludeDecoration="tags/reach" log \
825+
-n6 --decorate=short --pretty="tformat:%f%d" >actual &&
804826
test_cmp expect.decorate actual
805827
'
806828

@@ -816,11 +838,19 @@ test_expect_success 'multiple decorate-refs-exclude' '
816838
git log -n6 --decorate=short --pretty="tformat:%f%d" \
817839
--decorate-refs-exclude="heads/octopus*" \
818840
--decorate-refs-exclude="tags/reach" >actual &&
841+
test_cmp expect.decorate actual &&
842+
git -c log.excludeDecoration="heads/octopus*" \
843+
-c log.excludeDecoration="tags/reach" log \
844+
-n6 --decorate=short --pretty="tformat:%f%d" >actual &&
845+
test_cmp expect.decorate actual &&
846+
git -c log.excludeDecoration="heads/octopus*" log \
847+
--decorate-refs-exclude="tags/reach" \
848+
-n6 --decorate=short --pretty="tformat:%f%d" >actual &&
819849
test_cmp expect.decorate actual
820850
'
821851

822852
test_expect_success 'decorate-refs and decorate-refs-exclude' '
823-
cat >expect.decorate <<-\EOF &&
853+
cat >expect.no-decorate <<-\EOF &&
824854
Merge-tag-reach (master)
825855
Merge-tags-octopus-a-and-octopus-b
826856
seventh
@@ -831,6 +861,21 @@ test_expect_success 'decorate-refs and decorate-refs-exclude' '
831861
git log -n6 --decorate=short --pretty="tformat:%f%d" \
832862
--decorate-refs="heads/*" \
833863
--decorate-refs-exclude="heads/oc*" >actual &&
864+
test_cmp expect.no-decorate actual
865+
'
866+
867+
test_expect_success 'deocrate-refs and log.excludeDecoration' '
868+
cat >expect.decorate <<-\EOF &&
869+
Merge-tag-reach (master)
870+
Merge-tags-octopus-a-and-octopus-b
871+
seventh
872+
octopus-b (octopus-b)
873+
octopus-a (octopus-a)
874+
reach (reach)
875+
EOF
876+
git -c log.excludeDecoration="heads/oc*" log \
877+
--decorate-refs="heads/*" \
878+
-n6 --decorate=short --pretty="tformat:%f%d" >actual &&
834879
test_cmp expect.decorate actual
835880
'
836881

@@ -846,6 +891,10 @@ test_expect_success 'decorate-refs-exclude and simplify-by-decoration' '
846891
git log -n6 --decorate=short --pretty="tformat:%f%d" \
847892
--decorate-refs-exclude="*octopus*" \
848893
--simplify-by-decoration >actual &&
894+
test_cmp expect.decorate actual &&
895+
git -c log.excludeDecoration="*octopus*" log \
896+
-n6 --decorate=short --pretty="tformat:%f%d" \
897+
--simplify-by-decoration >actual &&
849898
test_cmp expect.decorate actual
850899
'
851900

0 commit comments

Comments
 (0)