git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Robin H. Johnson" <robbat2@gentoo.org>
To: git@vger.kernel.org
Cc: "Robin H. Johnson" <robbat2@gentoo.org>
Subject: [PATCH] clone: allow initial sparse checkouts
Date: Sat, 22 Feb 2014 18:31:53 -0800	[thread overview]
Message-ID: <1393122713-4308-1-git-send-email-robbat2@gentoo.org> (raw)

Presently if you want to perform a sparse checkout, you must either do a
full clone and then recheckout, or do a git init, manually set up
sparse, and then fetch and checkout.

This patch implements easily accessible sparse checkouts during clone,
in the --sparse-checkout option.

$ git clone REPO --sparse-checkout PATH

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
---
 Documentation/git-clone.txt |  5 +++++
 builtin/clone.c             | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 0363d00..1c21207 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -14,6 +14,7 @@ SYNOPSIS
 	  [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
 	  [--separate-git-dir <git dir>]
 	  [--depth <depth>] [--[no-]single-branch]
+	  [--sparse-checkout <path>]
 	  [--recursive | --recurse-submodules] [--] <repository>
 	  [<directory>]
 
@@ -209,6 +210,10 @@ objects from the source repository into a pack in the cloned repository.
 	The result is Git repository can be separated from working
 	tree.
 
+--sparse-checkout <path>::
+	Perform the initial checkout as a sparse checkout, checking out only the
+	paths specified by this option. This option may occur multiple times, with
+	one path per instance.
 
 <repository>::
 	The (possibly remote) repository to clone from.  See the
diff --git a/builtin/clone.c b/builtin/clone.c
index 43e772c..1137371 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -48,6 +48,7 @@ static int option_verbosity;
 static int option_progress = -1;
 static struct string_list option_config;
 static struct string_list option_reference;
+static struct string_list option_sparse_checkout_path;
 
 static int opt_parse_reference(const struct option *opt, const char *arg, int unset)
 {
@@ -97,6 +98,8 @@ static struct option builtin_clone_options[] = {
 		   N_("separate git dir from working tree")),
 	OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
 			N_("set config inside the new repository")),
+	OPT_STRING_LIST(0, "sparse-checkout", &option_sparse_checkout_path, N_("path"),
+			N_("set path for sparse checkout")),
 	OPT_END()
 };
 
@@ -270,6 +273,24 @@ static void setup_reference(void)
 	for_each_string_list(&option_reference, add_one_reference, NULL);
 }
 
+static void setup_sparse_checkout(void)
+{
+	FILE *info_sparse_checkout_fp;
+	struct string_list_item *item;
+	char *path = git_pathdup("info/sparse-checkout");
+	git_config_set("core.sparsecheckout", "true");
+	safe_create_leading_directories(path);
+	info_sparse_checkout_fp = fopen(path, "w");
+	if (!info_sparse_checkout_fp)
+		die(_("unable to create %s"), path);
+	for_each_string_list_item(item, &option_sparse_checkout_path) {
+		fprintf(info_sparse_checkout_fp, "%s\n", item->string);
+	}
+	fclose(info_sparse_checkout_fp);
+	adjust_shared_perm(path);
+	free(path);
+}
+
 static void copy_alternates(struct strbuf *src, struct strbuf *dst,
 			    const char *src_repo)
 {
@@ -873,6 +894,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	init_db(option_template, INIT_DB_QUIET);
 	write_config(&option_config);
 
+	if(option_sparse_checkout_path.nr)
+		setup_sparse_checkout();
+
 	git_config(git_default_config, NULL);
 
 	if (option_bare) {
-- 
1.9.0.291.g027825b.dirty

             reply	other threads:[~2014-02-23  2:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-23  2:31 Robin H. Johnson [this message]
2014-02-23  2:52 ` [PATCH] clone: allow initial sparse checkouts Duy Nguyen
2014-02-23  7:32   ` Robin H. Johnson
2014-02-23  8:43     ` Duy Nguyen
2014-02-23 20:58       ` Robin H. Johnson
2014-02-24 17:47         ` Junio C Hamano
2014-02-24 21:48           ` Robin H. Johnson
2014-02-25  0:17             ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393122713-4308-1-git-send-email-robbat2@gentoo.org \
    --to=robbat2@gentoo.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).