@@ -1096,12 +1096,36 @@ static char *guess_ref(const char *name, struct ref *peer)
10961096 return strbuf_detach (& buf , NULL );
10971097}
10981098
1099+ static int match_explicit_lhs (struct ref * src ,
1100+ struct refspec * rs ,
1101+ struct ref * * match ,
1102+ int * allocated_match )
1103+ {
1104+ switch (count_refspec_match (rs -> src , src , match )) {
1105+ case 1 :
1106+ * allocated_match = 0 ;
1107+ return 0 ;
1108+ case 0 :
1109+ /* The source could be in the get_sha1() format
1110+ * not a reference name. :refs/other is a
1111+ * way to delete 'other' ref at the remote end.
1112+ */
1113+ * match = try_explicit_object_name (rs -> src );
1114+ if (!* match )
1115+ return error ("src refspec %s does not match any." , rs -> src );
1116+ * allocated_match = 1 ;
1117+ return 0 ;
1118+ default :
1119+ return error ("src refspec %s matches more than one." , rs -> src );
1120+ }
1121+ }
1122+
10991123static int match_explicit (struct ref * src , struct ref * dst ,
11001124 struct ref * * * dst_tail ,
11011125 struct refspec * rs )
11021126{
11031127 struct ref * matched_src , * matched_dst ;
1104- int copy_src ;
1128+ int allocated_src ;
11051129
11061130 const char * dst_value = rs -> dst ;
11071131 char * dst_guess ;
@@ -1110,23 +1134,8 @@ static int match_explicit(struct ref *src, struct ref *dst,
11101134 return 0 ;
11111135
11121136 matched_src = matched_dst = NULL ;
1113- switch (count_refspec_match (rs -> src , src , & matched_src )) {
1114- case 1 :
1115- copy_src = 1 ;
1116- break ;
1117- case 0 :
1118- /* The source could be in the get_sha1() format
1119- * not a reference name. :refs/other is a
1120- * way to delete 'other' ref at the remote end.
1121- */
1122- matched_src = try_explicit_object_name (rs -> src );
1123- if (!matched_src )
1124- return error ("src refspec %s does not match any." , rs -> src );
1125- copy_src = 0 ;
1126- break ;
1127- default :
1128- return error ("src refspec %s matches more than one." , rs -> src );
1129- }
1137+ if (match_explicit_lhs (src , rs , & matched_src , & allocated_src ) < 0 )
1138+ return -1 ;
11301139
11311140 if (!dst_value ) {
11321141 unsigned char sha1 [20 ];
@@ -1171,7 +1180,9 @@ static int match_explicit(struct ref *src, struct ref *dst,
11711180 return error ("dst ref %s receives from more than one src." ,
11721181 matched_dst -> name );
11731182 else {
1174- matched_dst -> peer_ref = copy_src ? copy_ref (matched_src ) : matched_src ;
1183+ matched_dst -> peer_ref = allocated_src ?
1184+ matched_src :
1185+ copy_ref (matched_src );
11751186 matched_dst -> force = rs -> force ;
11761187 }
11771188 return 0 ;
0 commit comments