{"thread":{"id":"35937","subject":"[PATCH] clone: allow initial sparse checkouts","startedAt":"2014-02-23T02:31:53Z","lastAt":"2014-02-25T00:17:52Z","messageCount":8,"participants":["Robin H. Johnson","Duy Nguyen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"235195","messageId":"1393122713-4308-1-git-send-email-robbat2@gentoo.org","threadId":"35937","inReplyTo":null,"subject":"[PATCH] clone: allow initial sparse checkouts","fromName":"Robin H. Johnson","fromEmail":"robbat2@gentoo.org","sentAt":"2014-02-23T02:31:53Z","receivedAt":"2014-02-23T02:31:53Z","isPatch":true,"sender":{"key":"robbat2@gentoo.org","avatar":"https://avatars.githubusercontent.com/u/373898?v=4"},"body":"Presently if you want to perform a sparse checkout, you must either do a\nfull clone and then recheckout, or do a git init, manually set up\nsparse, and then fetch and checkout.\n\nThis patch implements easily accessible sparse checkouts during clone,\nin the --sparse-checkout option.\n\n$ git clone REPO --sparse-checkout PATH\n\nSigned-off-by: Robin H. Johnson <robbat2@gentoo.org>\n---\n Documentation/git-clone.txt |  5 +++++\n builtin/clone.c             | 24 ++++++++++++++++++++++++\n 2 files changed, 29 insertions(+)\n\ndiff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt\nindex 0363d00..1c21207 100644\n--- a/Documentation/git-clone.txt\n+++ b/Documentation/git-clone.txt\n@@ -14,6 +14,7 @@ SYNOPSIS\n \t  [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]\n \t  [--separate-git-dir <git dir>]\n \t  [--depth <depth>] [--[no-]single-branch]\n+\t  [--sparse-checkout <path>]\n \t  [--recursive | --recurse-submodules] [--] <repository>\n \t  [<directory>]\n \n@@ -209,6 +210,10 @@ objects from the source repository into a pack in the cloned repository.\n \tThe result is Git repository can be separated from working\n \ttree.\n \n+--sparse-checkout <path>::\n+\tPerform the initial checkout as a sparse checkout, checking out only the\n+\tpaths specified by this option. This option may occur multiple times, with\n+\tone path per instance.\n \n <repository>::\n \tThe (possibly remote) repository to clone from.  See the\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 43e772c..1137371 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -48,6 +48,7 @@ static int option_verbosity;\n static int option_progress = -1;\n static struct string_list option_config;\n static struct string_list option_reference;\n+static struct string_list option_sparse_checkout_path;\n \n static int opt_parse_reference(const struct option *opt, const char *arg, int unset)\n {\n@@ -97,6 +98,8 @@ static struct option builtin_clone_options[] = {\n \t\t   N_(\"separate git dir from working tree\")),\n \tOPT_STRING_LIST('c', \"config\", &option_config, N_(\"key=value\"),\n \t\t\tN_(\"set config inside the new repository\")),\n+\tOPT_STRING_LIST(0, \"sparse-checkout\", &option_sparse_checkout_path, N_(\"path\"),\n+\t\t\tN_(\"set path for sparse checkout\")),\n \tOPT_END()\n };\n \n@@ -270,6 +273,24 @@ static void setup_reference(void)\n \tfor_each_string_list(&option_reference, add_one_reference, NULL);\n }\n \n+static void setup_sparse_checkout(void)\n+{\n+\tFILE *info_sparse_checkout_fp;\n+\tstruct string_list_item *item;\n+\tchar *path = git_pathdup(\"info/sparse-checkout\");\n+\tgit_config_set(\"core.sparsecheckout\", \"true\");\n+\tsafe_create_leading_directories(path);\n+\tinfo_sparse_checkout_fp = fopen(path, \"w\");\n+\tif (!info_sparse_checkout_fp)\n+\t\tdie(_(\"unable to create %s\"), path);\n+\tfor_each_string_list_item(item, &option_sparse_checkout_path) {\n+\t\tfprintf(info_sparse_checkout_fp, \"%s\\n\", item->string);\n+\t}\n+\tfclose(info_sparse_checkout_fp);\n+\tadjust_shared_perm(path);\n+\tfree(path);\n+}\n+\n static void copy_alternates(struct strbuf *src, struct strbuf *dst,\n \t\t\t    const char *src_repo)\n {\n@@ -873,6 +894,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \tinit_db(option_template, INIT_DB_QUIET);\n \twrite_config(&option_config);\n \n+\tif(option_sparse_checkout_path.nr)\n+\t\tsetup_sparse_checkout();\n+\n \tgit_config(git_default_config, NULL);\n \n \tif (option_bare) {\n-- \n1.9.0.291.g027825b.dirty\n"},{"id":"235197","messageId":"CACsJy8BKJ4HzXLcajC8cXviD4hboRPOYhWSen7H5Ta=_JuXNjw@mail.gmail.com","threadId":"35937","inReplyTo":"1393122713-4308-1-git-send-email-robbat2@gentoo.org","subject":"Re: [PATCH] clone: allow initial sparse checkouts","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-23T02:52:16Z","receivedAt":"2014-02-23T02:52:16Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Feb 23, 2014 at 9:31 AM, Robin H. Johnson <robbat2@gentoo.org> wrote:\n> Presently if you want to perform a sparse checkout, you must either do a\n> full clone and then recheckout, or do a git init, manually set up\n> sparse, and then fetch and checkout.\n\nI think you could do \"clone -n\" (no checkout), set up sparse, then checkout.\n\n> This patch implements easily accessible sparse checkouts during clone,\n> in the --sparse-checkout option.\n>\n> $ git clone REPO --sparse-checkout PATH\n\nOr take a file as input if there are lots of paths/rules.\n-- \nDuy\n"},{"id":"235198","messageId":"robbat2-20140223T072340-334493350Z@orbis-terrarum.net","threadId":"35937","inReplyTo":"CACsJy8BKJ4HzXLcajC8cXviD4hboRPOYhWSen7H5Ta=_JuXNjw@mail.gmail.com","subject":"Re: [PATCH] clone: allow initial sparse checkouts","fromName":"Robin H. Johnson","fromEmail":"robbat2@gentoo.org","sentAt":"2014-02-23T07:32:07Z","receivedAt":"2014-02-23T07:32:07Z","isPatch":true,"sender":{"key":"robbat2@gentoo.org","avatar":"https://avatars.githubusercontent.com/u/373898?v=4"},"body":"On Sun, Feb 23, 2014 at 09:52:16AM +0700,  Duy Nguyen wrote:\n> On Sun, Feb 23, 2014 at 9:31 AM, Robin H. Johnson <robbat2@gentoo.org> wrote:\n> > Presently if you want to perform a sparse checkout, you must either do a\n> > full clone and then recheckout, or do a git init, manually set up\n> > sparse, and then fetch and checkout.\n> I think you could do \"clone -n\" (no checkout), set up sparse, then checkout.\nYes, I think there are a few more ways, but still would be nice to \n\n> \n> > This patch implements easily accessible sparse checkouts during clone,\n> > in the --sparse-checkout option.\n> >\n> > $ git clone REPO --sparse-checkout PATH\n> Or take a file as input if there are lots of paths/rules.\nHow much demand for taking a file of rules, and opinions of syntax to do\nthat vs specify on the commandline?\n\n--sparse-checkout-from FILE\nvs.\n--sparse-checkout '<PATH'\nor something other prefix character.\n\n-- \nRobin Hugh Johnson\nGentoo Linux: Developer, Infrastructure Lead\nE-Mail     : robbat2@gentoo.org\nGnuPG FP   : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85\n"},{"id":"235199","messageId":"CACsJy8ApmVPAnhQmVAsFyXtV49S+9VULsEYZ7W3x7HMMoVtDzA@mail.gmail.com","threadId":"35937","inReplyTo":"robbat2-20140223T072340-334493350Z@orbis-terrarum.net","subject":"Re: [PATCH] clone: allow initial sparse checkouts","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-23T08:43:47Z","receivedAt":"2014-02-23T08:43:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Feb 23, 2014 at 2:32 PM, Robin H. Johnson <robbat2@gentoo.org> wrote:\n>> > This patch implements easily accessible sparse checkouts during clone,\n>> > in the --sparse-checkout option.\n>> >\n>> > $ git clone REPO --sparse-checkout PATH\n>> Or take a file as input if there are lots of paths/rules.\n> How much demand for taking a file of rules,\n\nI don't know. I guess it depends on each repo's layout. If the layout\nis simple, usually you would need one or two rules so it's ok to type\nagain and again. If it's more complicated and starts using '!' rules,\nit's probably best to save in a file.\n\n> and opinions of syntax to do\n> that vs specify on the commandline?\n>\n> --sparse-checkout-from FILE\n\nI think this one is better. But if you don't see a need for it, we can\nalways delay implementing it until an actual use case comes up.\n\n> vs.\n> --sparse-checkout '<PATH'\n> or something other prefix character.\n-- \nDuy\n"},{"id":"235212","messageId":"robbat2-20140223T204934-225383635Z@orbis-terrarum.net","threadId":"35937","inReplyTo":"CACsJy8ApmVPAnhQmVAsFyXtV49S+9VULsEYZ7W3x7HMMoVtDzA@mail.gmail.com","subject":"Re: [PATCH] clone: allow initial sparse checkouts","fromName":"Robin H. Johnson","fromEmail":"robbat2@gentoo.org","sentAt":"2014-02-23T20:58:07Z","receivedAt":"2014-02-23T20:58:07Z","isPatch":true,"sender":{"key":"robbat2@gentoo.org","avatar":"https://avatars.githubusercontent.com/u/373898?v=4"},"body":"On Sun, Feb 23, 2014 at 03:43:47PM +0700,  Duy Nguyen wrote:\n> On Sun, Feb 23, 2014 at 2:32 PM, Robin H. Johnson <robbat2@gentoo.org> wrote:\n> >> > This patch implements easily accessible sparse checkouts during clone,\n> >> > in the --sparse-checkout option.\n> >> >\n> >> > $ git clone REPO --sparse-checkout PATH\n> >> Or take a file as input if there are lots of paths/rules.\n> > How much demand for taking a file of rules,\n> I don't know. I guess it depends on each repo's layout. If the layout\n> is simple, usually you would need one or two rules so it's ok to type\n> again and again. If it's more complicated and starts using '!' rules,\n> it's probably best to save in a file.\n> \n> > and opinions of syntax to do\n> > that vs specify on the commandline?\n> >\n> > --sparse-checkout-from FILE\n> \n> I think this one is better. But if you don't see a need for it, we can\n> always delay implementing it until an actual use case comes up.\nI think I'd prefer to delay that part then.\nWhat I'm concerned about if we do have it, is what ordering semantics\nthere should be, eg for something like:\n--sparse-checkout '!X' --sparse-checkout-from F --sparse-checkout Y\n\nShould that be [!X, *F, Y], or [*F, !X, Y], or something else?\nWould the option parser need to be modified to handle this?\nOr do we just make them mutually exclusive?\n\nThe only other clean alternative would be implementing ONLY\n--sparse-checkout-from, and letting uses use fds creatively:\n--sparse-checkout-from <(echo X; echo Y)\nBut the msysgit crowd would probably mumble complaints under their\nbreath at me.\n\n-- \nRobin Hugh Johnson\nGentoo Linux: Developer, Infrastructure Lead\nE-Mail     : robbat2@gentoo.org\nGnuPG FP   : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85\n"},{"id":"235271","messageId":"xmqqzjlg9zdn.fsf@gitster.dls.corp.google.com","threadId":"35937","inReplyTo":"robbat2-20140223T204934-225383635Z@orbis-terrarum.net","subject":"Re: [PATCH] clone: allow initial sparse checkouts","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-02-24T17:47:16Z","receivedAt":"2014-02-24T17:47:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Robin H. Johnson\" <robbat2@gentoo.org> writes:\n\n> The only other clean alternative would be implementing ONLY\n> --sparse-checkout-from, and letting uses use fds creatively:\n> --sparse-checkout-from <(echo X; echo Y)\n\nNot all POSIX shells have such an abomination that is process\nsubstitution.  You can easily work it around by adopting the usual\nconvention to use \"-\" to read from the standasrd input, though.\n\n\t(echo X; echo Y) | cmd --sparse-checkout-from -\n"},{"id":"235302","messageId":"robbat2-20140224T214733-300290109Z@orbis-terrarum.net","threadId":"35937","inReplyTo":"xmqqzjlg9zdn.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] clone: allow initial sparse checkouts","fromName":"Robin H. Johnson","fromEmail":"robbat2@gentoo.org","sentAt":"2014-02-24T21:48:01Z","receivedAt":"2014-02-24T21:48:01Z","isPatch":true,"sender":{"key":"robbat2@gentoo.org","avatar":"https://avatars.githubusercontent.com/u/373898?v=4"},"body":"On Mon, Feb 24, 2014 at 09:47:16AM -0800,  Junio C Hamano wrote:\n> \"Robin H. Johnson\" <robbat2@gentoo.org> writes:\n> > The only other clean alternative would be implementing ONLY\n> > --sparse-checkout-from, and letting uses use fds creatively:\n> > --sparse-checkout-from <(echo X; echo Y)\n> Not all POSIX shells have such an abomination that is process\n> substitution.  You can easily work it around by adopting the usual\n> convention to use \"-\" to read from the standasrd input, though.\n> \n> \t(echo X; echo Y) | cmd --sparse-checkout-from -\nIs that a vote that you'd like to see a --sparse-checkout-from variant\nof my patch?\n\n-- \nRobin Hugh Johnson\nGentoo Linux: Developer, Infrastructure Lead\nE-Mail     : robbat2@gentoo.org\nGnuPG FP   : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85\n"},{"id":"235308","messageId":"xmqqmwhg6o5r.fsf@gitster.dls.corp.google.com","threadId":"35937","inReplyTo":"robbat2-20140224T214733-300290109Z@orbis-terrarum.net","subject":"Re: [PATCH] clone: allow initial sparse checkouts","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-02-25T00:17:52Z","receivedAt":"2014-02-25T00:17:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Robin H. Johnson\" <robbat2@gentoo.org> writes:\n\n> On Mon, Feb 24, 2014 at 09:47:16AM -0800,  Junio C Hamano wrote:\n>> \"Robin H. Johnson\" <robbat2@gentoo.org> writes:\n>> > The only other clean alternative would be implementing ONLY\n>> > --sparse-checkout-from, and letting uses use fds creatively:\n>> > --sparse-checkout-from <(echo X; echo Y)\n>> Not all POSIX shells have such an abomination that is process\n>> substitution.  You can easily work it around by adopting the usual\n>> convention to use \"-\" to read from the standasrd input, though.\n>> \n>> \t(echo X; echo Y) | cmd --sparse-checkout-from -\n> Is that a vote that you'd like to see a --sparse-checkout-from variant\n> of my patch?\n\nHonestly, I do not particularly care too much about this feature,\nregardless of the interface [*1*].\n\nIt is just a vote that says \"if --something-from form is going to be\nimplemented, it should be able to read from the standard input with\n'-', unless there is a compelling reason not to do so\".\n\n\n[Footnote]\n\n*1* In the longer term, I think sparse checkout is broken as a\nconcept and I view this \"use sparse checkout from the get-go\" merely\na stop-gap measure to make the band-aid a bit less painful to use.\nWhat you really want is a narrow clone, which is conceptually cleaner\nbut a lot harder implentation-wise.\n\nNot that keeping a band-aid usable longer is necessarily bad in the\nreal world, though---so even I said *I*'m not interested, that is\ndifferent from saying I'm not taking a patch on this topic.\n"}]}