Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2022-08-09 16:11:42 +0300
committerJunio C Hamano <gitster@pobox.com>2022-08-11 00:07:37 +0300
commit59c1752ab6768cb9c380f0a7c9d06af79d183f67 (patch)
tree160d8560e87bd9d0426b9f45155340b8e6b675b9 /bundle-uri.c
parent55568919616429fbc209880cf189a3adaceb6093 (diff)
bundle-uri: add support for http(s):// and file://
The previous change created the 'git clone --bundle-uri=<uri>' option. Currently, <uri> must be a filename. Update copy_uri_to_file() to first inspect the URI for an HTTP(S) prefix and use git-remote-https as the way to download the data at that URI. Otherwise, check to see if file:// is present and modify the prefix accordingly. Reviewed-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'bundle-uri.c')
-rw-r--r--bundle-uri.c70
1 files changed, 67 insertions, 3 deletions
diff --git a/bundle-uri.c b/bundle-uri.c
index b35babc36a..4a8cc74ed0 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -23,10 +23,74 @@ static int find_temp_filename(struct strbuf *name)
return 0;
}
-static int copy_uri_to_file(const char *file, const char *uri)
+static int download_https_uri_to_file(const char *file, const char *uri)
{
- /* File-based URIs only for now. */
- return copy_file(file, uri, 0);
+ int result = 0;
+ struct child_process cp = CHILD_PROCESS_INIT;
+ FILE *child_in = NULL, *child_out = NULL;
+ struct strbuf line = STRBUF_INIT;
+ int found_get = 0;
+
+ strvec_pushl(&cp.args, "git-remote-https", uri, NULL);
+ cp.in = -1;
+ cp.out = -1;
+
+ if (start_command(&cp))
+ return 1;
+
+ child_in = fdopen(cp.in, "w");
+ if (!child_in) {
+ result = 1;
+ goto cleanup;
+ }
+
+ child_out = fdopen(cp.out, "r");
+ if (!child_out) {
+ result = 1;
+ goto cleanup;
+ }
+
+ fprintf(child_in, "capabilities\n");
+ fflush(child_in);
+
+ while (!strbuf_getline(&line, child_out)) {
+ if (!line.len)
+ break;
+ if (!strcmp(line.buf, "get"))
+ found_get = 1;
+ }
+ strbuf_release(&line);
+
+ if (!found_get) {
+ result = error(_("insufficient capabilities"));
+ goto cleanup;
+ }
+
+ fprintf(child_in, "get %s %s\n\n", uri, file);
+
+cleanup:
+ if (child_in)
+ fclose(child_in);
+ if (finish_command(&cp))
+ return 1;
+ if (child_out)
+ fclose(child_out);
+ return result;
+}
+
+static int copy_uri_to_file(const char *filename, const char *uri)
+{
+ const char *out;
+
+ if (starts_with(uri, "https:") ||
+ starts_with(uri, "http:"))
+ return download_https_uri_to_file(filename, uri);
+
+ if (skip_prefix(uri, "file://", &out))
+ uri = out;
+
+ /* Copy as a file */
+ return copy_file(filename, uri, 0);
}
static int unbundle_from_file(struct repository *r, const char *file)