Skip to content

Commit 135a12b

Browse files
chooglengitster
authored andcommitted
fetch: skip tasks related to fetching objects
cmd_fetch() does the following with the assumption that objects are fetched: * Run gc * Write commit graphs (if enabled by fetch.writeCommitGraph=true) However, neither of these tasks makes sense if objects are not fetched e.g. `git fetch --negotiate-only` never fetches objects. Speed up cmd_fetch() by bailing out early if we know for certain that objects will not be fetched. cmd_fetch() can bail out early whenever objects are not fetched, but for now this only considers --negotiate-only. The same optimization does not apply to `git fetch --dry-run` because that actually fetches objects; the dry run refers to not updating refs. Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bec587d commit 135a12b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

builtin/fetch.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,17 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
21332133
strvec_clear(&options);
21342134
}
21352135

2136+
/*
2137+
* Skip irrelevant tasks because we know objects were not
2138+
* fetched.
2139+
*
2140+
* NEEDSWORK: as a future optimization, we can return early
2141+
* whenever objects were not fetched e.g. if we already have all
2142+
* of them.
2143+
*/
2144+
if (negotiate_only)
2145+
goto cleanup;
2146+
21362147
prepare_repo_settings(the_repository);
21372148
if (fetch_write_commit_graph > 0 ||
21382149
(fetch_write_commit_graph < 0 &&

0 commit comments

Comments
 (0)