@matheusbsbs / matheus-bagliano / commits / a6be5e6764
Fork 0

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 <gister@pobox.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Apr 16, 2020 at 14:15 UTC a6be5e6764aabd4b418f7f365254518ec44c38d8
6 files changed +93 -11
Documentation/config/log.txt
+6
@@ -18,6 +18,12 @@ log.decorate::
18 names are shown. This is the same as the `--decorate` option
19 of the `git log`.
20
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 +
27 log.follow::
28 If `true`, `git log` will act as if the `--follow` option was used when
29 a single <path> is given. This has the same limitations as `--follow`,
Documentation/git-log.txt
+4 -1
@@ -43,7 +43,10 @@ OPTIONS
43 If no `--decorate-refs` is given, pretend as if all refs were
44 included. For each candidate, do not use it for decoration if it
45 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`.
50
51 --source::
52 Print out the ref name given on the command line by which each
builtin/log.c
+15 -1
@@ -164,9 +164,11 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
164 int quiet = 0, source = 0, mailmap;
165 static struct line_opt_callback_data line_cb = {NULL, NULL, STRING_LIST_INIT_DUP};
166 static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
167 + static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
168 static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
169 struct decoration_filter decoration_filter = {&decorate_refs_include,
169 - &decorate_refs_exclude};
170 + &decorate_refs_exclude,
171 + &decorate_refs_exclude_config};
172 static struct revision_sources revision_sources;
173
174 const struct option builtin_log_options[] = {
@@ -236,7 +238,19 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
238 }
239
240 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 +
252 rev->show_decorations = 1;
253 +
254 load_ref_decorations(&decoration_filter, decoration_style);
255 }
256
log-tree.c
+15 -7
@@ -103,6 +103,8 @@ static int ref_filter_match(const char *refname,
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) {
@@ -112,17 +114,20 @@ static int ref_filter_match(const char *refname,
114 }
115
116 if (include_patterns && include_patterns->nr) {
115 - int found = 0;
117 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;
120 }
121 + return 0;
122 + }
123
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 + }
129 }
130 +
131 return 1;
132 }
133
@@ -198,6 +203,9 @@ void load_ref_decorations(struct decoration_filter *filter, int flags)
203 for_each_string_list_item(item, filter->include_ref_pattern) {
204 normalize_glob_ref(item, NULL, item->string);
205 }
206 + for_each_string_list_item(item, filter->exclude_ref_config_pattern) {
207 + normalize_glob_ref(item, NULL, item->string);
208 + }
209 }
210 decoration_loaded = 1;
211 decoration_flags = flags;
log-tree.h
+3 -1
@@ -8,7 +8,9 @@ struct log_info {
8 };
9
10 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;
14 };
15
16 int parse_decorate_color_config(const char *var, const char *slot_name, const char *value);
t/t4202-log.sh
+50 -1
@@ -742,7 +742,23 @@ test_expect_success 'decorate-refs with glob' '
742 octopus-a (octopus-a)
743 reach
744 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 &&
756 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" \
762 --decorate-refs="heads/octopus*" >actual &&
763 test_cmp expect.decorate actual
764 '
@@ -787,6 +803,9 @@ test_expect_success 'decorate-refs-exclude with glob' '
803 EOF
804 git log -n6 --decorate=short --pretty="tformat:%f%d" \
805 --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 &&
809 test_cmp expect.decorate actual
810 '
811
@@ -801,6 +820,9 @@ test_expect_success 'decorate-refs-exclude without globs' '
820 EOF
821 git log -n6 --decorate=short --pretty="tformat:%f%d" \
822 --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 &&
826 test_cmp expect.decorate actual
827 '
828
@@ -816,11 +838,19 @@ test_expect_success 'multiple decorate-refs-exclude' '
838 git log -n6 --decorate=short --pretty="tformat:%f%d" \
839 --decorate-refs-exclude="heads/octopus*" \
840 --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 &&
849 test_cmp expect.decorate actual
850 '
851
852 test_expect_success 'decorate-refs and decorate-refs-exclude' '
823 - cat >expect.decorate <<-\EOF &&
853 + cat >expect.no-decorate <<-\EOF &&
854 Merge-tag-reach (master)
855 Merge-tags-octopus-a-and-octopus-b
856 seventh
@@ -831,6 +861,21 @@ test_expect_success 'decorate-refs and decorate-refs-exclude' '
861 git log -n6 --decorate=short --pretty="tformat:%f%d" \
862 --decorate-refs="heads/*" \
863 --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 &&
879 test_cmp expect.decorate actual
880 '
881
@@ -846,6 +891,10 @@ test_expect_success 'decorate-refs-exclude and simplify-by-decoration' '
891 git log -n6 --decorate=short --pretty="tformat:%f%d" \
892 --decorate-refs-exclude="*octopus*" \
893 --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 &&
898 test_cmp expect.decorate actual
899 '
900