Message ID | 9ebcc5808a21e1f87370b6c18ea28168e63d4e3a.1596590295.git.jonathantanmy@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Lazy fetch with subprocess | expand |
Jonathan Tan <jonathantanmy@google.com> writes: > Signed-off-by: Jonathan Tan <jonathantanmy@google.com> > --- > builtin/fetch.c | 19 +++++++++++++++++-- > 1 file changed, 17 insertions(+), 2 deletions(-) > > diff --git a/builtin/fetch.c b/builtin/fetch.c > index 3ccf69753f..a5498646bf 100644 > --- a/builtin/fetch.c > +++ b/builtin/fetch.c > @@ -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 negotiation_tip = STRING_LIST_INIT_NODUP; > static int fetch_write_commit_graph = -1; > +static int stdin_refspecs = 0; Don't initialize statics to 0 (leave that to BSS). > @@ -209,6 +210,8 @@ static struct option builtin_fetch_options[] = { > N_("check for forced-updates on all updated branches")), > OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph, > N_("write the commit-graph after fetching")), > + OPT_BOOL(0, "stdin", &stdin_refspecs, > + N_("accept refspecs from stdin")), > OPT_END() > }; > > @@ -1684,7 +1687,8 @@ static inline void fetch_one_setup_partial(struct remote *remote) > 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; > int i; > @@ -1741,6 +1745,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); > + } This will use refspecs both from the command line and the standard input by appending? IOW, these refspecs that came from the standard input are treated otherwise identically to those that came from the command line? I do not particularly care whether it is "append to command line" or "replace command line", as I do not think it makes much difference in usability. Just wanted to be sure you coded the behaviour you wanted. > @@ -1849,6 +1860,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) > die(_("--filter can only be used with the remote " > "configured in extensions.partialclone")); > > + if (stdin_refspecs) > + die(_("--stdin can only be used when fetching " > + "from one remote")); Is that only because you happened to have implemented the reading in fetch_one() that is designed to be called once per remote? You could read them here to a refspec for everybody, and then pass a pointer to that refspec as the extra parameter to fetch_one(), and fetch_one() can use that by duplicating and appending to its "rs", if we wanted to, no? I do not know how important to support such a use case, though. It just feels a bit of shame if this restriction is purely imposed by the implementation, when lifting the refstiction does not seem too involved. Thanks. > if (max_children < 0) > max_children = fetch_parallel_config;
> > @@ -1741,6 +1745,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); > > + } > > This will use refspecs both from the command line and the standard > input by appending? IOW, these refspecs that came from the standard > input are treated otherwise identically to those that came from the > command line? > > I do not particularly care whether it is "append to command line" or > "replace command line", as I do not think it makes much difference > in usability. Just wanted to be sure you coded the behaviour you > wanted. Yes, except that I didn't plan to support the "tag foo" format. (My aim with this is just to allow "git fetch" to take large numbers of refspecs, because when we lazy fetch, the number of objects we fetch might be large.) > > @@ -1849,6 +1860,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) > > die(_("--filter can only be used with the remote " > > "configured in extensions.partialclone")); > > > > + if (stdin_refspecs) > > + die(_("--stdin can only be used when fetching " > > + "from one remote")); > > Is that only because you happened to have implemented the reading in > fetch_one() that is designed to be called once per remote? > > You could read them here to a refspec for everybody, and then pass a > pointer to that refspec as the extra parameter to fetch_one(), and > fetch_one() can use that by duplicating and appending to its "rs", > if we wanted to, no? I do not know how important to support such a > use case, though. It just feels a bit of shame if this restriction > is purely imposed by the implementation, when lifting the refstiction > does not seem too involved. Yes, and I only implemented the reading in fetch_one() because fetch_multiple() does not read additional refspecs from the command-line (it does not take "argv"). Looking at the code, this seems to be on purpose - there is the error message "fetch --all does not make sense with refspecs", and when --multiple is set, all args are assumed to be remotes.
> > @@ -1741,6 +1745,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); > > + } > > This will use refspecs both from the command line and the standard > input by appending? IOW, these refspecs that came from the standard > input are treated otherwise identically to those that came from the > command line? > > I do not particularly care whether it is "append to command line" or > "replace command line", as I do not think it makes much difference > in usability. Just wanted to be sure you coded the behaviour you > wanted. Yes, except that I didn't plan to support the "tag foo" format. (My aim with this is just to allow "git fetch" to take large numbers of refspecs, because when we lazy fetch, the number of objects we fetch might be large.) > > @@ -1849,6 +1860,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) > > die(_("--filter can only be used with the remote " > > "configured in extensions.partialclone")); > > > > + if (stdin_refspecs) > > + die(_("--stdin can only be used when fetching " > > + "from one remote")); > > Is that only because you happened to have implemented the reading in > fetch_one() that is designed to be called once per remote? > > You could read them here to a refspec for everybody, and then pass a > pointer to that refspec as the extra parameter to fetch_one(), and > fetch_one() can use that by duplicating and appending to its "rs", > if we wanted to, no? I do not know how important to support such a > use case, though. It just feels a bit of shame if this restriction > is purely imposed by the implementation, when lifting the refstiction > does not seem too involved. Yes, and I only implemented the reading in fetch_one() because fetch_multiple() does not read additional refspecs from the command-line (it does not take "argv"). Looking at the code, this seems to be on purpose - there is the error message "fetch --all does not make sense with refspecs", and when --multiple is set, all args are assumed to be remotes.
Jonathan Tan <jonathantanmy@google.com> writes: > Yes, and I only implemented the reading in fetch_one() because > fetch_multiple() does not read additional refspecs from the command-line > (it does not take "argv"). Looking at the code, this seems to be on > purpose - there is the error message "fetch --all does not make sense > with refspecs", and when --multiple is set, all args are assumed to be > remotes. OK, that does make sense. so the multiple one is just a short-hand for for remote in ... do git fetch $remote done
diff --git a/builtin/fetch.c b/builtin/fetch.c index 3ccf69753f..a5498646bf 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -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 negotiation_tip = STRING_LIST_INIT_NODUP; 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) { @@ -209,6 +210,8 @@ static struct option builtin_fetch_options[] = { N_("check for forced-updates on all updated branches")), OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph, N_("write the commit-graph after fetching")), + OPT_BOOL(0, "stdin", &stdin_refspecs, + N_("accept refspecs from stdin")), OPT_END() }; @@ -1684,7 +1687,8 @@ static inline void fetch_one_setup_partial(struct remote *remote) 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; int i; @@ -1741,6 +1745,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) gtransport->server_options = &server_options; @@ -1841,7 +1852,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) if (remote) { if (filter_options.choice || has_promisor_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 { int max_children = max_jobs; @@ -1849,6 +1860,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) die(_("--filter can only be used with the remote " "configured in extensions.partialclone")); + if (stdin_refspecs) + die(_("--stdin can only be used when fetching " + "from one remote")); + if (max_children < 0) max_children = fetch_parallel_config;
Signed-off-by: Jonathan Tan <jonathantanmy@google.com> --- builtin/fetch.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)