transport.c: extract 'fill_alternate_refs_command'

To list alternate references, 'read_alternate_refs' creates a child process running 'git for-each-ref' in the alternate's Git directory. Prepare to run other commands besides 'git for-each-ref' by introducing and moving the relevant code from 'read_alternate_refs' to 'fill_alternate_refs_command'. Signed-off-by: Taylor Blau <me@ttaylorr.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Oct 8, 2018 at 11:09 UTC 1e5f31d444436cfab1b1aef3026ffbd925f5a818
1 file changed +12 -6
transport.c
+12 -6
@@ -1325,6 +1325,17 @@ literal_copy:
1325 return xstrdup(url);
1326 }
1327
1328 +static void fill_alternate_refs_command(struct child_process *cmd,
1329 + const char *repo_path)
1330 +{
1331 + cmd->git_cmd = 1;
1332 + argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path);
1333 + argv_array_push(&cmd->args, "for-each-ref");
1334 + argv_array_push(&cmd->args, "--format=%(objectname)");
1335 + cmd->env = local_repo_env;
1336 + cmd->out = -1;
1337 +}
1338 +
1339 static void read_alternate_refs(const char *path,
1340 alternate_ref_fn *cb,
1341 void *data)
@@ -1333,12 +1344,7 @@ static void read_alternate_refs(const char *path,
1344 struct strbuf line = STRBUF_INIT;
1345 FILE *fh;
1346
1336 - cmd.git_cmd = 1;
1337 - argv_array_pushf(&cmd.args, "--git-dir=%s", path);
1338 - argv_array_push(&cmd.args, "for-each-ref");
1339 - argv_array_push(&cmd.args, "--format=%(objectname)");
1340 - cmd.env = local_repo_env;
1341 - cmd.out = -1;
1347 + fill_alternate_refs_command(&cmd, path);
1348
1349 if (start_command(&cmd))
1350 return;