@@ -65,19 +65,19 @@ static void add_pushurl(struct remote *remote, const char *pushurl)
65
65
remote -> pushurl [remote -> pushurl_nr ++ ] = pushurl ;
66
66
}
67
67
68
- static void add_pushurl_alias (struct remote * remote , const char * url )
68
+ static void add_pushurl_alias (struct remote_state * remote_state ,
69
+ struct remote * remote , const char * url )
69
70
{
70
- const char * pushurl =
71
- alias_url (url , & the_repository -> remote_state -> rewrites_push );
71
+ const char * pushurl = alias_url (url , & remote_state -> rewrites_push );
72
72
if (pushurl != url )
73
73
add_pushurl (remote , pushurl );
74
74
}
75
75
76
- static void add_url_alias (struct remote * remote , const char * url )
76
+ static void add_url_alias (struct remote_state * remote_state ,
77
+ struct remote * remote , const char * url )
77
78
{
78
- add_url (remote ,
79
- alias_url (url , & the_repository -> remote_state -> rewrites ));
80
- add_pushurl_alias (remote , url );
79
+ add_url (remote , alias_url (url , & remote_state -> rewrites ));
80
+ add_pushurl_alias (remote_state , remote , url );
81
81
}
82
82
83
83
struct remotes_hash_key {
@@ -102,7 +102,8 @@ static int remotes_hash_cmp(const void *unused_cmp_data,
102
102
return strcmp (a -> name , b -> name );
103
103
}
104
104
105
- static struct remote * make_remote (const char * name , int len )
105
+ static struct remote * make_remote (struct remote_state * remote_state ,
106
+ const char * name , int len )
106
107
{
107
108
struct remote * ret ;
108
109
struct remotes_hash_key lookup ;
@@ -115,8 +116,7 @@ static struct remote *make_remote(const char *name, int len)
115
116
lookup .len = len ;
116
117
hashmap_entry_init (& lookup_entry , memhash (name , len ));
117
118
118
- e = hashmap_get (& the_repository -> remote_state -> remotes_hash ,
119
- & lookup_entry , & lookup );
119
+ e = hashmap_get (& remote_state -> remotes_hash , & lookup_entry , & lookup );
120
120
if (e )
121
121
return container_of (e , struct remote , ent );
122
122
@@ -127,15 +127,12 @@ static struct remote *make_remote(const char *name, int len)
127
127
refspec_init (& ret -> push , REFSPEC_PUSH );
128
128
refspec_init (& ret -> fetch , REFSPEC_FETCH );
129
129
130
- ALLOC_GROW (the_repository -> remote_state -> remotes ,
131
- the_repository -> remote_state -> remotes_nr + 1 ,
132
- the_repository -> remote_state -> remotes_alloc );
133
- the_repository -> remote_state
134
- -> remotes [the_repository -> remote_state -> remotes_nr ++ ] = ret ;
130
+ ALLOC_GROW (remote_state -> remotes , remote_state -> remotes_nr + 1 ,
131
+ remote_state -> remotes_alloc );
132
+ remote_state -> remotes [remote_state -> remotes_nr ++ ] = ret ;
135
133
136
134
hashmap_entry_init (& ret -> ent , lookup_entry .hash );
137
- if (hashmap_put_entry (& the_repository -> remote_state -> remotes_hash , ret ,
138
- ent ))
135
+ if (hashmap_put_entry (& remote_state -> remotes_hash , ret , ent ))
139
136
BUG ("hashmap_put overwrote entry after hashmap_get returned NULL" );
140
137
return ret ;
141
138
}
@@ -169,25 +166,22 @@ static void add_merge(struct branch *branch, const char *name)
169
166
branch -> merge_name [branch -> merge_nr ++ ] = name ;
170
167
}
171
168
172
- static struct branch * make_branch (const char * name , size_t len )
169
+ static struct branch * make_branch (struct remote_state * remote_state ,
170
+ const char * name , size_t len )
173
171
{
174
172
struct branch * ret ;
175
173
int i ;
176
174
177
- for (i = 0 ; i < the_repository -> remote_state -> branches_nr ; i ++ ) {
178
- if (!strncmp (name ,
179
- the_repository -> remote_state -> branches [i ]-> name ,
180
- len ) &&
181
- !the_repository -> remote_state -> branches [i ]-> name [len ])
182
- return the_repository -> remote_state -> branches [i ];
175
+ for (i = 0 ; i < remote_state -> branches_nr ; i ++ ) {
176
+ if (!strncmp (name , remote_state -> branches [i ]-> name , len ) &&
177
+ !remote_state -> branches [i ]-> name [len ])
178
+ return remote_state -> branches [i ];
183
179
}
184
180
185
- ALLOC_GROW (the_repository -> remote_state -> branches ,
186
- the_repository -> remote_state -> branches_nr + 1 ,
187
- the_repository -> remote_state -> branches_alloc );
181
+ ALLOC_GROW (remote_state -> branches , remote_state -> branches_nr + 1 ,
182
+ remote_state -> branches_alloc );
188
183
CALLOC_ARRAY (ret , 1 );
189
- the_repository -> remote_state
190
- -> branches [the_repository -> remote_state -> branches_nr ++ ] = ret ;
184
+ remote_state -> branches [remote_state -> branches_nr ++ ] = ret ;
191
185
ret -> name = xstrndup (name , len );
192
186
ret -> refname = xstrfmt ("refs/heads/%s" , ret -> name );
193
187
@@ -229,7 +223,8 @@ static const char *skip_spaces(const char *s)
229
223
return s ;
230
224
}
231
225
232
- static void read_remotes_file (struct remote * remote )
226
+ static void read_remotes_file (struct remote_state * remote_state ,
227
+ struct remote * remote )
233
228
{
234
229
struct strbuf buf = STRBUF_INIT ;
235
230
FILE * f = fopen_or_warn (git_path ("remotes/%s" , remote -> name ), "r" );
@@ -244,7 +239,8 @@ static void read_remotes_file(struct remote *remote)
244
239
strbuf_rtrim (& buf );
245
240
246
241
if (skip_prefix (buf .buf , "URL:" , & v ))
247
- add_url_alias (remote , xstrdup (skip_spaces (v )));
242
+ add_url_alias (remote_state , remote ,
243
+ xstrdup (skip_spaces (v )));
248
244
else if (skip_prefix (buf .buf , "Push:" , & v ))
249
245
refspec_append (& remote -> push , skip_spaces (v ));
250
246
else if (skip_prefix (buf .buf , "Pull:" , & v ))
@@ -254,7 +250,8 @@ static void read_remotes_file(struct remote *remote)
254
250
fclose (f );
255
251
}
256
252
257
- static void read_branches_file (struct remote * remote )
253
+ static void read_branches_file (struct remote_state * remote_state ,
254
+ struct remote * remote )
258
255
{
259
256
char * frag ;
260
257
struct strbuf buf = STRBUF_INIT ;
@@ -286,7 +283,7 @@ static void read_branches_file(struct remote *remote)
286
283
else
287
284
frag = (char * )git_default_branch_name (0 );
288
285
289
- add_url_alias (remote , strbuf_detach (& buf , NULL ));
286
+ add_url_alias (remote_state , remote , strbuf_detach (& buf , NULL ));
290
287
refspec_appendf (& remote -> fetch , "refs/heads/%s:refs/heads/%s" ,
291
288
frag , remote -> name );
292
289
@@ -305,10 +302,12 @@ static int handle_config(const char *key, const char *value, void *cb)
305
302
const char * subkey ;
306
303
struct remote * remote ;
307
304
struct branch * branch ;
305
+ struct remote_state * remote_state = cb ;
306
+
308
307
if (parse_config_key (key , "branch" , & name , & namelen , & subkey ) >= 0 ) {
309
308
if (!name )
310
309
return 0 ;
311
- branch = make_branch (name , namelen );
310
+ branch = make_branch (remote_state , name , namelen );
312
311
if (!strcmp (subkey , "remote" )) {
313
312
return git_config_string (& branch -> remote_name , key , value );
314
313
} else if (!strcmp (subkey , "pushremote" )) {
@@ -327,16 +326,14 @@ static int handle_config(const char *key, const char *value, void *cb)
327
326
if (!strcmp (subkey , "insteadof" )) {
328
327
if (!value )
329
328
return config_error_nonbool (key );
330
- rewrite = make_rewrite (
331
- & the_repository -> remote_state -> rewrites , name ,
332
- namelen );
329
+ rewrite = make_rewrite (& remote_state -> rewrites , name ,
330
+ namelen );
333
331
add_instead_of (rewrite , xstrdup (value ));
334
332
} else if (!strcmp (subkey , "pushinsteadof" )) {
335
333
if (!value )
336
334
return config_error_nonbool (key );
337
- rewrite = make_rewrite (
338
- & the_repository -> remote_state -> rewrites_push ,
339
- name , namelen );
335
+ rewrite = make_rewrite (& remote_state -> rewrites_push ,
336
+ name , namelen );
340
337
add_instead_of (rewrite , xstrdup (value ));
341
338
}
342
339
}
@@ -346,9 +343,8 @@ static int handle_config(const char *key, const char *value, void *cb)
346
343
347
344
/* Handle remote.* variables */
348
345
if (!name && !strcmp (subkey , "pushdefault" ))
349
- return git_config_string (
350
- & the_repository -> remote_state -> pushremote_name , key ,
351
- value );
346
+ return git_config_string (& remote_state -> pushremote_name , key ,
347
+ value );
352
348
353
349
if (!name )
354
350
return 0 ;
@@ -358,7 +354,7 @@ static int handle_config(const char *key, const char *value, void *cb)
358
354
name );
359
355
return 0 ;
360
356
}
361
- remote = make_remote (name , namelen );
357
+ remote = make_remote (remote_state , name , namelen );
362
358
remote -> origin = REMOTE_CONFIG ;
363
359
if (current_config_scope () == CONFIG_SCOPE_LOCAL ||
364
360
current_config_scope () == CONFIG_SCOPE_WORKTREE )
@@ -428,61 +424,51 @@ static int handle_config(const char *key, const char *value, void *cb)
428
424
return 0 ;
429
425
}
430
426
431
- static void alias_all_urls (void )
427
+ static void alias_all_urls (struct remote_state * remote_state )
432
428
{
433
429
int i , j ;
434
- for (i = 0 ; i < the_repository -> remote_state -> remotes_nr ; i ++ ) {
430
+ for (i = 0 ; i < remote_state -> remotes_nr ; i ++ ) {
435
431
int add_pushurl_aliases ;
436
- if (!the_repository -> remote_state -> remotes [i ])
432
+ if (!remote_state -> remotes [i ])
437
433
continue ;
438
- for (j = 0 ;
439
- j < the_repository -> remote_state -> remotes [i ]-> pushurl_nr ;
440
- j ++ ) {
441
- the_repository -> remote_state -> remotes [i ]-> pushurl [j ] =
442
- alias_url (
443
- the_repository -> remote_state -> remotes [i ]
444
- -> pushurl [j ],
445
- & the_repository -> remote_state -> rewrites );
434
+ for (j = 0 ; j < remote_state -> remotes [i ]-> pushurl_nr ; j ++ ) {
435
+ remote_state -> remotes [i ]-> pushurl [j ] =
436
+ alias_url (remote_state -> remotes [i ]-> pushurl [j ],
437
+ & remote_state -> rewrites );
446
438
}
447
- add_pushurl_aliases =
448
- the_repository -> remote_state -> remotes [i ]-> pushurl_nr ==
449
- 0 ;
450
- for (j = 0 ;
451
- j < the_repository -> remote_state -> remotes [i ]-> url_nr ;
452
- j ++ ) {
439
+ add_pushurl_aliases = remote_state -> remotes [i ]-> pushurl_nr == 0 ;
440
+ for (j = 0 ; j < remote_state -> remotes [i ]-> url_nr ; j ++ ) {
453
441
if (add_pushurl_aliases )
454
442
add_pushurl_alias (
455
- the_repository -> remote_state -> remotes [i ],
456
- the_repository -> remote_state -> remotes [i ]
457
- -> url [j ]);
458
- the_repository -> remote_state -> remotes [i ]
459
- -> url [j ] = alias_url (
460
- the_repository -> remote_state -> remotes [i ]-> url [j ],
461
- & the_repository -> remote_state -> rewrites );
443
+ remote_state , remote_state -> remotes [i ],
444
+ remote_state -> remotes [i ]-> url [j ]);
445
+ remote_state -> remotes [i ]-> url [j ] =
446
+ alias_url (remote_state -> remotes [i ]-> url [j ],
447
+ & remote_state -> rewrites );
462
448
}
463
449
}
464
450
}
465
451
466
- static void read_config (void )
452
+ static void read_config (struct repository * repo )
467
453
{
468
- static int loaded ;
469
454
int flag ;
470
455
471
- if (loaded )
456
+ if (repo -> remote_state -> initialized )
472
457
return ;
473
- loaded = 1 ;
458
+ repo -> remote_state -> initialized = 1 ;
474
459
475
- the_repository -> remote_state -> current_branch = NULL ;
460
+ repo -> remote_state -> current_branch = NULL ;
476
461
if (startup_info -> have_repository ) {
477
- const char * head_ref = resolve_ref_unsafe ("HEAD" , 0 , NULL , & flag );
462
+ const char * head_ref = refs_resolve_ref_unsafe (
463
+ get_main_ref_store (repo ), "HEAD" , 0 , NULL , & flag );
478
464
if (head_ref && (flag & REF_ISSYMREF ) &&
479
465
skip_prefix (head_ref , "refs/heads/" , & head_ref )) {
480
- the_repository -> remote_state -> current_branch =
481
- make_branch ( head_ref , strlen (head_ref ));
466
+ repo -> remote_state -> current_branch = make_branch (
467
+ repo -> remote_state , head_ref , strlen (head_ref ));
482
468
}
483
469
}
484
- git_config ( handle_config , NULL );
485
- alias_all_urls ();
470
+ repo_config ( repo , handle_config , repo -> remote_state );
471
+ alias_all_urls (repo -> remote_state );
486
472
}
487
473
488
474
static int valid_remote_nick (const char * name )
@@ -552,23 +538,23 @@ static struct remote *remote_get_1(const char *name,
552
538
struct remote * ret ;
553
539
int name_given = 0 ;
554
540
555
- read_config ();
541
+ read_config (the_repository );
556
542
557
543
if (name )
558
544
name_given = 1 ;
559
545
else
560
546
name = get_default (the_repository -> remote_state -> current_branch ,
561
547
& name_given );
562
548
563
- ret = make_remote (name , 0 );
549
+ ret = make_remote (the_repository -> remote_state , name , 0 );
564
550
if (valid_remote_nick (name ) && have_git_dir ()) {
565
551
if (!valid_remote (ret ))
566
- read_remotes_file (ret );
552
+ read_remotes_file (the_repository -> remote_state , ret );
567
553
if (!valid_remote (ret ))
568
- read_branches_file (ret );
554
+ read_branches_file (the_repository -> remote_state , ret );
569
555
}
570
556
if (name_given && !valid_remote (ret ))
571
- add_url_alias (ret , name );
557
+ add_url_alias (the_repository -> remote_state , ret , name );
572
558
if (!valid_remote (ret ))
573
559
return NULL ;
574
560
return ret ;
@@ -596,7 +582,7 @@ int remote_is_configured(struct remote *remote, int in_repo)
596
582
int for_each_remote (each_remote_fn fn , void * priv )
597
583
{
598
584
int i , result = 0 ;
599
- read_config ();
585
+ read_config (the_repository );
600
586
for (i = 0 ; i < the_repository -> remote_state -> remotes_nr && !result ;
601
587
i ++ ) {
602
588
struct remote * remote =
@@ -1709,11 +1695,12 @@ struct branch *branch_get(const char *name)
1709
1695
{
1710
1696
struct branch * ret ;
1711
1697
1712
- read_config ();
1698
+ read_config (the_repository );
1713
1699
if (!name || !* name || !strcmp (name , "HEAD" ))
1714
1700
ret = the_repository -> remote_state -> current_branch ;
1715
1701
else
1716
- ret = make_branch (name , strlen (name ));
1702
+ ret = make_branch (the_repository -> remote_state , name ,
1703
+ strlen (name ));
1717
1704
set_merge (ret );
1718
1705
return ret ;
1719
1706
}
0 commit comments