summaryrefslogtreecommitdiff
path: root/builtin/clone.c
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2022-08-09 13:11:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-08-10 21:07:37 (GMT)
commit55568919616429fbc209880cf189a3adaceb6093 (patch)
treead443684968b415f4be585093bbc320e98671c5e /builtin/clone.c
parent53a50892be20a91fb0dcf572a641ce2a79af1a38 (diff)
downloadgit-55568919616429fbc209880cf189a3adaceb6093.zip
git-55568919616429fbc209880cf189a3adaceb6093.tar.gz
git-55568919616429fbc209880cf189a3adaceb6093.tar.bz2
clone: add --bundle-uri option
Cloning a remote repository is one of the most expensive operations in Git. The server can spend a lot of CPU time generating a pack-file for the client's request. The amount of data can clog the network for a long time, and the Git protocol is not resumable. For users with poor network connections or are located far away from the origin server, this can be especially painful. Add a new '--bundle-uri' option to 'git clone' to bootstrap a clone from a bundle. If the user is aware of a bundle server, then they can tell Git to bootstrap the new repository with these bundles before fetching the remaining objects from the origin server. 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 'builtin/clone.c')
-rw-r--r--builtin/clone.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index c4ff464..4224d56 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -34,6 +34,7 @@
#include "list-objects-filter-options.h"
#include "hook.h"
#include "bundle.h"
+#include "bundle-uri.h"
/*
* Overall FIXMEs:
@@ -77,6 +78,7 @@ static int option_filter_submodules = -1; /* unspecified */
static int config_filter_submodules = -1; /* unspecified */
static struct string_list server_options = STRING_LIST_INIT_NODUP;
static int option_remote_submodules;
+static const char *bundle_uri;
static int recurse_submodules_cb(const struct option *opt,
const char *arg, int unset)
@@ -160,6 +162,8 @@ static struct option builtin_clone_options[] = {
N_("any cloned submodules will use their remote-tracking branch")),
OPT_BOOL(0, "sparse", &option_sparse_checkout,
N_("initialize sparse-checkout file to include only files at root")),
+ OPT_STRING(0, "bundle-uri", &bundle_uri,
+ N_("uri"), N_("a URI for downloading bundles before fetching from origin remote")),
OPT_END()
};
@@ -1232,6 +1236,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (transport->smart_options && !deepen && !filter_options.choice)
transport->smart_options->check_self_contained_and_connected = 1;
+ /*
+ * Before fetching from the remote, download and install bundle
+ * data from the --bundle-uri option.
+ */
+ if (bundle_uri) {
+ /* At this point, we need the_repository to match the cloned repo. */
+ repo_init(the_repository, git_dir, work_tree);
+ if (fetch_bundle_uri(the_repository, bundle_uri))
+ warning(_("failed to fetch objects from bundle URI '%s'"),
+ bundle_uri);
+ }
strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD");
refspec_ref_prefixes(&remote->fetch,