Skip to content

Commit a039a1f

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48bf2fa commit a039a1f

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

builtin/gc.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -873,55 +873,38 @@ static int maintenance_task_commit_graph(struct maintenance_run_opts *opts)
873873
return 0;
874874
}
875875

876-
static int fetch_remote(const char *remote, struct maintenance_run_opts *opts)
876+
static int fetch_remote(struct remote *remote, void *cbdata)
877877
{
878+
struct maintenance_run_opts *opts = cbdata;
878879
struct child_process child = CHILD_PROCESS_INIT;
879880

880881
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",
882883
"--no-write-fetch-head", "--recurse-submodules=no",
883884
"--refmap=", NULL);
884885

885886
if (opts->quiet)
886887
strvec_push(&child.args, "--quiet");
887888

888-
strvec_pushf(&child.args, "+refs/heads/*:refs/prefetch/%s/*", remote);
889+
strvec_pushf(&child.args, "+refs/heads/*:refs/prefetch/%s/*", remote->name);
889890

890891
return !!run_command(&child);
891892
}
892893

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-
901894
static int maintenance_task_prefetch(struct maintenance_run_opts *opts)
902895
{
903-
int result = 0;
904-
struct string_list_item *item;
905-
struct string_list remotes = STRING_LIST_INIT_DUP;
906-
907896
git_config_set_multivar_gently("log.excludedecoration",
908897
"refs/prefetch/",
909898
"refs/prefetch/",
910899
CONFIG_FLAGS_FIXED_VALUE |
911900
CONFIG_FLAGS_MULTI_REPLACE);
912901

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;
917905
}
918906

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;
925908
}
926909

927910
static int maintenance_task_gc(struct maintenance_run_opts *opts)

0 commit comments

Comments
 (0)