@@ -1180,11 +1180,28 @@ struct all_refs_cb {
11801180 const char * name_for_errormsg ;
11811181};
11821182
1183+ int ref_excluded (struct string_list * ref_excludes , const char * path )
1184+ {
1185+ struct string_list_item * item ;
1186+
1187+ if (!ref_excludes )
1188+ return 0 ;
1189+ for_each_string_list_item (item , ref_excludes ) {
1190+ if (!fnmatch (item -> string , path , 0 ))
1191+ return 1 ;
1192+ }
1193+ return 0 ;
1194+ }
1195+
11831196static int handle_one_ref (const char * path , const unsigned char * sha1 , int flag , void * cb_data )
11841197{
11851198 struct all_refs_cb * cb = cb_data ;
1186- struct object * object = get_reference (cb -> all_revs , path , sha1 ,
1187- cb -> all_flags );
1199+ struct object * object ;
1200+
1201+ if (ref_excluded (cb -> all_revs -> ref_excludes , path ))
1202+ return 0 ;
1203+
1204+ object = get_reference (cb -> all_revs , path , sha1 , cb -> all_flags );
11881205 add_rev_cmdline (cb -> all_revs , object , path , REV_CMD_REF , cb -> all_flags );
11891206 add_pending_sha1 (cb -> all_revs , path , sha1 , cb -> all_flags );
11901207 return 0 ;
@@ -1197,6 +1214,24 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs,
11971214 cb -> all_flags = flags ;
11981215}
11991216
1217+ void clear_ref_exclusion (struct string_list * * ref_excludes_p )
1218+ {
1219+ if (* ref_excludes_p ) {
1220+ string_list_clear (* ref_excludes_p , 0 );
1221+ free (* ref_excludes_p );
1222+ }
1223+ * ref_excludes_p = NULL ;
1224+ }
1225+
1226+ void add_ref_exclusion (struct string_list * * ref_excludes_p , const char * exclude )
1227+ {
1228+ if (!* ref_excludes_p ) {
1229+ * ref_excludes_p = xcalloc (1 , sizeof (* * ref_excludes_p ));
1230+ (* ref_excludes_p )-> strdup_strings = 1 ;
1231+ }
1232+ string_list_append (* ref_excludes_p , exclude );
1233+ }
1234+
12001235static void handle_refs (const char * submodule , struct rev_info * revs , unsigned flags ,
12011236 int (* for_each )(const char * , each_ref_fn , void * ))
12021237{
@@ -1969,33 +2004,44 @@ static int handle_revision_pseudo_opt(const char *submodule,
19692004 if (!strcmp (arg , "--all" )) {
19702005 handle_refs (submodule , revs , * flags , for_each_ref_submodule );
19712006 handle_refs (submodule , revs , * flags , head_ref_submodule );
2007+ clear_ref_exclusion (& revs -> ref_excludes );
19722008 } else if (!strcmp (arg , "--branches" )) {
19732009 handle_refs (submodule , revs , * flags , for_each_branch_ref_submodule );
2010+ clear_ref_exclusion (& revs -> ref_excludes );
19742011 } else if (!strcmp (arg , "--bisect" )) {
19752012 handle_refs (submodule , revs , * flags , for_each_bad_bisect_ref );
19762013 handle_refs (submodule , revs , * flags ^ (UNINTERESTING | BOTTOM ), for_each_good_bisect_ref );
19772014 revs -> bisect = 1 ;
19782015 } else if (!strcmp (arg , "--tags" )) {
19792016 handle_refs (submodule , revs , * flags , for_each_tag_ref_submodule );
2017+ clear_ref_exclusion (& revs -> ref_excludes );
19802018 } else if (!strcmp (arg , "--remotes" )) {
19812019 handle_refs (submodule , revs , * flags , for_each_remote_ref_submodule );
2020+ clear_ref_exclusion (& revs -> ref_excludes );
19822021 } else if ((argcount = parse_long_opt ("glob" , argv , & optarg ))) {
19832022 struct all_refs_cb cb ;
19842023 init_all_refs_cb (& cb , revs , * flags );
19852024 for_each_glob_ref (handle_one_ref , optarg , & cb );
2025+ clear_ref_exclusion (& revs -> ref_excludes );
2026+ return argcount ;
2027+ } else if ((argcount = parse_long_opt ("exclude" , argv , & optarg ))) {
2028+ add_ref_exclusion (& revs -> ref_excludes , optarg );
19862029 return argcount ;
19872030 } else if (!prefixcmp (arg , "--branches=" )) {
19882031 struct all_refs_cb cb ;
19892032 init_all_refs_cb (& cb , revs , * flags );
19902033 for_each_glob_ref_in (handle_one_ref , arg + 11 , "refs/heads/" , & cb );
2034+ clear_ref_exclusion (& revs -> ref_excludes );
19912035 } else if (!prefixcmp (arg , "--tags=" )) {
19922036 struct all_refs_cb cb ;
19932037 init_all_refs_cb (& cb , revs , * flags );
19942038 for_each_glob_ref_in (handle_one_ref , arg + 7 , "refs/tags/" , & cb );
2039+ clear_ref_exclusion (& revs -> ref_excludes );
19952040 } else if (!prefixcmp (arg , "--remotes=" )) {
19962041 struct all_refs_cb cb ;
19972042 init_all_refs_cb (& cb , revs , * flags );
19982043 for_each_glob_ref_in (handle_one_ref , arg + 10 , "refs/remotes/" , & cb );
2044+ clear_ref_exclusion (& revs -> ref_excludes );
19992045 } else if (!strcmp (arg , "--reflog" )) {
20002046 handle_reflog (revs , * flags );
20012047 } else if (!strcmp (arg , "--not" )) {
0 commit comments