Skip to content

Commit a6be5e6

Browse files
derrickstoleegitster
authored andcommitted
log: add log.excludeDecoration config option
In 'git log', the --decorate-refs-exclude option appends a pattern to a string_list. This list is used to prevent showing some refs in the decoration output, or even by --simplify-by-decoration. Users may want to use their refs space to store utility refs that should not appear in the decoration output. For example, Scalar [1] runs a background fetch but places the "new" refs inside the refs/scalar/hidden/<remote>/* refspace instead of refs/<remote>/* to avoid updating remote refs when the user is not looking. However, these "hidden" refs appear during regular 'git log' queries. A similar idea to use "hidden" refs is under consideration for core Git [2]. Add the 'log.excludeDecoration' config option so users can exclude some refs from decorations by default instead of needing to use --decorate-refs-exclude manually. The config value is multi-valued much like the command-line option. The documentation is careful to point out that the config value can be overridden by the --decorate-refs option, even though --decorate-refs-exclude would always "win" over --decorate-refs. Since the 'log.excludeDecoration' takes lower precedence to --decorate-refs, and --decorate-refs-exclude takes higher precedence, the struct decoration_filter needed another field. This led also to new logic in load_ref_decorations() and ref_filter_match(). There are several tests in t4202-log.sh that test the --decorate-refs-(include|exclude) options, so these are extended. Since the expected output is already stored as a file, most tests could simply replace a "--decorate-refs-exclude" option with an in-line config setting. Other tests involve the precedence of the config option compared to command-line options and needed more modification. [1] https://github.com/microsoft/scalar [2] https://lore.kernel.org/git/77b1da5d3063a2404cd750adfe3bb8be9b6c497d.1585946894.git.gitgitgadget@gmail.com/ Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9f7a79 commit a6be5e6

File tree

6 files changed

+93
-11
lines changed

6 files changed

+93
-11
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
@@ -164,9 +164,11 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
164164
int quiet = 0, source = 0, mailmap;
165165
static struct line_opt_callback_data line_cb = {NULL, NULL, STRING_LIST_INIT_DUP};
166166
static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
167+
static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
167168
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
168169
struct decoration_filter decoration_filter = {&decorate_refs_include,
169-
&decorate_refs_exclude};
170+
&decorate_refs_exclude,
171+
&decorate_refs_exclude_config};
170172
static struct revision_sources revision_sources;
171173

172174
const struct option builtin_log_options[] = {
@@ -236,7 +238,19 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
236238
}
237239

238240
if (decoration_style) {
241+
const struct string_list *config_exclude =
242+
repo_config_get_value_multi(the_repository,
243+
"log.excludeDecoration");
244+
245+
if (config_exclude) {
246+
struct string_list_item *item;
247+
for_each_string_list_item(item, config_exclude)
248+
string_list_append(&decorate_refs_exclude_config,
249+
item->string);
250+
}
251+
239252
rev->show_decorations = 1;
253+
240254
load_ref_decorations(&decoration_filter, decoration_style);
241255
}
242256

log-tree.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ static int ref_filter_match(const char *refname,
103103
struct string_list_item *item;
104104
const struct string_list *exclude_patterns = filter->exclude_ref_pattern;
105105
const struct string_list *include_patterns = filter->include_ref_pattern;
106+
const struct string_list *exclude_patterns_config =
107+
filter->exclude_ref_config_pattern;
106108

107109
if (exclude_patterns && exclude_patterns->nr) {
108110
for_each_string_list_item(item, exclude_patterns) {
@@ -112,17 +114,20 @@ static int ref_filter_match(const char *refname,
112114
}
113115

114116
if (include_patterns && include_patterns->nr) {
115-
int found = 0;
116117
for_each_string_list_item(item, include_patterns) {
117-
if (match_ref_pattern(refname, item)) {
118-
found = 1;
119-
break;
120-
}
118+
if (match_ref_pattern(refname, item))
119+
return 1;
121120
}
121+
return 0;
122+
}
122123

123-
if (!found)
124-
return 0;
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+
}
125129
}
130+
126131
return 1;
127132
}
128133

@@ -198,6 +203,9 @@ void load_ref_decorations(struct decoration_filter *filter, int flags)
198203
for_each_string_list_item(item, filter->include_ref_pattern) {
199204
normalize_glob_ref(item, NULL, item->string);
200205
}
206+
for_each_string_list_item(item, filter->exclude_ref_config_pattern) {
207+
normalize_glob_ref(item, NULL, item->string);
208+
}
201209
}
202210
decoration_loaded = 1;
203211
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);

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)