Skip to content

Commit 14b8ced

Browse files
bmwillgitster
authored andcommitted
fetch: refactor the population of peer ref OIDs
Populate peer ref OIDs in get_ref_map instead of do_fetch. Besides tightening scopes of variables in the code, this also prepares for get_ref_map being able to be called multiple times within do_fetch. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3374292 commit 14b8ced

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

builtin/fetch.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ static struct ref *get_ref_map(struct transport *transport,
351351
/* opportunistically-updated references: */
352352
struct ref *orefs = NULL, **oref_tail = &orefs;
353353

354+
struct string_list existing_refs = STRING_LIST_INIT_DUP;
354355
const struct ref *remote_refs;
355356

356357
if (rs->nr)
@@ -458,7 +459,23 @@ static struct ref *get_ref_map(struct transport *transport,
458459
tail = &rm->next;
459460
}
460461

461-
return ref_remove_duplicates(ref_map);
462+
ref_map = ref_remove_duplicates(ref_map);
463+
464+
for_each_ref(add_existing, &existing_refs);
465+
for (rm = ref_map; rm; rm = rm->next) {
466+
if (rm->peer_ref) {
467+
struct string_list_item *peer_item =
468+
string_list_lookup(&existing_refs,
469+
rm->peer_ref->name);
470+
if (peer_item) {
471+
struct object_id *old_oid = peer_item->util;
472+
oidcpy(&rm->peer_ref->old_oid, old_oid);
473+
}
474+
}
475+
}
476+
string_list_clear(&existing_refs, 1);
477+
478+
return ref_map;
462479
}
463480

464481
#define STORE_REF_ERROR_OTHER 1
@@ -1110,14 +1127,10 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map)
11101127
static int do_fetch(struct transport *transport,
11111128
struct refspec *rs)
11121129
{
1113-
struct string_list existing_refs = STRING_LIST_INIT_DUP;
11141130
struct ref *ref_map;
1115-
struct ref *rm;
11161131
int autotags = (transport->remote->fetch_tags == 1);
11171132
int retcode = 0;
11181133

1119-
for_each_ref(add_existing, &existing_refs);
1120-
11211134
if (tags == TAGS_DEFAULT) {
11221135
if (transport->remote->fetch_tags == 2)
11231136
tags = TAGS_SET;
@@ -1136,18 +1149,6 @@ static int do_fetch(struct transport *transport,
11361149
if (!update_head_ok)
11371150
check_not_current_branch(ref_map);
11381151

1139-
for (rm = ref_map; rm; rm = rm->next) {
1140-
if (rm->peer_ref) {
1141-
struct string_list_item *peer_item =
1142-
string_list_lookup(&existing_refs,
1143-
rm->peer_ref->name);
1144-
if (peer_item) {
1145-
struct object_id *old_oid = peer_item->util;
1146-
oidcpy(&rm->peer_ref->old_oid, old_oid);
1147-
}
1148-
}
1149-
}
1150-
11511152
if (tags == TAGS_DEFAULT && autotags)
11521153
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
11531154
if (prune) {
@@ -1183,7 +1184,6 @@ static int do_fetch(struct transport *transport,
11831184
}
11841185

11851186
cleanup:
1186-
string_list_clear(&existing_refs, 1);
11871187
return retcode;
11881188
}
11891189

0 commit comments

Comments
 (0)