@@ -254,17 +254,17 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
254
254
return 0 ;
255
255
}
256
256
257
- static void find_non_local_tags (struct transport * transport ,
258
- struct ref * * head ,
259
- struct ref * * * tail )
257
+ static void find_non_local_tags (const struct ref * refs ,
258
+ struct ref * * head ,
259
+ struct ref * * * tail )
260
260
{
261
261
struct string_list existing_refs = STRING_LIST_INIT_DUP ;
262
262
struct string_list remote_refs = STRING_LIST_INIT_NODUP ;
263
263
const struct ref * ref ;
264
264
struct string_list_item * item = NULL ;
265
265
266
266
for_each_ref (add_existing , & existing_refs );
267
- for (ref = transport_get_remote_refs ( transport , NULL ) ; ref ; ref = ref -> next ) {
267
+ for (ref = refs ; ref ; ref = ref -> next ) {
268
268
if (!starts_with (ref -> name , "refs/tags/" ))
269
269
continue ;
270
270
@@ -338,35 +338,20 @@ static void find_non_local_tags(struct transport *transport,
338
338
string_list_clear (& remote_refs , 0 );
339
339
}
340
340
341
- static struct ref * get_ref_map (struct transport * transport ,
341
+ static struct ref * get_ref_map (struct remote * remote ,
342
+ const struct ref * remote_refs ,
342
343
struct refspec * rs ,
343
344
int tags , int * autotags )
344
345
{
345
346
int i ;
346
347
struct ref * rm ;
347
348
struct ref * ref_map = NULL ;
348
349
struct ref * * tail = & ref_map ;
349
- struct argv_array ref_prefixes = ARGV_ARRAY_INIT ;
350
350
351
351
/* opportunistically-updated references: */
352
352
struct ref * orefs = NULL , * * oref_tail = & orefs ;
353
353
354
354
struct string_list existing_refs = STRING_LIST_INIT_DUP ;
355
- const struct ref * remote_refs ;
356
-
357
- if (rs -> nr )
358
- refspec_ref_prefixes (rs , & ref_prefixes );
359
- else if (transport -> remote && transport -> remote -> fetch .nr )
360
- refspec_ref_prefixes (& transport -> remote -> fetch , & ref_prefixes );
361
-
362
- if (ref_prefixes .argc &&
363
- (tags == TAGS_SET || (tags == TAGS_DEFAULT && !rs -> nr ))) {
364
- argv_array_push (& ref_prefixes , "refs/tags/" );
365
- }
366
-
367
- remote_refs = transport_get_remote_refs (transport , & ref_prefixes );
368
-
369
- argv_array_clear (& ref_prefixes );
370
355
371
356
if (rs -> nr ) {
372
357
struct refspec * fetch_refspec ;
@@ -403,15 +388,14 @@ static struct ref *get_ref_map(struct transport *transport,
403
388
if (refmap .nr )
404
389
fetch_refspec = & refmap ;
405
390
else
406
- fetch_refspec = & transport -> remote -> fetch ;
391
+ fetch_refspec = & remote -> fetch ;
407
392
408
393
for (i = 0 ; i < fetch_refspec -> nr ; i ++ )
409
394
get_fetch_map (ref_map , & fetch_refspec -> items [i ], & oref_tail , 1 );
410
395
} else if (refmap .nr ) {
411
396
die ("--refmap option is only meaningful with command-line refspec(s)." );
412
397
} else {
413
398
/* Use the defaults */
414
- struct remote * remote = transport -> remote ;
415
399
struct branch * branch = branch_get (NULL );
416
400
int has_merge = branch_has_merge_config (branch );
417
401
if (remote &&
@@ -450,7 +434,7 @@ static struct ref *get_ref_map(struct transport *transport,
450
434
/* also fetch all tags */
451
435
get_fetch_map (remote_refs , tag_refspec , & tail , 0 );
452
436
else if (tags == TAGS_DEFAULT && * autotags )
453
- find_non_local_tags (transport , & ref_map , & tail );
437
+ find_non_local_tags (remote_refs , & ref_map , & tail );
454
438
455
439
/* Now append any refs to be updated opportunistically: */
456
440
* tail = orefs ;
@@ -1143,6 +1127,8 @@ static int do_fetch(struct transport *transport,
1143
1127
struct ref * ref_map ;
1144
1128
int autotags = (transport -> remote -> fetch_tags == 1 );
1145
1129
int retcode = 0 ;
1130
+ const struct ref * remote_refs ;
1131
+ struct argv_array ref_prefixes = ARGV_ARRAY_INIT ;
1146
1132
1147
1133
if (tags == TAGS_DEFAULT ) {
1148
1134
if (transport -> remote -> fetch_tags == 2 )
@@ -1158,7 +1144,21 @@ static int do_fetch(struct transport *transport,
1158
1144
goto cleanup ;
1159
1145
}
1160
1146
1161
- ref_map = get_ref_map (transport , rs , tags , & autotags );
1147
+ if (rs -> nr )
1148
+ refspec_ref_prefixes (rs , & ref_prefixes );
1149
+ else if (transport -> remote && transport -> remote -> fetch .nr )
1150
+ refspec_ref_prefixes (& transport -> remote -> fetch , & ref_prefixes );
1151
+
1152
+ if (ref_prefixes .argc &&
1153
+ (tags == TAGS_SET || (tags == TAGS_DEFAULT && !rs -> nr ))) {
1154
+ argv_array_push (& ref_prefixes , "refs/tags/" );
1155
+ }
1156
+
1157
+ remote_refs = transport_get_remote_refs (transport , & ref_prefixes );
1158
+ argv_array_clear (& ref_prefixes );
1159
+
1160
+ ref_map = get_ref_map (transport -> remote , remote_refs , rs ,
1161
+ tags , & autotags );
1162
1162
if (!update_head_ok )
1163
1163
check_not_current_branch (ref_map );
1164
1164
@@ -1190,7 +1190,7 @@ static int do_fetch(struct transport *transport,
1190
1190
if (tags == TAGS_DEFAULT && autotags ) {
1191
1191
struct ref * * tail = & ref_map ;
1192
1192
ref_map = NULL ;
1193
- find_non_local_tags (transport , & ref_map , & tail );
1193
+ find_non_local_tags (remote_refs , & ref_map , & tail );
1194
1194
if (ref_map )
1195
1195
backfill_tags (transport , ref_map );
1196
1196
free_refs (ref_map );
0 commit comments