fetch: allow refspecs specified through stdin
In a subsequent patch, partial clones will be taught to fetch missing objects using a "git fetch" subprocess. Because the number of objects fetched may be too numerous to fit on the command line, teach "fetch" to accept refspecs passed through stdin. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
cbe566a071
commit
2b713c272c
@ -48,6 +48,10 @@ include::fetch-options.txt[]
|
|||||||
|
|
||||||
include::pull-fetch-param.txt[]
|
include::pull-fetch-param.txt[]
|
||||||
|
|
||||||
|
--stdin::
|
||||||
|
Read refspecs, one per line, from stdin in addition to those provided
|
||||||
|
as arguments. The "tag <name>" format is not supported.
|
||||||
|
|
||||||
include::urls-remotes.txt[]
|
include::urls-remotes.txt[]
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ static struct list_objects_filter_options filter_options;
|
|||||||
static struct string_list server_options = STRING_LIST_INIT_DUP;
|
static struct string_list server_options = STRING_LIST_INIT_DUP;
|
||||||
static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP;
|
static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP;
|
||||||
static int fetch_write_commit_graph = -1;
|
static int fetch_write_commit_graph = -1;
|
||||||
|
static int stdin_refspecs = 0;
|
||||||
|
|
||||||
static int git_fetch_config(const char *k, const char *v, void *cb)
|
static int git_fetch_config(const char *k, const char *v, void *cb)
|
||||||
{
|
{
|
||||||
@ -205,6 +206,8 @@ static struct option builtin_fetch_options[] = {
|
|||||||
N_("check for forced-updates on all updated branches")),
|
N_("check for forced-updates on all updated branches")),
|
||||||
OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph,
|
OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph,
|
||||||
N_("write the commit-graph after fetching")),
|
N_("write the commit-graph after fetching")),
|
||||||
|
OPT_BOOL(0, "stdin", &stdin_refspecs,
|
||||||
|
N_("accept refspecs from stdin")),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1680,7 +1683,8 @@ static inline void fetch_one_setup_partial(struct remote *remote)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fetch_one(struct remote *remote, int argc, const char **argv, int prune_tags_ok)
|
static int fetch_one(struct remote *remote, int argc, const char **argv,
|
||||||
|
int prune_tags_ok, int use_stdin_refspecs)
|
||||||
{
|
{
|
||||||
struct refspec rs = REFSPEC_INIT_FETCH;
|
struct refspec rs = REFSPEC_INIT_FETCH;
|
||||||
int i;
|
int i;
|
||||||
@ -1737,6 +1741,13 @@ static int fetch_one(struct remote *remote, int argc, const char **argv, int pru
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (use_stdin_refspecs) {
|
||||||
|
struct strbuf line = STRBUF_INIT;
|
||||||
|
while (strbuf_getline_lf(&line, stdin) != EOF)
|
||||||
|
refspec_append(&rs, line.buf);
|
||||||
|
strbuf_release(&line);
|
||||||
|
}
|
||||||
|
|
||||||
if (server_options.nr)
|
if (server_options.nr)
|
||||||
gtransport->server_options = &server_options;
|
gtransport->server_options = &server_options;
|
||||||
|
|
||||||
@ -1837,7 +1848,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
|
|||||||
if (remote) {
|
if (remote) {
|
||||||
if (filter_options.choice || has_promisor_remote())
|
if (filter_options.choice || has_promisor_remote())
|
||||||
fetch_one_setup_partial(remote);
|
fetch_one_setup_partial(remote);
|
||||||
result = fetch_one(remote, argc, argv, prune_tags_ok);
|
result = fetch_one(remote, argc, argv, prune_tags_ok, stdin_refspecs);
|
||||||
} else {
|
} else {
|
||||||
int max_children = max_jobs;
|
int max_children = max_jobs;
|
||||||
|
|
||||||
@ -1845,6 +1856,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
|
|||||||
die(_("--filter can only be used with the remote "
|
die(_("--filter can only be used with the remote "
|
||||||
"configured in extensions.partialclone"));
|
"configured in extensions.partialclone"));
|
||||||
|
|
||||||
|
if (stdin_refspecs)
|
||||||
|
die(_("--stdin can only be used when fetching "
|
||||||
|
"from one remote"));
|
||||||
|
|
||||||
if (max_children < 0)
|
if (max_children < 0)
|
||||||
max_children = fetch_parallel_config;
|
max_children = fetch_parallel_config;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user