11#include "cache.h"
2+ #include "config.h"
23#include "object-store.h"
34#include "tag.h"
45#include "blob.h"
@@ -1519,11 +1520,17 @@ static void add_rev_cmdline_list(struct rev_info *revs,
15191520
15201521int ref_excluded (const struct ref_exclusions * exclusions , const char * path )
15211522{
1523+ const char * stripped_path = strip_namespace (path );
15221524 struct string_list_item * item ;
1525+
15231526 for_each_string_list_item (item , & exclusions -> excluded_refs ) {
15241527 if (!wildmatch (item -> string , path , 0 ))
15251528 return 1 ;
15261529 }
1530+
1531+ if (ref_is_hidden (stripped_path , path , & exclusions -> hidden_refs ))
1532+ return 1 ;
1533+
15271534 return 0 ;
15281535}
15291536
@@ -1536,13 +1543,44 @@ void init_ref_exclusions(struct ref_exclusions *exclusions)
15361543void clear_ref_exclusions (struct ref_exclusions * exclusions )
15371544{
15381545 string_list_clear (& exclusions -> excluded_refs , 0 );
1546+ string_list_clear (& exclusions -> hidden_refs , 0 );
1547+ exclusions -> hidden_refs_configured = 0 ;
15391548}
15401549
15411550void add_ref_exclusion (struct ref_exclusions * exclusions , const char * exclude )
15421551{
15431552 string_list_append (& exclusions -> excluded_refs , exclude );
15441553}
15451554
1555+ struct exclude_hidden_refs_cb {
1556+ struct ref_exclusions * exclusions ;
1557+ const char * section ;
1558+ };
1559+
1560+ static int hide_refs_config (const char * var , const char * value , void * cb_data )
1561+ {
1562+ struct exclude_hidden_refs_cb * cb = cb_data ;
1563+ cb -> exclusions -> hidden_refs_configured = 1 ;
1564+ return parse_hide_refs_config (var , value , cb -> section ,
1565+ & cb -> exclusions -> hidden_refs );
1566+ }
1567+
1568+ void exclude_hidden_refs (struct ref_exclusions * exclusions , const char * section )
1569+ {
1570+ struct exclude_hidden_refs_cb cb ;
1571+
1572+ if (strcmp (section , "receive" ) && strcmp (section , "uploadpack" ))
1573+ die (_ ("unsupported section for hidden refs: %s" ), section );
1574+
1575+ if (exclusions -> hidden_refs_configured )
1576+ die (_ ("--exclude-hidden= passed more than once" ));
1577+
1578+ cb .exclusions = exclusions ;
1579+ cb .section = section ;
1580+
1581+ git_config (hide_refs_config , & cb );
1582+ }
1583+
15461584struct all_refs_cb {
15471585 int all_flags ;
15481586 int warned_bad_reflog ;
@@ -2221,7 +2259,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
22212259 !strcmp (arg , "--bisect" ) || starts_with (arg , "--glob=" ) ||
22222260 !strcmp (arg , "--indexed-objects" ) ||
22232261 !strcmp (arg , "--alternate-refs" ) ||
2224- starts_with (arg , "--exclude=" ) ||
2262+ starts_with (arg , "--exclude=" ) || starts_with ( arg , "--exclude-hidden=" ) ||
22252263 starts_with (arg , "--branches=" ) || starts_with (arg , "--tags=" ) ||
22262264 starts_with (arg , "--remotes=" ) || starts_with (arg , "--no-walk=" ))
22272265 {
@@ -2687,6 +2725,8 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
26872725 }
26882726 clear_ref_exclusions (& revs -> ref_excludes );
26892727 } else if (!strcmp (arg , "--branches" )) {
2728+ if (revs -> ref_excludes .hidden_refs_configured )
2729+ return error (_ ("--exclude-hidden cannot be used together with --branches" ));
26902730 handle_refs (refs , revs , * flags , refs_for_each_branch_ref );
26912731 clear_ref_exclusions (& revs -> ref_excludes );
26922732 } else if (!strcmp (arg , "--bisect" )) {
@@ -2696,9 +2736,13 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
26962736 for_each_good_bisect_ref );
26972737 revs -> bisect = 1 ;
26982738 } else if (!strcmp (arg , "--tags" )) {
2739+ if (revs -> ref_excludes .hidden_refs_configured )
2740+ return error (_ ("--exclude-hidden cannot be used together with --tags" ));
26992741 handle_refs (refs , revs , * flags , refs_for_each_tag_ref );
27002742 clear_ref_exclusions (& revs -> ref_excludes );
27012743 } else if (!strcmp (arg , "--remotes" )) {
2744+ if (revs -> ref_excludes .hidden_refs_configured )
2745+ return error (_ ("--exclude-hidden cannot be used together with --remotes" ));
27022746 handle_refs (refs , revs , * flags , refs_for_each_remote_ref );
27032747 clear_ref_exclusions (& revs -> ref_excludes );
27042748 } else if ((argcount = parse_long_opt ("glob" , argv , & optarg ))) {
@@ -2710,18 +2754,27 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
27102754 } else if ((argcount = parse_long_opt ("exclude" , argv , & optarg ))) {
27112755 add_ref_exclusion (& revs -> ref_excludes , optarg );
27122756 return argcount ;
2757+ } else if ((argcount = parse_long_opt ("exclude-hidden" , argv , & optarg ))) {
2758+ exclude_hidden_refs (& revs -> ref_excludes , optarg );
2759+ return argcount ;
27132760 } else if (skip_prefix (arg , "--branches=" , & optarg )) {
27142761 struct all_refs_cb cb ;
2762+ if (revs -> ref_excludes .hidden_refs_configured )
2763+ return error (_ ("--exclude-hidden cannot be used together with --branches" ));
27152764 init_all_refs_cb (& cb , revs , * flags );
27162765 for_each_glob_ref_in (handle_one_ref , optarg , "refs/heads/" , & cb );
27172766 clear_ref_exclusions (& revs -> ref_excludes );
27182767 } else if (skip_prefix (arg , "--tags=" , & optarg )) {
27192768 struct all_refs_cb cb ;
2769+ if (revs -> ref_excludes .hidden_refs_configured )
2770+ return error (_ ("--exclude-hidden cannot be used together with --tags" ));
27202771 init_all_refs_cb (& cb , revs , * flags );
27212772 for_each_glob_ref_in (handle_one_ref , optarg , "refs/tags/" , & cb );
27222773 clear_ref_exclusions (& revs -> ref_excludes );
27232774 } else if (skip_prefix (arg , "--remotes=" , & optarg )) {
27242775 struct all_refs_cb cb ;
2776+ if (revs -> ref_excludes .hidden_refs_configured )
2777+ return error (_ ("--exclude-hidden cannot be used together with --remotes" ));
27252778 init_all_refs_cb (& cb , revs , * flags );
27262779 for_each_glob_ref_in (handle_one_ref , optarg , "refs/remotes/" , & cb );
27272780 clear_ref_exclusions (& revs -> ref_excludes );
0 commit comments