55#include "transport.h"
66#include "strvec.h"
77
8+ struct promisor_remote_config {
9+ struct promisor_remote * promisors ;
10+ struct promisor_remote * * promisors_tail ;
11+ };
12+
813static int fetch_objects (const char * remote_name ,
914 const struct object_id * oids ,
1015 int oid_nr )
@@ -35,10 +40,8 @@ static int fetch_objects(const char *remote_name,
3540 return finish_command (& child ) ? -1 : 0 ;
3641}
3742
38- static struct promisor_remote * promisors ;
39- static struct promisor_remote * * promisors_tail = & promisors ;
40-
41- static struct promisor_remote * promisor_remote_new (const char * remote_name )
43+ static struct promisor_remote * promisor_remote_new (struct promisor_remote_config * config ,
44+ const char * remote_name )
4245{
4346 struct promisor_remote * r ;
4447
@@ -50,18 +53,19 @@ static struct promisor_remote *promisor_remote_new(const char *remote_name)
5053
5154 FLEX_ALLOC_STR (r , name , remote_name );
5255
53- * promisors_tail = r ;
54- promisors_tail = & r -> next ;
56+ * config -> promisors_tail = r ;
57+ config -> promisors_tail = & r -> next ;
5558
5659 return r ;
5760}
5861
59- static struct promisor_remote * promisor_remote_lookup (const char * remote_name ,
62+ static struct promisor_remote * promisor_remote_lookup (struct promisor_remote_config * config ,
63+ const char * remote_name ,
6064 struct promisor_remote * * previous )
6165{
6266 struct promisor_remote * r , * p ;
6367
64- for (p = NULL , r = promisors ; r ; p = r , r = r -> next )
68+ for (p = NULL , r = config -> promisors ; r ; p = r , r = r -> next )
6569 if (!strcmp (r -> name , remote_name )) {
6670 if (previous )
6771 * previous = p ;
@@ -71,7 +75,8 @@ static struct promisor_remote *promisor_remote_lookup(const char *remote_name,
7175 return NULL ;
7276}
7377
74- static void promisor_remote_move_to_tail (struct promisor_remote * r ,
78+ static void promisor_remote_move_to_tail (struct promisor_remote_config * config ,
79+ struct promisor_remote * r ,
7580 struct promisor_remote * previous )
7681{
7782 if (r -> next == NULL )
@@ -80,14 +85,15 @@ static void promisor_remote_move_to_tail(struct promisor_remote *r,
8085 if (previous )
8186 previous -> next = r -> next ;
8287 else
83- promisors = r -> next ? r -> next : r ;
88+ config -> promisors = r -> next ? r -> next : r ;
8489 r -> next = NULL ;
85- * promisors_tail = r ;
86- promisors_tail = & r -> next ;
90+ * config -> promisors_tail = r ;
91+ config -> promisors_tail = & r -> next ;
8792}
8893
8994static int promisor_remote_config (const char * var , const char * value , void * data )
9095{
96+ struct promisor_remote_config * config = data ;
9197 const char * name ;
9298 size_t namelen ;
9399 const char * subkey ;
@@ -103,8 +109,8 @@ static int promisor_remote_config(const char *var, const char *value, void *data
103109
104110 remote_name = xmemdupz (name , namelen );
105111
106- if (!promisor_remote_lookup (remote_name , NULL ))
107- promisor_remote_new (remote_name );
112+ if (!promisor_remote_lookup (config , remote_name , NULL ))
113+ promisor_remote_new (config , remote_name );
108114
109115 free (remote_name );
110116 return 0 ;
@@ -113,9 +119,9 @@ static int promisor_remote_config(const char *var, const char *value, void *data
113119 struct promisor_remote * r ;
114120 char * remote_name = xmemdupz (name , namelen );
115121
116- r = promisor_remote_lookup (remote_name , NULL );
122+ r = promisor_remote_lookup (config , remote_name , NULL );
117123 if (!r )
118- r = promisor_remote_new (remote_name );
124+ r = promisor_remote_new (config , remote_name );
119125
120126 free (remote_name );
121127
@@ -128,59 +134,63 @@ static int promisor_remote_config(const char *var, const char *value, void *data
128134 return 0 ;
129135}
130136
131- static int initialized ;
132-
133- static void promisor_remote_init (void )
137+ static void promisor_remote_init (struct repository * r )
134138{
135- if (initialized )
139+ struct promisor_remote_config * config ;
140+
141+ if (r -> promisor_remote_config )
136142 return ;
137- initialized = 1 ;
143+ config = r -> promisor_remote_config =
144+ xcalloc (sizeof (* r -> promisor_remote_config ), 1 );
145+ config -> promisors_tail = & config -> promisors ;
138146
139- git_config ( promisor_remote_config , NULL );
147+ repo_config ( r , promisor_remote_config , config );
140148
141- if (the_repository -> repository_format_partial_clone ) {
149+ if (r -> repository_format_partial_clone ) {
142150 struct promisor_remote * o , * previous ;
143151
144- o = promisor_remote_lookup (the_repository -> repository_format_partial_clone ,
152+ o = promisor_remote_lookup (config ,
153+ r -> repository_format_partial_clone ,
145154 & previous );
146155 if (o )
147- promisor_remote_move_to_tail (o , previous );
156+ promisor_remote_move_to_tail (config , o , previous );
148157 else
149- promisor_remote_new (the_repository -> repository_format_partial_clone );
158+ promisor_remote_new (config , r -> repository_format_partial_clone );
150159 }
151160}
152161
153- static void promisor_remote_clear (void )
162+ void promisor_remote_clear (struct promisor_remote_config * config )
154163{
155- while (promisors ) {
156- struct promisor_remote * r = promisors ;
157- promisors = promisors -> next ;
164+ while (config -> promisors ) {
165+ struct promisor_remote * r = config -> promisors ;
166+ config -> promisors = config -> promisors -> next ;
158167 free (r );
159168 }
160169
161- promisors_tail = & promisors ;
170+ config -> promisors_tail = & config -> promisors ;
162171}
163172
164- void promisor_remote_reinit ( void )
173+ void repo_promisor_remote_reinit ( struct repository * r )
165174{
166- initialized = 0 ;
167- promisor_remote_clear ( );
168- promisor_remote_init ();
175+ promisor_remote_clear ( r -> promisor_remote_config ) ;
176+ FREE_AND_NULL ( r -> promisor_remote_config );
177+ promisor_remote_init (r );
169178}
170179
171- struct promisor_remote * promisor_remote_find (const char * remote_name )
180+ struct promisor_remote * repo_promisor_remote_find (struct repository * r ,
181+ const char * remote_name )
172182{
173- promisor_remote_init ();
183+ promisor_remote_init (r );
174184
175185 if (!remote_name )
176- return promisors ;
186+ return r -> promisor_remote_config -> promisors ;
177187
178- return promisor_remote_lookup (remote_name , NULL );
188+ return promisor_remote_lookup (r -> promisor_remote_config , remote_name , NULL );
179189}
180190
181- int has_promisor_remote ( void )
191+ int repo_has_promisor_remote ( struct repository * r )
182192{
183- return !!promisor_remote_find ( NULL );
193+ return !!repo_promisor_remote_find ( r , NULL );
184194}
185195
186196static int remove_fetched_oids (struct repository * repo ,
@@ -228,9 +238,11 @@ int promisor_remote_get_direct(struct repository *repo,
228238 if (oid_nr == 0 )
229239 return 0 ;
230240
231- promisor_remote_init ();
241+ promisor_remote_init (repo );
232242
233- for (r = promisors ; r ; r = r -> next ) {
243+ if (repo != the_repository )
244+ BUG ("only the_repository is supported for now" );
245+ for (r = repo -> promisor_remote_config -> promisors ; r ; r = r -> next ) {
234246 if (fetch_objects (r -> name , remaining_oids , remaining_nr ) < 0 ) {
235247 if (remaining_nr == 1 )
236248 continue ;
0 commit comments