@@ -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+
104118static int decorate_callback (const struct option * opt , const char * arg , int unset )
105119{
106120 if (unset )
@@ -162,25 +176,72 @@ static void cmd_log_init_defaults(struct rev_info *rev)
162176 parse_date_format (default_date_mode , & rev -> date_mode );
163177}
164178
179+ static void set_default_decoration_filter (struct decoration_filter * decoration_filter )
180+ {
181+ int i ;
182+ char * value = NULL ;
183+ struct string_list * include = decoration_filter -> include_ref_pattern ;
184+ const struct string_list * config_exclude =
185+ git_config_get_value_multi ("log.excludeDecoration" );
186+
187+ if (config_exclude ) {
188+ struct string_list_item * item ;
189+ for_each_string_list_item (item , config_exclude )
190+ string_list_append (decoration_filter -> exclude_ref_config_pattern ,
191+ item -> string );
192+ }
193+
194+ /*
195+ * By default, decorate_all is disabled. Enable it if
196+ * log.initialDecorationSet=all. Don't ever disable it by config,
197+ * since the command-line takes precedent.
198+ */
199+ if (use_default_decoration_filter &&
200+ !git_config_get_string ("log.initialdecorationset" , & value ) &&
201+ !strcmp ("all" , value ))
202+ use_default_decoration_filter = 0 ;
203+ free (value );
204+
205+ if (!use_default_decoration_filter ||
206+ decoration_filter -> exclude_ref_pattern -> nr ||
207+ decoration_filter -> include_ref_pattern -> nr ||
208+ decoration_filter -> exclude_ref_config_pattern -> nr )
209+ return ;
210+
211+ /*
212+ * No command-line or config options were given, so
213+ * populate with sensible defaults.
214+ */
215+ for (i = 0 ; i < ARRAY_SIZE (ref_namespace ); i ++ ) {
216+ if (!ref_namespace [i ].decoration )
217+ continue ;
218+
219+ string_list_append (include , ref_namespace [i ].ref );
220+ }
221+ }
222+
165223static void cmd_log_init_finish (int argc , const char * * argv , const char * prefix ,
166224 struct rev_info * rev , struct setup_revision_opt * opt )
167225{
168226 struct userformat_want w ;
169227 int quiet = 0 , source = 0 , mailmap ;
170228 static struct line_opt_callback_data line_cb = {NULL , NULL , STRING_LIST_INIT_DUP };
171- static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP ;
172- static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP ;
173- static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP ;
174- struct decoration_filter decoration_filter = {& decorate_refs_include ,
175- & decorate_refs_exclude ,
176- & decorate_refs_exclude_config };
229+ struct decoration_filter decoration_filter = {
230+ .exclude_ref_pattern = & decorate_refs_exclude ,
231+ .include_ref_pattern = & decorate_refs_include ,
232+ .exclude_ref_config_pattern = & decorate_refs_exclude_config ,
233+ };
177234 static struct revision_sources revision_sources ;
178235
179236 const struct option builtin_log_options [] = {
180237 OPT__QUIET (& quiet , N_ ("suppress diff output" )),
181238 OPT_BOOL (0 , "source" , & source , N_ ("show source" )),
182239 OPT_BOOL (0 , "use-mailmap" , & mailmap , N_ ("use mail map file" )),
183240 OPT_ALIAS (0 , "mailmap" , "use-mailmap" ),
241+ OPT_CALLBACK_F (0 , "clear-decorations" , NULL , NULL ,
242+ N_ ("clear all previously-defined decoration filters" ),
243+ PARSE_OPT_NOARG | PARSE_OPT_NONEG ,
244+ clear_decorations_callback ),
184245 OPT_STRING_LIST (0 , "decorate-refs" , & decorate_refs_include ,
185246 N_ ("pattern" ), N_ ("only decorate refs that match <pattern>" )),
186247 OPT_STRING_LIST (0 , "decorate-refs-exclude" , & decorate_refs_exclude ,
@@ -265,16 +326,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
265326 }
266327
267328 if (decoration_style || rev -> simplify_by_decoration ) {
268- const struct string_list * config_exclude =
269- repo_config_get_value_multi (the_repository ,
270- "log.excludeDecoration" );
271-
272- if (config_exclude ) {
273- struct string_list_item * item ;
274- for_each_string_list_item (item , config_exclude )
275- string_list_append (& decorate_refs_exclude_config ,
276- item -> string );
277- }
329+ set_default_decoration_filter (& decoration_filter );
278330
279331 if (decoration_style )
280332 rev -> show_decorations = 1 ;
0 commit comments