@@ -925,128 +925,6 @@ struct ref *apply_negative_refspecs(struct ref *ref_map, struct refspec *rs)
925925 return ref_map ;
926926}
927927
928- static int refspec_find_negative_match (struct refspec * rs , struct refspec_item * query )
929- {
930- int i , matched_negative = 0 ;
931- int find_src = !query -> src ;
932- struct string_list reversed = STRING_LIST_INIT_DUP ;
933- const char * needle = find_src ? query -> dst : query -> src ;
934-
935- /*
936- * Check whether the queried ref matches any negative refpsec. If so,
937- * then we should ultimately treat this as not matching the query at
938- * all.
939- *
940- * Note that negative refspecs always match the source, but the query
941- * item uses the destination. To handle this, we apply pattern
942- * refspecs in reverse to figure out if the query source matches any
943- * of the negative refspecs.
944- *
945- * The first loop finds and expands all positive refspecs
946- * matched by the queried ref.
947- *
948- * The second loop checks if any of the results of the first loop
949- * match any negative refspec.
950- */
951- for (i = 0 ; i < rs -> nr ; i ++ ) {
952- struct refspec_item * refspec = & rs -> items [i ];
953- char * expn_name ;
954-
955- if (refspec -> negative )
956- continue ;
957-
958- /* Note the reversal of src and dst */
959- if (refspec -> pattern ) {
960- const char * key = refspec -> dst ? refspec -> dst : refspec -> src ;
961- const char * value = refspec -> src ;
962-
963- if (match_name_with_pattern (key , needle , value , & expn_name ))
964- string_list_append_nodup (& reversed , expn_name );
965- } else if (refspec -> matching ) {
966- /* For the special matching refspec, any query should match */
967- string_list_append (& reversed , needle );
968- } else if (!refspec -> src ) {
969- BUG ("refspec->src should not be null here" );
970- } else if (!strcmp (needle , refspec -> src )) {
971- string_list_append (& reversed , refspec -> src );
972- }
973- }
974-
975- for (i = 0 ; !matched_negative && i < reversed .nr ; i ++ ) {
976- if (refname_matches_negative_refspec_item (reversed .items [i ].string , rs ))
977- matched_negative = 1 ;
978- }
979-
980- string_list_clear (& reversed , 0 );
981-
982- return matched_negative ;
983- }
984-
985- static void refspec_find_all_matches (struct refspec * rs ,
986- struct refspec_item * query ,
987- struct string_list * results )
988- {
989- int i ;
990- int find_src = !query -> src ;
991-
992- if (find_src && !query -> dst )
993- BUG ("refspec_find_all_matches: need either src or dst" );
994-
995- if (refspec_find_negative_match (rs , query ))
996- return ;
997-
998- for (i = 0 ; i < rs -> nr ; i ++ ) {
999- struct refspec_item * refspec = & rs -> items [i ];
1000- const char * key = find_src ? refspec -> dst : refspec -> src ;
1001- const char * value = find_src ? refspec -> src : refspec -> dst ;
1002- const char * needle = find_src ? query -> dst : query -> src ;
1003- char * * result = find_src ? & query -> src : & query -> dst ;
1004-
1005- if (!refspec -> dst || refspec -> negative )
1006- continue ;
1007- if (refspec -> pattern ) {
1008- if (match_name_with_pattern (key , needle , value , result ))
1009- string_list_append_nodup (results , * result );
1010- } else if (!strcmp (needle , key )) {
1011- string_list_append (results , value );
1012- }
1013- }
1014- }
1015-
1016- int refspec_find_match (struct refspec * rs , struct refspec_item * query )
1017- {
1018- int i ;
1019- int find_src = !query -> src ;
1020- const char * needle = find_src ? query -> dst : query -> src ;
1021- char * * result = find_src ? & query -> src : & query -> dst ;
1022-
1023- if (find_src && !query -> dst )
1024- BUG ("refspec_find_match: need either src or dst" );
1025-
1026- if (refspec_find_negative_match (rs , query ))
1027- return -1 ;
1028-
1029- for (i = 0 ; i < rs -> nr ; i ++ ) {
1030- struct refspec_item * refspec = & rs -> items [i ];
1031- const char * key = find_src ? refspec -> dst : refspec -> src ;
1032- const char * value = find_src ? refspec -> src : refspec -> dst ;
1033-
1034- if (!refspec -> dst || refspec -> negative )
1035- continue ;
1036- if (refspec -> pattern ) {
1037- if (match_name_with_pattern (key , needle , value , result )) {
1038- query -> force = refspec -> force ;
1039- return 0 ;
1040- }
1041- } else if (!strcmp (needle , key )) {
1042- * result = xstrdup (value );
1043- query -> force = refspec -> force ;
1044- return 0 ;
1045- }
1046- }
1047- return -1 ;
1048- }
1049-
1050928char * apply_refspecs (struct refspec * rs , const char * name )
1051929{
1052930 struct refspec_item query ;
0 commit comments