Skip to content

Commit 284b2ce

Browse files
pks-tgitster
authored andcommitted
fetch: refactor fetch refs to be more extendable
Refactor `fetch_refs()` code to make it more extendable by explicitly handling error cases. The refactored code should behave the same. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 62b5a35 commit 284b2ce

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

builtin/fetch.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,18 +1293,28 @@ static int check_exist_and_connected(struct ref *ref_map)
12931293

12941294
static int fetch_refs(struct transport *transport, struct ref *ref_map)
12951295
{
1296-
int ret = check_exist_and_connected(ref_map);
1296+
int ret;
1297+
1298+
/*
1299+
* We don't need to perform a fetch in case we can already satisfy all
1300+
* refs.
1301+
*/
1302+
ret = check_exist_and_connected(ref_map);
12971303
if (ret) {
12981304
trace2_region_enter("fetch", "fetch_refs", the_repository);
12991305
ret = transport_fetch_refs(transport, ref_map);
13001306
trace2_region_leave("fetch", "fetch_refs", the_repository);
1307+
if (ret)
1308+
goto out;
13011309
}
1302-
if (!ret)
1303-
/*
1304-
* Keep the new pack's ".keep" file around to allow the caller
1305-
* time to update refs to reference the new objects.
1306-
*/
1307-
return 0;
1310+
1311+
/*
1312+
* Keep the new pack's ".keep" file around to allow the caller
1313+
* time to update refs to reference the new objects.
1314+
*/
1315+
return ret;
1316+
1317+
out:
13081318
transport_unlock_pack(transport);
13091319
return ret;
13101320
}

0 commit comments

Comments
 (0)