@@ -40,7 +40,8 @@ static int tags = TAGS_DEFAULT, unshallow;
40
40
static const char * depth ;
41
41
static const char * upload_pack ;
42
42
static struct strbuf default_rla = STRBUF_INIT ;
43
- static struct transport * transport ;
43
+ static struct transport * gtransport ;
44
+ static struct transport * gsecondary ;
44
45
static const char * submodule_prefix = "" ;
45
46
static const char * recurse_submodules_default ;
46
47
@@ -108,8 +109,10 @@ static struct option builtin_fetch_options[] = {
108
109
109
110
static void unlock_pack (void )
110
111
{
111
- if (transport )
112
- transport_unlock_pack (transport );
112
+ if (gtransport )
113
+ transport_unlock_pack (gtransport );
114
+ if (gsecondary )
115
+ transport_unlock_pack (gsecondary );
113
116
}
114
117
115
118
static void unlock_pack_on_signal (int signo )
@@ -733,6 +736,48 @@ static int truncate_fetch_head(void)
733
736
return 0 ;
734
737
}
735
738
739
+ static void set_option (struct transport * transport , const char * name , const char * value )
740
+ {
741
+ int r = transport_set_option (transport , name , value );
742
+ if (r < 0 )
743
+ die (_ ("Option \"%s\" value \"%s\" is not valid for %s" ),
744
+ name , value , transport -> url );
745
+ if (r > 0 )
746
+ warning (_ ("Option \"%s\" is ignored for %s\n" ),
747
+ name , transport -> url );
748
+ }
749
+
750
+ static struct transport * prepare_transport (struct remote * remote )
751
+ {
752
+ struct transport * transport ;
753
+ transport = transport_get (remote , NULL );
754
+ transport_set_verbosity (transport , verbosity , progress );
755
+ if (upload_pack )
756
+ set_option (transport , TRANS_OPT_UPLOADPACK , upload_pack );
757
+ if (keep )
758
+ set_option (transport , TRANS_OPT_KEEP , "yes" );
759
+ if (depth )
760
+ set_option (transport , TRANS_OPT_DEPTH , depth );
761
+ return transport ;
762
+ }
763
+
764
+ static void backfill_tags (struct transport * transport , struct ref * ref_map )
765
+ {
766
+ if (transport -> cannot_reuse ) {
767
+ gsecondary = prepare_transport (transport -> remote );
768
+ transport = gsecondary ;
769
+ }
770
+
771
+ transport_set_option (transport , TRANS_OPT_FOLLOWTAGS , NULL );
772
+ transport_set_option (transport , TRANS_OPT_DEPTH , "0" );
773
+ fetch_refs (transport , ref_map );
774
+
775
+ if (gsecondary ) {
776
+ transport_disconnect (gsecondary );
777
+ gsecondary = NULL ;
778
+ }
779
+ }
780
+
736
781
static int do_fetch (struct transport * transport ,
737
782
struct refspec * refs , int ref_count )
738
783
{
@@ -819,11 +864,8 @@ static int do_fetch(struct transport *transport,
819
864
struct ref * * tail = & ref_map ;
820
865
ref_map = NULL ;
821
866
find_non_local_tags (transport , & ref_map , & tail );
822
- if (ref_map ) {
823
- transport_set_option (transport , TRANS_OPT_FOLLOWTAGS , NULL );
824
- transport_set_option (transport , TRANS_OPT_DEPTH , "0" );
825
- fetch_refs (transport , ref_map );
826
- }
867
+ if (ref_map )
868
+ backfill_tags (transport , ref_map );
827
869
free_refs (ref_map );
828
870
}
829
871
@@ -832,17 +874,6 @@ static int do_fetch(struct transport *transport,
832
874
return retcode ;
833
875
}
834
876
835
- static void set_option (const char * name , const char * value )
836
- {
837
- int r = transport_set_option (transport , name , value );
838
- if (r < 0 )
839
- die (_ ("Option \"%s\" value \"%s\" is not valid for %s" ),
840
- name , value , transport -> url );
841
- if (r > 0 )
842
- warning (_ ("Option \"%s\" is ignored for %s\n" ),
843
- name , transport -> url );
844
- }
845
-
846
877
static int get_one_remote_for_fetch (struct remote * remote , void * priv )
847
878
{
848
879
struct string_list * list = priv ;
@@ -965,26 +996,18 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
965
996
die (_ ("No remote repository specified. Please, specify either a URL or a\n"
966
997
"remote name from which new revisions should be fetched." ));
967
998
968
- transport = transport_get (remote , NULL );
999
+ gtransport = prepare_transport (remote );
969
1000
970
1001
if (prune < 0 ) {
971
1002
/* no command line request */
972
- if (0 <= transport -> remote -> prune )
973
- prune = transport -> remote -> prune ;
1003
+ if (0 <= gtransport -> remote -> prune )
1004
+ prune = gtransport -> remote -> prune ;
974
1005
else if (0 <= fetch_prune_config )
975
1006
prune = fetch_prune_config ;
976
1007
else
977
1008
prune = PRUNE_BY_DEFAULT ;
978
1009
}
979
1010
980
- transport_set_verbosity (transport , verbosity , progress );
981
- if (upload_pack )
982
- set_option (TRANS_OPT_UPLOADPACK , upload_pack );
983
- if (keep )
984
- set_option (TRANS_OPT_KEEP , "yes" );
985
- if (depth )
986
- set_option (TRANS_OPT_DEPTH , depth );
987
-
988
1011
if (argc > 0 ) {
989
1012
int j = 0 ;
990
1013
refs = xcalloc (argc + 1 , sizeof (const char * ));
@@ -1010,10 +1033,10 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
1010
1033
sigchain_push_common (unlock_pack_on_signal );
1011
1034
atexit (unlock_pack );
1012
1035
refspec = parse_fetch_refspec (ref_nr , refs );
1013
- exit_code = do_fetch (transport , refspec , ref_nr );
1036
+ exit_code = do_fetch (gtransport , refspec , ref_nr );
1014
1037
free_refspec (ref_nr , refspec );
1015
- transport_disconnect (transport );
1016
- transport = NULL ;
1038
+ transport_disconnect (gtransport );
1039
+ gtransport = NULL ;
1017
1040
return exit_code ;
1018
1041
}
1019
1042
0 commit comments