@@ -548,7 +548,7 @@ static struct ref *find_remote_branch(const struct ref *refs, const char *branch
548548}
549549
550550static struct ref * wanted_peer_refs (const struct ref * refs ,
551- struct refspec_item * refspec )
551+ struct refspec * refspec )
552552{
553553 struct ref * head = copy_ref (find_ref_by_name (refs , "HEAD" ));
554554 struct ref * local_refs = head ;
@@ -569,13 +569,19 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
569569 warning (_ ("Could not find remote branch %s to clone." ),
570570 option_branch );
571571 else {
572- get_fetch_map (remote_head , refspec , & tail , 0 );
572+ int i ;
573+ for (i = 0 ; i < refspec -> nr ; i ++ )
574+ get_fetch_map (remote_head , & refspec -> items [i ],
575+ & tail , 0 );
573576
574577 /* if --branch=tag, pull the requested tag explicitly */
575578 get_fetch_map (remote_head , tag_refspec , & tail , 0 );
576579 }
577- } else
578- get_fetch_map (refs , refspec , & tail , 0 );
580+ } else {
581+ int i ;
582+ for (i = 0 ; i < refspec -> nr ; i ++ )
583+ get_fetch_map (refs , & refspec -> items [i ], & tail , 0 );
584+ }
579585
580586 if (!option_mirror && !option_single_branch && !option_no_tags )
581587 get_fetch_map (refs , tag_refspec , & tail , 0 );
@@ -890,15 +896,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
890896 const struct ref * our_head_points_at ;
891897 struct ref * mapped_refs ;
892898 const struct ref * ref ;
893- struct strbuf key = STRBUF_INIT , value = STRBUF_INIT ;
899+ struct strbuf key = STRBUF_INIT ;
900+ struct strbuf default_refspec = STRBUF_INIT ;
894901 struct strbuf branch_top = STRBUF_INIT , reflog_msg = STRBUF_INIT ;
895902 struct transport * transport = NULL ;
896903 const char * src_ref_prefix = "refs/heads/" ;
897904 struct remote * remote ;
898905 int err = 0 , complete_refs_before_fetch = 1 ;
899906 int submodule_progress ;
900907
901- struct refspec rs = REFSPEC_INIT_FETCH ;
902908 struct argv_array ref_prefixes = ARGV_ARRAY_INIT ;
903909
904910 fetch_if_missing = 0 ;
@@ -1067,7 +1073,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10671073 strbuf_addf (& branch_top , "refs/remotes/%s/" , option_origin );
10681074 }
10691075
1070- strbuf_addf (& value , "+%s*:%s*" , src_ref_prefix , branch_top .buf );
10711076 strbuf_addf (& key , "remote.%s.url" , option_origin );
10721077 git_config_set (key .buf , repo );
10731078 strbuf_reset (& key );
@@ -1081,11 +1086,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10811086 if (option_required_reference .nr || option_optional_reference .nr )
10821087 setup_reference ();
10831088
1084- refspec_append ( & rs , value . buf );
1089+ remote = remote_get ( option_origin );
10851090
1086- strbuf_reset (& value );
1091+ strbuf_addf (& default_refspec , "+%s*:%s*" , src_ref_prefix ,
1092+ branch_top .buf );
1093+ refspec_append (& remote -> fetch , default_refspec .buf );
10871094
1088- remote = remote_get (option_origin );
10891095 transport = transport_get (remote , remote -> url [0 ]);
10901096 transport_set_verbosity (transport , option_verbosity , option_progress );
10911097 transport -> family = family ;
@@ -1140,7 +1146,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11401146
11411147
11421148 argv_array_push (& ref_prefixes , "HEAD" );
1143- refspec_ref_prefixes (& rs , & ref_prefixes );
1149+ refspec_ref_prefixes (& remote -> fetch , & ref_prefixes );
11441150 if (option_branch )
11451151 expand_ref_prefix (& ref_prefixes , option_branch );
11461152 if (!option_no_tags )
@@ -1149,7 +1155,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11491155 refs = transport_get_remote_refs (transport , & ref_prefixes );
11501156
11511157 if (refs ) {
1152- mapped_refs = wanted_peer_refs (refs , & rs . items [ 0 ] );
1158+ mapped_refs = wanted_peer_refs (refs , & remote -> fetch );
11531159 /*
11541160 * transport_get_remote_refs() may return refs with null sha-1
11551161 * in mapped_refs (see struct transport->get_refs_list
@@ -1240,10 +1246,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12401246 strbuf_release (& reflog_msg );
12411247 strbuf_release (& branch_top );
12421248 strbuf_release (& key );
1243- strbuf_release (& value );
1249+ strbuf_release (& default_refspec );
12441250 junk_mode = JUNK_LEAVE_ALL ;
12451251
1246- refspec_clear (& rs );
12471252 argv_array_clear (& ref_prefixes );
12481253 return err ;
12491254}
0 commit comments