5
5
#include "transport.h"
6
6
#include "strvec.h"
7
7
8
+ struct promisor_remote_config {
9
+ struct promisor_remote * promisors ;
10
+ struct promisor_remote * * promisors_tail ;
11
+ };
12
+
8
13
static int fetch_objects (const char * remote_name ,
9
14
const struct object_id * oids ,
10
15
int oid_nr )
@@ -35,10 +40,8 @@ static int fetch_objects(const char *remote_name,
35
40
return finish_command (& child ) ? -1 : 0 ;
36
41
}
37
42
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 )
42
45
{
43
46
struct promisor_remote * r ;
44
47
@@ -50,18 +53,19 @@ static struct promisor_remote *promisor_remote_new(const char *remote_name)
50
53
51
54
FLEX_ALLOC_STR (r , name , remote_name );
52
55
53
- * promisors_tail = r ;
54
- promisors_tail = & r -> next ;
56
+ * config -> promisors_tail = r ;
57
+ config -> promisors_tail = & r -> next ;
55
58
56
59
return r ;
57
60
}
58
61
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 ,
60
64
struct promisor_remote * * previous )
61
65
{
62
66
struct promisor_remote * r , * p ;
63
67
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 )
65
69
if (!strcmp (r -> name , remote_name )) {
66
70
if (previous )
67
71
* previous = p ;
@@ -71,7 +75,8 @@ static struct promisor_remote *promisor_remote_lookup(const char *remote_name,
71
75
return NULL ;
72
76
}
73
77
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 ,
75
80
struct promisor_remote * previous )
76
81
{
77
82
if (r -> next == NULL )
@@ -80,14 +85,15 @@ static void promisor_remote_move_to_tail(struct promisor_remote *r,
80
85
if (previous )
81
86
previous -> next = r -> next ;
82
87
else
83
- promisors = r -> next ? r -> next : r ;
88
+ config -> promisors = r -> next ? r -> next : r ;
84
89
r -> next = NULL ;
85
- * promisors_tail = r ;
86
- promisors_tail = & r -> next ;
90
+ * config -> promisors_tail = r ;
91
+ config -> promisors_tail = & r -> next ;
87
92
}
88
93
89
94
static int promisor_remote_config (const char * var , const char * value , void * data )
90
95
{
96
+ struct promisor_remote_config * config = data ;
91
97
const char * name ;
92
98
size_t namelen ;
93
99
const char * subkey ;
@@ -103,8 +109,8 @@ static int promisor_remote_config(const char *var, const char *value, void *data
103
109
104
110
remote_name = xmemdupz (name , namelen );
105
111
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 );
108
114
109
115
free (remote_name );
110
116
return 0 ;
@@ -113,9 +119,9 @@ static int promisor_remote_config(const char *var, const char *value, void *data
113
119
struct promisor_remote * r ;
114
120
char * remote_name = xmemdupz (name , namelen );
115
121
116
- r = promisor_remote_lookup (remote_name , NULL );
122
+ r = promisor_remote_lookup (config , remote_name , NULL );
117
123
if (!r )
118
- r = promisor_remote_new (remote_name );
124
+ r = promisor_remote_new (config , remote_name );
119
125
120
126
free (remote_name );
121
127
@@ -128,59 +134,63 @@ static int promisor_remote_config(const char *var, const char *value, void *data
128
134
return 0 ;
129
135
}
130
136
131
- static int initialized ;
132
-
133
- static void promisor_remote_init (void )
137
+ static void promisor_remote_init (struct repository * r )
134
138
{
135
- if (initialized )
139
+ struct promisor_remote_config * config ;
140
+
141
+ if (r -> promisor_remote_config )
136
142
return ;
137
- initialized = 1 ;
143
+ config = r -> promisor_remote_config =
144
+ xcalloc (sizeof (* r -> promisor_remote_config ), 1 );
145
+ config -> promisors_tail = & config -> promisors ;
138
146
139
- git_config ( promisor_remote_config , NULL );
147
+ repo_config ( r , promisor_remote_config , config );
140
148
141
- if (the_repository -> repository_format_partial_clone ) {
149
+ if (r -> repository_format_partial_clone ) {
142
150
struct promisor_remote * o , * previous ;
143
151
144
- o = promisor_remote_lookup (the_repository -> repository_format_partial_clone ,
152
+ o = promisor_remote_lookup (config ,
153
+ r -> repository_format_partial_clone ,
145
154
& previous );
146
155
if (o )
147
- promisor_remote_move_to_tail (o , previous );
156
+ promisor_remote_move_to_tail (config , o , previous );
148
157
else
149
- promisor_remote_new (the_repository -> repository_format_partial_clone );
158
+ promisor_remote_new (config , r -> repository_format_partial_clone );
150
159
}
151
160
}
152
161
153
- static void promisor_remote_clear (void )
162
+ void promisor_remote_clear (struct promisor_remote_config * config )
154
163
{
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 ;
158
167
free (r );
159
168
}
160
169
161
- promisors_tail = & promisors ;
170
+ config -> promisors_tail = & config -> promisors ;
162
171
}
163
172
164
- void promisor_remote_reinit ( void )
173
+ void repo_promisor_remote_reinit ( struct repository * r )
165
174
{
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 );
169
178
}
170
179
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 )
172
182
{
173
- promisor_remote_init ();
183
+ promisor_remote_init (r );
174
184
175
185
if (!remote_name )
176
- return promisors ;
186
+ return r -> promisor_remote_config -> promisors ;
177
187
178
- return promisor_remote_lookup (remote_name , NULL );
188
+ return promisor_remote_lookup (r -> promisor_remote_config , remote_name , NULL );
179
189
}
180
190
181
- int has_promisor_remote ( void )
191
+ int repo_has_promisor_remote ( struct repository * r )
182
192
{
183
- return !!promisor_remote_find ( NULL );
193
+ return !!repo_promisor_remote_find ( r , NULL );
184
194
}
185
195
186
196
static int remove_fetched_oids (struct repository * repo ,
@@ -228,9 +238,11 @@ int promisor_remote_get_direct(struct repository *repo,
228
238
if (oid_nr == 0 )
229
239
return 0 ;
230
240
231
- promisor_remote_init ();
241
+ promisor_remote_init (repo );
232
242
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 ) {
234
246
if (fetch_objects (r -> name , remaining_oids , remaining_nr ) < 0 ) {
235
247
if (remaining_nr == 1 )
236
248
continue ;
0 commit comments