Skip to content

Commit

Permalink
transport.c: extract 'fill_alternate_refs_command'
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Jeff King <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
ttaylorr authored and gitster committed Oct 9, 2018
1 parent bdf4276 commit 1e5f31d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,17 @@ char *transport_anonymize_url(const char *url)
return xstrdup(url);
}

static void fill_alternate_refs_command(struct child_process *cmd,
const char *repo_path)
{
cmd->git_cmd = 1;
argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path);
argv_array_push(&cmd->args, "for-each-ref");
argv_array_push(&cmd->args, "--format=%(objectname)");
cmd->env = local_repo_env;
cmd->out = -1;
}

static void read_alternate_refs(const char *path,
alternate_ref_fn *cb,
void *data)
Expand All @@ -1333,12 +1344,7 @@ static void read_alternate_refs(const char *path,
struct strbuf line = STRBUF_INIT;
FILE *fh;

cmd.git_cmd = 1;
argv_array_pushf(&cmd.args, "--git-dir=%s", path);
argv_array_push(&cmd.args, "for-each-ref");
argv_array_push(&cmd.args, "--format=%(objectname)");
cmd.env = local_repo_env;
cmd.out = -1;
fill_alternate_refs_command(&cmd, path);

if (start_command(&cmd))
return;
Expand Down

0 comments on commit 1e5f31d

Please sign in to comment.