@@ -381,6 +381,20 @@ static struct string_list *fields_sent(void)
381
381
return & fields_list ;
382
382
}
383
383
384
+ static struct string_list * fields_checked (void )
385
+ {
386
+ static struct string_list fields_list = STRING_LIST_INIT_NODUP ;
387
+ static int initialized = 0 ;
388
+
389
+ if (!initialized ) {
390
+ fields_list .cmp = strcasecmp ;
391
+ fields_from_config (& fields_list , "promisor.checkFields" );
392
+ initialized = 1 ;
393
+ }
394
+
395
+ return & fields_list ;
396
+ }
397
+
384
398
/*
385
399
* Linked list for promisor remotes involved in the "promisor-remote"
386
400
* protocol capability.
@@ -537,6 +551,55 @@ enum accept_promisor {
537
551
ACCEPT_ALL
538
552
};
539
553
554
+ static int match_field_against_config (const char * field , const char * value ,
555
+ struct promisor_info * config_info )
556
+ {
557
+ if (config_info -> filter && !strcasecmp (field , promisor_field_filter ))
558
+ return !strcmp (config_info -> filter , value );
559
+ else if (config_info -> token && !strcasecmp (field , promisor_field_token ))
560
+ return !strcmp (config_info -> token , value );
561
+
562
+ return 0 ;
563
+ }
564
+
565
+ static int all_fields_match (struct promisor_info * advertised ,
566
+ struct promisor_info * config_info ,
567
+ int in_list )
568
+ {
569
+ struct string_list * fields = fields_checked ();
570
+ struct string_list_item * item_checked ;
571
+
572
+ for_each_string_list_item (item_checked , fields ) {
573
+ int match = 0 ;
574
+ const char * field = item_checked -> string ;
575
+ const char * value = NULL ;
576
+
577
+ if (!strcasecmp (field , promisor_field_filter ))
578
+ value = advertised -> filter ;
579
+ else if (!strcasecmp (field , promisor_field_token ))
580
+ value = advertised -> token ;
581
+
582
+ if (!value )
583
+ return 0 ;
584
+
585
+ if (in_list ) {
586
+ for (struct promisor_info * p = config_info ; p ; p = p -> next ) {
587
+ if (match_field_against_config (field , value , p )) {
588
+ match = 1 ;
589
+ break ;
590
+ }
591
+ }
592
+ } else {
593
+ match = match_field_against_config (field , value , config_info );
594
+ }
595
+
596
+ if (!match )
597
+ return 0 ;
598
+ }
599
+
600
+ return 1 ;
601
+ }
602
+
540
603
static int should_accept_remote (enum accept_promisor accept ,
541
604
struct promisor_info * advertised ,
542
605
struct promisor_info * config_info )
@@ -546,7 +609,7 @@ static int should_accept_remote(enum accept_promisor accept,
546
609
const char * remote_url = advertised -> url ;
547
610
548
611
if (accept == ACCEPT_ALL )
549
- return 1 ;
612
+ return all_fields_match ( advertised , config_info , 1 ) ;
550
613
551
614
p = remote_nick_find (config_info , remote_name );
552
615
@@ -555,7 +618,7 @@ static int should_accept_remote(enum accept_promisor accept,
555
618
return 0 ;
556
619
557
620
if (accept == ACCEPT_KNOWN_NAME )
558
- return 1 ;
621
+ return all_fields_match ( advertised , p , 0 ) ;
559
622
560
623
if (accept != ACCEPT_KNOWN_URL )
561
624
BUG ("Unhandled 'enum accept_promisor' value '%d'" , accept );
@@ -570,7 +633,7 @@ static int should_accept_remote(enum accept_promisor accept,
570
633
remote_name );
571
634
572
635
if (!strcmp (p -> url , remote_url ))
573
- return 1 ;
636
+ return all_fields_match ( advertised , p , 0 ) ;
574
637
575
638
warning (_ ("known remote named '%s' but with URL '%s' instead of '%s'" ),
576
639
remote_name , p -> url , remote_url );
@@ -602,6 +665,10 @@ static struct promisor_info *parse_one_advertised_remote(struct strbuf *remote_i
602
665
info -> name = value ;
603
666
else if (!strcmp (elem , "url" ))
604
667
info -> url = value ;
668
+ else if (!strcasecmp (elem , promisor_field_filter ))
669
+ info -> filter = value ;
670
+ else if (!strcasecmp (elem , promisor_field_token ))
671
+ info -> token = value ;
605
672
else
606
673
free (value );
607
674
}
@@ -644,9 +711,6 @@ static void filter_promisor_remote(struct repository *repo,
644
711
if (accept == ACCEPT_NONE )
645
712
return ;
646
713
647
- if (accept != ACCEPT_ALL )
648
- config_info = promisor_config_info_list (repo , NULL );
649
-
650
714
/* Parse remote info received */
651
715
652
716
remotes = strbuf_split_str (info , ';' , 0 );
@@ -661,6 +725,9 @@ static void filter_promisor_remote(struct repository *repo,
661
725
if (!advertised )
662
726
continue ;
663
727
728
+ if (!config_info )
729
+ config_info = promisor_config_info_list (repo , fields_checked ());
730
+
664
731
if (should_accept_remote (accept , advertised , config_info ))
665
732
strvec_push (accepted , advertised -> name );
666
733
0 commit comments