@@ -36,7 +36,8 @@ static int tags = TAGS_DEFAULT, unshallow;
36
36
static const char * depth ;
37
37
static const char * upload_pack ;
38
38
static struct strbuf default_rla = STRBUF_INIT ;
39
- static struct transport * transport ;
39
+ static struct transport * gtransport ;
40
+ static struct transport * gsecondary ;
40
41
static const char * submodule_prefix = "" ;
41
42
static const char * recurse_submodules_default ;
42
43
@@ -95,8 +96,10 @@ static struct option builtin_fetch_options[] = {
95
96
96
97
static void unlock_pack (void )
97
98
{
98
- if (transport )
99
- transport_unlock_pack (transport );
99
+ if (gtransport )
100
+ transport_unlock_pack (gtransport );
101
+ if (gsecondary )
102
+ transport_unlock_pack (gsecondary );
100
103
}
101
104
102
105
static void unlock_pack_on_signal (int signo )
@@ -720,6 +723,48 @@ static int truncate_fetch_head(void)
720
723
return 0 ;
721
724
}
722
725
726
+ static void set_option (struct transport * transport , const char * name , const char * value )
727
+ {
728
+ int r = transport_set_option (transport , name , value );
729
+ if (r < 0 )
730
+ die (_ ("Option \"%s\" value \"%s\" is not valid for %s" ),
731
+ name , value , transport -> url );
732
+ if (r > 0 )
733
+ warning (_ ("Option \"%s\" is ignored for %s\n" ),
734
+ name , transport -> url );
735
+ }
736
+
737
+ static struct transport * prepare_transport (struct remote * remote )
738
+ {
739
+ struct transport * transport ;
740
+ transport = transport_get (remote , NULL );
741
+ transport_set_verbosity (transport , verbosity , progress );
742
+ if (upload_pack )
743
+ set_option (transport , TRANS_OPT_UPLOADPACK , upload_pack );
744
+ if (keep )
745
+ set_option (transport , TRANS_OPT_KEEP , "yes" );
746
+ if (depth )
747
+ set_option (transport , TRANS_OPT_DEPTH , depth );
748
+ return transport ;
749
+ }
750
+
751
+ static void backfill_tags (struct transport * transport , struct ref * ref_map )
752
+ {
753
+ if (transport -> cannot_reuse ) {
754
+ gsecondary = prepare_transport (transport -> remote );
755
+ transport = gsecondary ;
756
+ }
757
+
758
+ transport_set_option (transport , TRANS_OPT_FOLLOWTAGS , NULL );
759
+ transport_set_option (transport , TRANS_OPT_DEPTH , "0" );
760
+ fetch_refs (transport , ref_map );
761
+
762
+ if (gsecondary ) {
763
+ transport_disconnect (gsecondary );
764
+ gsecondary = NULL ;
765
+ }
766
+ }
767
+
723
768
static int do_fetch (struct transport * transport ,
724
769
struct refspec * refs , int ref_count )
725
770
{
@@ -803,11 +848,8 @@ static int do_fetch(struct transport *transport,
803
848
struct ref * * tail = & ref_map ;
804
849
ref_map = NULL ;
805
850
find_non_local_tags (transport , & ref_map , & tail );
806
- if (ref_map ) {
807
- transport_set_option (transport , TRANS_OPT_FOLLOWTAGS , NULL );
808
- transport_set_option (transport , TRANS_OPT_DEPTH , "0" );
809
- fetch_refs (transport , ref_map );
810
- }
851
+ if (ref_map )
852
+ backfill_tags (transport , ref_map );
811
853
free_refs (ref_map );
812
854
}
813
855
@@ -816,17 +858,6 @@ static int do_fetch(struct transport *transport,
816
858
return retcode ;
817
859
}
818
860
819
- static void set_option (const char * name , const char * value )
820
- {
821
- int r = transport_set_option (transport , name , value );
822
- if (r < 0 )
823
- die (_ ("Option \"%s\" value \"%s\" is not valid for %s" ),
824
- name , value , transport -> url );
825
- if (r > 0 )
826
- warning (_ ("Option \"%s\" is ignored for %s\n" ),
827
- name , transport -> url );
828
- }
829
-
830
861
static int get_one_remote_for_fetch (struct remote * remote , void * priv )
831
862
{
832
863
struct string_list * list = priv ;
@@ -949,15 +980,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
949
980
die (_ ("No remote repository specified. Please, specify either a URL or a\n"
950
981
"remote name from which new revisions should be fetched." ));
951
982
952
- transport = transport_get (remote , NULL );
953
- transport_set_verbosity (transport , verbosity , progress );
954
- if (upload_pack )
955
- set_option (TRANS_OPT_UPLOADPACK , upload_pack );
956
- if (keep )
957
- set_option (TRANS_OPT_KEEP , "yes" );
958
- if (depth )
959
- set_option (TRANS_OPT_DEPTH , depth );
960
-
983
+ gtransport = prepare_transport (remote );
961
984
if (argc > 0 ) {
962
985
int j = 0 ;
963
986
refs = xcalloc (argc + 1 , sizeof (const char * ));
@@ -983,10 +1006,10 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
983
1006
sigchain_push_common (unlock_pack_on_signal );
984
1007
atexit (unlock_pack );
985
1008
refspec = parse_fetch_refspec (ref_nr , refs );
986
- exit_code = do_fetch (transport , refspec , ref_nr );
1009
+ exit_code = do_fetch (gtransport , refspec , ref_nr );
987
1010
free_refspec (ref_nr , refspec );
988
- transport_disconnect (transport );
989
- transport = NULL ;
1011
+ transport_disconnect (gtransport );
1012
+ gtransport = NULL ;
990
1013
return exit_code ;
991
1014
}
992
1015
0 commit comments