maintenance: simplify prefetch logic
The previous logic filled a string list with the names of each remote, but instead we could simply run the appropriate 'git fetch' data directly in the remote iterator. Do this for reduced code size, but also because it sets up an upcoming change to use the remote's refspec. This data is accessible from the 'struct remote' data that is now accessible in fetch_remote(). Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Apr 6, 2021 at 18:47 UTC
a039a1fcf987de3a8209cc5229324d37d9ead16e
1 file changed
+8
-25
builtin/gc.c
+8
-25
@@ -873,55 +873,38 @@ static int maintenance_task_commit_graph(struct maintenance_run_opts *opts)
873
return 0;
874
}
875
876
-static int fetch_remote(const char *remote, struct maintenance_run_opts *opts)
876
+static int fetch_remote(struct remote *remote, void *cbdata)
877
{
878
+ struct maintenance_run_opts *opts = cbdata;
879
struct child_process child = CHILD_PROCESS_INIT;
880
881
child.git_cmd = 1;
881
- strvec_pushl(&child.args, "fetch", remote, "--prune", "--no-tags",
882
+ strvec_pushl(&child.args, "fetch", remote->name, "--prune", "--no-tags",
883
"--no-write-fetch-head", "--recurse-submodules=no",
884
"--refmap=", NULL);
885
886
if (opts->quiet)
887
strvec_push(&child.args, "--quiet");
888
888
- strvec_pushf(&child.args, "+refs/heads/*:refs/prefetch/%s/*", remote);
889
+ strvec_pushf(&child.args, "+refs/heads/*:refs/prefetch/%s/*", remote->name);
890
891
return !!run_command(&child);
892
}
893
893
-static int append_remote(struct remote *remote, void *cbdata)
894
-{
895
- struct string_list *remotes = (struct string_list *)cbdata;
896
-
897
- string_list_append(remotes, remote->name);
898
- return 0;
899
-}
900
-
894
static int maintenance_task_prefetch(struct maintenance_run_opts *opts)
895
{
903
- int result = 0;
904
- struct string_list_item *item;
905
- struct string_list remotes = STRING_LIST_INIT_DUP;
906
-
896
git_config_set_multivar_gently("log.excludedecoration",
897
"refs/prefetch/",
898
"refs/prefetch/",
899
CONFIG_FLAGS_FIXED_VALUE |
900
CONFIG_FLAGS_MULTI_REPLACE);
901
913
- if (for_each_remote(append_remote, &remotes)) {
914
- error(_("failed to fill remotes"));
915
- result = 1;
916
- goto cleanup;
902
+ if (for_each_remote(fetch_remote, opts)) {
903
+ error(_("failed to prefetch remotes"));
904
+ return 1;
905
}
906
919
- for_each_string_list_item(item, &remotes)
920
- result |= fetch_remote(item->string, opts);
921
-
922
-cleanup:
923
- string_list_clear(&remotes, 0);
924
- return result;
907
+ return 0;
908
}
909
910
static int maintenance_task_gc(struct maintenance_run_opts *opts)