55#include "transport.h"
66#include "strvec.h"
77
8- static char * repository_format_partial_clone ;
9-
10- void set_repository_format_partial_clone (char * partial_clone )
11- {
12- repository_format_partial_clone = xstrdup_or_null (partial_clone );
13- }
8+ struct promisor_remote_config {
9+ struct promisor_remote * promisors ;
10+ struct promisor_remote * * promisors_tail ;
11+ };
1412
1513static int fetch_objects (struct repository * repo ,
1614 const char * remote_name ,
@@ -23,6 +21,8 @@ static int fetch_objects(struct repository *repo,
2321
2422 child .git_cmd = 1 ;
2523 child .in = -1 ;
24+ if (repo != the_repository )
25+ prepare_other_repo_env (& child .env_array , repo -> gitdir );
2626 strvec_pushl (& child .args , "-c" , "fetch.negotiationAlgorithm=noop" ,
2727 "fetch" , remote_name , "--no-tags" ,
2828 "--no-write-fetch-head" , "--recurse-submodules=no" ,
@@ -45,10 +45,8 @@ static int fetch_objects(struct repository *repo,
4545 return finish_command (& child ) ? -1 : 0 ;
4646}
4747
48- static struct promisor_remote * promisors ;
49- static struct promisor_remote * * promisors_tail = & promisors ;
50-
51- static struct promisor_remote * promisor_remote_new (const char * remote_name )
48+ static struct promisor_remote * promisor_remote_new (struct promisor_remote_config * config ,
49+ const char * remote_name )
5250{
5351 struct promisor_remote * r ;
5452
@@ -60,18 +58,19 @@ static struct promisor_remote *promisor_remote_new(const char *remote_name)
6058
6159 FLEX_ALLOC_STR (r , name , remote_name );
6260
63- * promisors_tail = r ;
64- promisors_tail = & r -> next ;
61+ * config -> promisors_tail = r ;
62+ config -> promisors_tail = & r -> next ;
6563
6664 return r ;
6765}
6866
69- static struct promisor_remote * promisor_remote_lookup (const char * remote_name ,
67+ static struct promisor_remote * promisor_remote_lookup (struct promisor_remote_config * config ,
68+ const char * remote_name ,
7069 struct promisor_remote * * previous )
7170{
7271 struct promisor_remote * r , * p ;
7372
74- for (p = NULL , r = promisors ; r ; p = r , r = r -> next )
73+ for (p = NULL , r = config -> promisors ; r ; p = r , r = r -> next )
7574 if (!strcmp (r -> name , remote_name )) {
7675 if (previous )
7776 * previous = p ;
@@ -81,7 +80,8 @@ static struct promisor_remote *promisor_remote_lookup(const char *remote_name,
8180 return NULL ;
8281}
8382
84- static void promisor_remote_move_to_tail (struct promisor_remote * r ,
83+ static void promisor_remote_move_to_tail (struct promisor_remote_config * config ,
84+ struct promisor_remote * r ,
8585 struct promisor_remote * previous )
8686{
8787 if (r -> next == NULL )
@@ -90,14 +90,15 @@ static void promisor_remote_move_to_tail(struct promisor_remote *r,
9090 if (previous )
9191 previous -> next = r -> next ;
9292 else
93- promisors = r -> next ? r -> next : r ;
93+ config -> promisors = r -> next ? r -> next : r ;
9494 r -> next = NULL ;
95- * promisors_tail = r ;
96- promisors_tail = & r -> next ;
95+ * config -> promisors_tail = r ;
96+ config -> promisors_tail = & r -> next ;
9797}
9898
9999static int promisor_remote_config (const char * var , const char * value , void * data )
100100{
101+ struct promisor_remote_config * config = data ;
101102 const char * name ;
102103 size_t namelen ;
103104 const char * subkey ;
@@ -113,8 +114,8 @@ static int promisor_remote_config(const char *var, const char *value, void *data
113114
114115 remote_name = xmemdupz (name , namelen );
115116
116- if (!promisor_remote_lookup (remote_name , NULL ))
117- promisor_remote_new (remote_name );
117+ if (!promisor_remote_lookup (config , remote_name , NULL ))
118+ promisor_remote_new (config , remote_name );
118119
119120 free (remote_name );
120121 return 0 ;
@@ -123,9 +124,9 @@ static int promisor_remote_config(const char *var, const char *value, void *data
123124 struct promisor_remote * r ;
124125 char * remote_name = xmemdupz (name , namelen );
125126
126- r = promisor_remote_lookup (remote_name , NULL );
127+ r = promisor_remote_lookup (config , remote_name , NULL );
127128 if (!r )
128- r = promisor_remote_new (remote_name );
129+ r = promisor_remote_new (config , remote_name );
129130
130131 free (remote_name );
131132
@@ -138,59 +139,63 @@ static int promisor_remote_config(const char *var, const char *value, void *data
138139 return 0 ;
139140}
140141
141- static int initialized ;
142-
143- static void promisor_remote_init (void )
142+ static void promisor_remote_init (struct repository * r )
144143{
145- if (initialized )
144+ struct promisor_remote_config * config ;
145+
146+ if (r -> promisor_remote_config )
146147 return ;
147- initialized = 1 ;
148+ config = r -> promisor_remote_config =
149+ xcalloc (sizeof (* r -> promisor_remote_config ), 1 );
150+ config -> promisors_tail = & config -> promisors ;
148151
149- git_config ( promisor_remote_config , NULL );
152+ repo_config ( r , promisor_remote_config , config );
150153
151- if (repository_format_partial_clone ) {
154+ if (r -> repository_format_partial_clone ) {
152155 struct promisor_remote * o , * previous ;
153156
154- o = promisor_remote_lookup (repository_format_partial_clone ,
157+ o = promisor_remote_lookup (config ,
158+ r -> repository_format_partial_clone ,
155159 & previous );
156160 if (o )
157- promisor_remote_move_to_tail (o , previous );
161+ promisor_remote_move_to_tail (config , o , previous );
158162 else
159- promisor_remote_new (repository_format_partial_clone );
163+ promisor_remote_new (config , r -> repository_format_partial_clone );
160164 }
161165}
162166
163- static void promisor_remote_clear (void )
167+ void promisor_remote_clear (struct promisor_remote_config * config )
164168{
165- while (promisors ) {
166- struct promisor_remote * r = promisors ;
167- promisors = promisors -> next ;
169+ while (config -> promisors ) {
170+ struct promisor_remote * r = config -> promisors ;
171+ config -> promisors = config -> promisors -> next ;
168172 free (r );
169173 }
170174
171- promisors_tail = & promisors ;
175+ config -> promisors_tail = & config -> promisors ;
172176}
173177
174- void promisor_remote_reinit ( void )
178+ void repo_promisor_remote_reinit ( struct repository * r )
175179{
176- initialized = 0 ;
177- promisor_remote_clear ( );
178- promisor_remote_init ();
180+ promisor_remote_clear ( r -> promisor_remote_config ) ;
181+ FREE_AND_NULL ( r -> promisor_remote_config );
182+ promisor_remote_init (r );
179183}
180184
181- struct promisor_remote * promisor_remote_find (const char * remote_name )
185+ struct promisor_remote * repo_promisor_remote_find (struct repository * r ,
186+ const char * remote_name )
182187{
183- promisor_remote_init ();
188+ promisor_remote_init (r );
184189
185190 if (!remote_name )
186- return promisors ;
191+ return r -> promisor_remote_config -> promisors ;
187192
188- return promisor_remote_lookup (remote_name , NULL );
193+ return promisor_remote_lookup (r -> promisor_remote_config , remote_name , NULL );
189194}
190195
191- int has_promisor_remote ( void )
196+ int repo_has_promisor_remote ( struct repository * r )
192197{
193- return !!promisor_remote_find ( NULL );
198+ return !!repo_promisor_remote_find ( r , NULL );
194199}
195200
196201static int remove_fetched_oids (struct repository * repo ,
@@ -238,9 +243,9 @@ int promisor_remote_get_direct(struct repository *repo,
238243 if (oid_nr == 0 )
239244 return 0 ;
240245
241- promisor_remote_init ();
246+ promisor_remote_init (repo );
242247
243- for (r = promisors ; r ; r = r -> next ) {
248+ for (r = repo -> promisor_remote_config -> promisors ; r ; r = r -> next ) {
244249 if (fetch_objects (repo , r -> name , remaining_oids , remaining_nr ) < 0 ) {
245250 if (remaining_nr == 1 )
246251 continue ;
0 commit comments