@@ -1084,9 +1084,8 @@ N_("it took %.2f seconds to check forced updates; you can use\n"
1084
1084
1085
1085
static int store_updated_refs (const char * raw_url , const char * remote_name ,
1086
1086
int connectivity_checked , struct ref * ref_map ,
1087
- struct worktree * * worktrees )
1087
+ struct fetch_head * fetch_head , struct worktree * * worktrees )
1088
1088
{
1089
- struct fetch_head fetch_head ;
1090
1089
int url_len , i , rc = 0 ;
1091
1090
struct strbuf note = STRBUF_INIT , err = STRBUF_INIT ;
1092
1091
struct ref_transaction * transaction = NULL ;
@@ -1096,10 +1095,6 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
1096
1095
int want_status ;
1097
1096
int summary_width = transport_summary_width (ref_map );
1098
1097
1099
- rc = open_fetch_head (& fetch_head );
1100
- if (rc )
1101
- return -1 ;
1102
-
1103
1098
if (raw_url )
1104
1099
url = transport_anonymize_url (raw_url );
1105
1100
else
@@ -1206,7 +1201,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
1206
1201
strbuf_addf (& note , "'%s' of " , what );
1207
1202
}
1208
1203
1209
- append_fetch_head (& fetch_head , & rm -> old_oid ,
1204
+ append_fetch_head (fetch_head , & rm -> old_oid ,
1210
1205
rm -> fetch_head_status ,
1211
1206
note .buf , url , url_len );
1212
1207
@@ -1246,9 +1241,6 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
1246
1241
}
1247
1242
}
1248
1243
1249
- if (!rc )
1250
- commit_fetch_head (& fetch_head );
1251
-
1252
1244
if (rc & STORE_REF_ERROR_DF_CONFLICT )
1253
1245
error (_ ("some local refs could not be updated; try running\n"
1254
1246
" 'git remote prune %s' to remove any old, conflicting "
@@ -1268,7 +1260,6 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
1268
1260
strbuf_release (& err );
1269
1261
ref_transaction_free (transaction );
1270
1262
free (url );
1271
- close_fetch_head (& fetch_head );
1272
1263
return rc ;
1273
1264
}
1274
1265
@@ -1309,6 +1300,7 @@ static int check_exist_and_connected(struct ref *ref_map)
1309
1300
1310
1301
static int fetch_and_consume_refs (struct transport * transport ,
1311
1302
struct ref * ref_map ,
1303
+ struct fetch_head * fetch_head ,
1312
1304
struct worktree * * worktrees )
1313
1305
{
1314
1306
int connectivity_checked = 1 ;
@@ -1331,7 +1323,7 @@ static int fetch_and_consume_refs(struct transport *transport,
1331
1323
1332
1324
trace2_region_enter ("fetch" , "consume_refs" , the_repository );
1333
1325
ret = store_updated_refs (transport -> url , transport -> remote -> name ,
1334
- connectivity_checked , ref_map , worktrees );
1326
+ connectivity_checked , ref_map , fetch_head , worktrees );
1335
1327
trace2_region_leave ("fetch" , "consume_refs" , the_repository );
1336
1328
1337
1329
out :
@@ -1503,7 +1495,9 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
1503
1495
return transport ;
1504
1496
}
1505
1497
1506
- static void backfill_tags (struct transport * transport , struct ref * ref_map ,
1498
+ static void backfill_tags (struct transport * transport ,
1499
+ struct ref * ref_map ,
1500
+ struct fetch_head * fetch_head ,
1507
1501
struct worktree * * worktrees )
1508
1502
{
1509
1503
int cannot_reuse ;
@@ -1525,7 +1519,7 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map,
1525
1519
transport_set_option (transport , TRANS_OPT_FOLLOWTAGS , NULL );
1526
1520
transport_set_option (transport , TRANS_OPT_DEPTH , "0" );
1527
1521
transport_set_option (transport , TRANS_OPT_DEEPEN_RELATIVE , NULL );
1528
- fetch_and_consume_refs (transport , ref_map , worktrees );
1522
+ fetch_and_consume_refs (transport , ref_map , fetch_head , worktrees );
1529
1523
1530
1524
if (gsecondary ) {
1531
1525
transport_disconnect (gsecondary );
@@ -1544,6 +1538,7 @@ static int do_fetch(struct transport *transport,
1544
1538
TRANSPORT_LS_REFS_OPTIONS_INIT ;
1545
1539
int must_list_refs = 1 ;
1546
1540
struct worktree * * worktrees = get_worktrees ();
1541
+ struct fetch_head fetch_head = { 0 };
1547
1542
1548
1543
if (tags == TAGS_DEFAULT ) {
1549
1544
if (transport -> remote -> fetch_tags == 2 )
@@ -1601,6 +1596,10 @@ static int do_fetch(struct transport *transport,
1601
1596
if (!update_head_ok )
1602
1597
check_not_current_branch (ref_map , worktrees );
1603
1598
1599
+ retcode = open_fetch_head (& fetch_head );
1600
+ if (retcode )
1601
+ goto cleanup ;
1602
+
1604
1603
if (tags == TAGS_DEFAULT && autotags )
1605
1604
transport_set_option (transport , TRANS_OPT_FOLLOWTAGS , "1" );
1606
1605
if (prune ) {
@@ -1619,7 +1618,8 @@ static int do_fetch(struct transport *transport,
1619
1618
if (retcode != 0 )
1620
1619
retcode = 1 ;
1621
1620
}
1622
- if (fetch_and_consume_refs (transport , ref_map , worktrees )) {
1621
+
1622
+ if (fetch_and_consume_refs (transport , ref_map , & fetch_head , worktrees )) {
1623
1623
retcode = 1 ;
1624
1624
goto cleanup ;
1625
1625
}
@@ -1633,11 +1633,13 @@ static int do_fetch(struct transport *transport,
1633
1633
1634
1634
find_non_local_tags (remote_refs , & tags_ref_map , & tail );
1635
1635
if (tags_ref_map )
1636
- backfill_tags (transport , tags_ref_map , worktrees );
1636
+ backfill_tags (transport , tags_ref_map , & fetch_head , worktrees );
1637
1637
1638
1638
free_refs (tags_ref_map );
1639
1639
}
1640
1640
1641
+ commit_fetch_head (& fetch_head );
1642
+
1641
1643
if (set_upstream ) {
1642
1644
struct branch * branch = branch_get ("HEAD" );
1643
1645
struct ref * rm ;
@@ -1693,6 +1695,7 @@ static int do_fetch(struct transport *transport,
1693
1695
}
1694
1696
1695
1697
cleanup :
1698
+ close_fetch_head (& fetch_head );
1696
1699
free_refs (ref_map );
1697
1700
free_worktrees (worktrees );
1698
1701
return retcode ;
0 commit comments