remote-curl: add 'get' capability
A future change will want a way to download a file over HTTP(S) using the simplest of download mechanisms. We do not want to assume that the server on the other side understands anything about the Git protocol but could be a simple static web server. Create the new 'get' capability for the remote helpers which advertises that the 'get' command is avalable. A caller can send a line containing 'get <url> <path>' to download the file at <url> into the file at <path>. Reviewed-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
6a475b71f8
commit
b5624a4474
@ -1286,6 +1286,29 @@ static void parse_fetch(struct strbuf *buf)
|
||||
strbuf_reset(buf);
|
||||
}
|
||||
|
||||
static void parse_get(const char *arg)
|
||||
{
|
||||
struct strbuf url = STRBUF_INIT;
|
||||
struct strbuf path = STRBUF_INIT;
|
||||
const char *space;
|
||||
|
||||
space = strchr(arg, ' ');
|
||||
|
||||
if (!space)
|
||||
die(_("protocol error: expected '<url> <path>', missing space"));
|
||||
|
||||
strbuf_add(&url, arg, space - arg);
|
||||
strbuf_addstr(&path, space + 1);
|
||||
|
||||
if (http_get_file(url.buf, path.buf, NULL))
|
||||
die(_("failed to download file at URL '%s'"), url.buf);
|
||||
|
||||
strbuf_release(&url);
|
||||
strbuf_release(&path);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static int push_dav(int nr_spec, const char **specs)
|
||||
{
|
||||
struct child_process child = CHILD_PROCESS_INIT;
|
||||
@ -1564,9 +1587,14 @@ int cmd_main(int argc, const char **argv)
|
||||
printf("unsupported\n");
|
||||
fflush(stdout);
|
||||
|
||||
} else if (skip_prefix(buf.buf, "get ", &arg)) {
|
||||
parse_get(arg);
|
||||
fflush(stdout);
|
||||
|
||||
} else if (!strcmp(buf.buf, "capabilities")) {
|
||||
printf("stateless-connect\n");
|
||||
printf("fetch\n");
|
||||
printf("get\n");
|
||||
printf("option\n");
|
||||
printf("push\n");
|
||||
printf("check-connectivity\n");
|
||||
|
Reference in New Issue
Block a user