5
5
#include "transport.h"
6
6
#include "strvec.h"
7
7
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
+ };
14
12
15
13
static int fetch_objects (struct repository * repo ,
16
14
const char * remote_name ,
@@ -23,6 +21,8 @@ static int fetch_objects(struct repository *repo,
23
21
24
22
child .git_cmd = 1 ;
25
23
child .in = -1 ;
24
+ if (repo != the_repository )
25
+ prepare_other_repo_env (& child .env_array , repo -> gitdir );
26
26
strvec_pushl (& child .args , "-c" , "fetch.negotiationAlgorithm=noop" ,
27
27
"fetch" , remote_name , "--no-tags" ,
28
28
"--no-write-fetch-head" , "--recurse-submodules=no" ,
@@ -45,10 +45,8 @@ static int fetch_objects(struct repository *repo,
45
45
return finish_command (& child ) ? -1 : 0 ;
46
46
}
47
47
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 )
52
50
{
53
51
struct promisor_remote * r ;
54
52
@@ -60,18 +58,19 @@ static struct promisor_remote *promisor_remote_new(const char *remote_name)
60
58
61
59
FLEX_ALLOC_STR (r , name , remote_name );
62
60
63
- * promisors_tail = r ;
64
- promisors_tail = & r -> next ;
61
+ * config -> promisors_tail = r ;
62
+ config -> promisors_tail = & r -> next ;
65
63
66
64
return r ;
67
65
}
68
66
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 ,
70
69
struct promisor_remote * * previous )
71
70
{
72
71
struct promisor_remote * r , * p ;
73
72
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 )
75
74
if (!strcmp (r -> name , remote_name )) {
76
75
if (previous )
77
76
* previous = p ;
@@ -81,7 +80,8 @@ static struct promisor_remote *promisor_remote_lookup(const char *remote_name,
81
80
return NULL ;
82
81
}
83
82
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 ,
85
85
struct promisor_remote * previous )
86
86
{
87
87
if (r -> next == NULL )
@@ -90,14 +90,15 @@ static void promisor_remote_move_to_tail(struct promisor_remote *r,
90
90
if (previous )
91
91
previous -> next = r -> next ;
92
92
else
93
- promisors = r -> next ? r -> next : r ;
93
+ config -> promisors = r -> next ? r -> next : r ;
94
94
r -> next = NULL ;
95
- * promisors_tail = r ;
96
- promisors_tail = & r -> next ;
95
+ * config -> promisors_tail = r ;
96
+ config -> promisors_tail = & r -> next ;
97
97
}
98
98
99
99
static int promisor_remote_config (const char * var , const char * value , void * data )
100
100
{
101
+ struct promisor_remote_config * config = data ;
101
102
const char * name ;
102
103
size_t namelen ;
103
104
const char * subkey ;
@@ -113,8 +114,8 @@ static int promisor_remote_config(const char *var, const char *value, void *data
113
114
114
115
remote_name = xmemdupz (name , namelen );
115
116
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 );
118
119
119
120
free (remote_name );
120
121
return 0 ;
@@ -123,9 +124,9 @@ static int promisor_remote_config(const char *var, const char *value, void *data
123
124
struct promisor_remote * r ;
124
125
char * remote_name = xmemdupz (name , namelen );
125
126
126
- r = promisor_remote_lookup (remote_name , NULL );
127
+ r = promisor_remote_lookup (config , remote_name , NULL );
127
128
if (!r )
128
- r = promisor_remote_new (remote_name );
129
+ r = promisor_remote_new (config , remote_name );
129
130
130
131
free (remote_name );
131
132
@@ -138,59 +139,63 @@ static int promisor_remote_config(const char *var, const char *value, void *data
138
139
return 0 ;
139
140
}
140
141
141
- static int initialized ;
142
-
143
- static void promisor_remote_init (void )
142
+ static void promisor_remote_init (struct repository * r )
144
143
{
145
- if (initialized )
144
+ struct promisor_remote_config * config ;
145
+
146
+ if (r -> promisor_remote_config )
146
147
return ;
147
- initialized = 1 ;
148
+ config = r -> promisor_remote_config =
149
+ xcalloc (sizeof (* r -> promisor_remote_config ), 1 );
150
+ config -> promisors_tail = & config -> promisors ;
148
151
149
- git_config ( promisor_remote_config , NULL );
152
+ repo_config ( r , promisor_remote_config , config );
150
153
151
- if (repository_format_partial_clone ) {
154
+ if (r -> repository_format_partial_clone ) {
152
155
struct promisor_remote * o , * previous ;
153
156
154
- o = promisor_remote_lookup (repository_format_partial_clone ,
157
+ o = promisor_remote_lookup (config ,
158
+ r -> repository_format_partial_clone ,
155
159
& previous );
156
160
if (o )
157
- promisor_remote_move_to_tail (o , previous );
161
+ promisor_remote_move_to_tail (config , o , previous );
158
162
else
159
- promisor_remote_new (repository_format_partial_clone );
163
+ promisor_remote_new (config , r -> repository_format_partial_clone );
160
164
}
161
165
}
162
166
163
- static void promisor_remote_clear (void )
167
+ void promisor_remote_clear (struct promisor_remote_config * config )
164
168
{
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 ;
168
172
free (r );
169
173
}
170
174
171
- promisors_tail = & promisors ;
175
+ config -> promisors_tail = & config -> promisors ;
172
176
}
173
177
174
- void promisor_remote_reinit ( void )
178
+ void repo_promisor_remote_reinit ( struct repository * r )
175
179
{
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 );
179
183
}
180
184
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 )
182
187
{
183
- promisor_remote_init ();
188
+ promisor_remote_init (r );
184
189
185
190
if (!remote_name )
186
- return promisors ;
191
+ return r -> promisor_remote_config -> promisors ;
187
192
188
- return promisor_remote_lookup (remote_name , NULL );
193
+ return promisor_remote_lookup (r -> promisor_remote_config , remote_name , NULL );
189
194
}
190
195
191
- int has_promisor_remote ( void )
196
+ int repo_has_promisor_remote ( struct repository * r )
192
197
{
193
- return !!promisor_remote_find ( NULL );
198
+ return !!repo_promisor_remote_find ( r , NULL );
194
199
}
195
200
196
201
static int remove_fetched_oids (struct repository * repo ,
@@ -238,9 +243,9 @@ int promisor_remote_get_direct(struct repository *repo,
238
243
if (oid_nr == 0 )
239
244
return 0 ;
240
245
241
- promisor_remote_init ();
246
+ promisor_remote_init (repo );
242
247
243
- for (r = promisors ; r ; r = r -> next ) {
248
+ for (r = repo -> promisor_remote_config -> promisors ; r ; r = r -> next ) {
244
249
if (fetch_objects (repo , r -> name , remaining_oids , remaining_nr ) < 0 ) {
245
250
if (remaining_nr == 1 )
246
251
continue ;
0 commit comments