threads / patch / 14628

patch, 12 partsgit-clone: support --path to do sparse clone

Subject: [PATCH 08/12] git-clone: support --path to do sparse clone

## tl;dr

16 messages between Jul 23, 2008 and Jul 25, 2008. Diffs are folded; open one to read it.

replies: 15people: 7as markdown or json

Nguyễn Thái Ngọc Duy· Jul 23, 2008, 14:57 UTC · lore
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-clone.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
Show changes to builtin-clone.c +13 −0
diff --git a/builtin-clone.c b/builtin-clone.c
index 3522245..229f2e2 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -36,6 +36,7 @@ static const char * const builtin_clone_usage[] = {
 static int option_quiet, option_no_checkout, option_bare;
 static int option_local, option_no_hardlinks, option_shared;
 static char *option_template, *option_reference, *option_depth;
+static char *option_sparse_prefix;
 static char *option_origin = NULL;
 static char *option_upload_pack = "git-upload-pack";
 
@@ -43,6 +44,8 @@ static struct option builtin_clone_options[] = {
 	OPT__QUIET(&option_quiet),
 	OPT_BOOLEAN('n', "no-checkout", &option_no_checkout,
 		    "don't create a checkout"),
+	OPT_STRING(0, "path", &option_sparse_prefix, "prefixes",
+		    "limit checkout to specified paths (sparse checkout)"),
 	OPT_BOOLEAN(0, "bare", &option_bare, "create a bare repository"),
 	OPT_BOOLEAN(0, "naked", &option_bare, "create a bare repository"),
 	OPT_BOOLEAN('l', "local", &option_local,
@@ -364,9 +367,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 			die("--bare and --origin %s options are incompatible.",
 			    option_origin);
 		option_no_checkout = 1;
+		if (option_sparse_prefix)
+			die("--bare and --path options are incompatible.");
 		use_separate_remote = 0;
 	}
 
+	if (option_no_checkout && option_sparse_prefix)
+		die("--no-checkout and --path options are incompatible.");
+
 	if (!option_origin)
 		option_origin = "origin";
 
@@ -549,6 +557,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		/* We need to be in the new work tree for the checkout */
 		setup_work_tree();
 
+		if (option_sparse_prefix) {
+			git_config_set("core.sparsecheckout", option_sparse_prefix);
+			set_sparse_prefix(option_sparse_prefix);
+		}
+
 		fd = hold_locked_index(lock_file, 1);
 
 		memset(&opts, 0, sizeof opts);
-- 
1.5.5.GIT
Jeff King· Jul 24, 2008, 17:19 UTC · re: Nguyễn Thái Ngọc Duy · lore

Re: [PATCH 08/12] git-clone: support --path to do sparse clone

On Wed, Jul 23, 2008 at 09:57:18PM +0700, Nguyễn Thái Ngọc Duy wrote:
Show 5 quoted lines
> +		if (option_sparse_prefix) {
> +			git_config_set("core.sparsecheckout", option_sparse_prefix);
> +			set_sparse_prefix(option_sparse_prefix);
> +		}
> +

As a user, I would expect "sparse clone" to also be sparse on the fetching. That is, to not even bother fetching tree objects that we are not going to check out. But that is a whole other can of worms from local sparseness, so I think it is worth saving for a different series.

So instead I would suggest that this be mentioned in the documentation for --path, but there doesn't seem to be any.

-Peff
Johannes Schindelin· Jul 24, 2008, 17:41 UTC · re: Jeff King · lore

sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

Hi,
On Thu, 24 Jul 2008, Jeff King wrote:
> As a user, I would expect "sparse clone" to also be sparse on the 
> fetching. That is, to not even bother fetching tree objects that we are 
> not going to check out. But that is a whole other can of worms from 
> local sparseness, so I think it is worth saving for a different series.

I think this is not even worth of a series. Sure, it would have benefits for those who want sparse checkouts. But it comes for a high price on everyone else:

- security issues (you'd need to open the git protocol to give you 
  something else than a ref, _including_ refs that were deleted)
- performance issues (the server would have to do a lot more, faking 
  commits, or in the alternative serving a gazillion more sessions if the 
  client does the reconstruction)
... and I am sure there are tons more issues.

Ciao, Dscho

Jeff King· Jul 24, 2008, 18:28 UTC · re: Johannes Schindelin · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

On Thu, Jul 24, 2008 at 06:41:03PM +0100, Johannes Schindelin wrote:
Show 8 quoted lines
> > As a user, I would expect "sparse clone" to also be sparse on the 
> > fetching. That is, to not even bother fetching tree objects that we are 
> > not going to check out. But that is a whole other can of worms from 
> > local sparseness, so I think it is worth saving for a different series.
> 
> I think this is not even worth of a series.  Sure, it would have benefits 
> for those who want sparse checkouts.  But it comes for a high price on 
> everyone else:

I agree there are a lot of issues. I am just thinking of the person who said they had a >100G repository. But I am also not volunteering to do it, so I will let somebody who really cares about it try to defend the idea.

-Peff
Johannes Schindelin· Jul 25, 2008, 00:09 UTC · re: Jeff King · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

Hi,
On Thu, 24 Jul 2008, Jeff King wrote:
Show 16 quoted lines
> On Thu, Jul 24, 2008 at 06:41:03PM +0100, Johannes Schindelin wrote:
> 
> > > As a user, I would expect "sparse clone" to also be sparse on the 
> > > fetching. That is, to not even bother fetching tree objects that we 
> > > are not going to check out. But that is a whole other can of worms 
> > > from local sparseness, so I think it is worth saving for a different 
> > > series.
> > 
> > I think this is not even worth of a series.  Sure, it would have 
> > benefits for those who want sparse checkouts.  But it comes for a high 
> > price on everyone else:
> 
> I agree there are a lot of issues. I am just thinking of the person who 
> said they had a >100G repository. But I am also not volunteering to do 
> it, so I will let somebody who really cares about it try to defend the 
> idea.

I never said that there were no benefits. I argued that there are too many _downsides_ to those who _don't_ benefit.

Ciao, Dscho

James Pickens· Jul 25, 2008, 00:46 UTC · re: Jeff King · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

Jeff King <peff <at> peff.net> writes:
> I agree there are a lot of issues. I am just thinking of the person who
> said they had a >100G repository. But I am also not volunteering to do
> it, so I will let somebody who really cares about it try to defend the
> idea.

If you're referring to me (I mentioned a 144G CVS repo), then let me clarify a couple of things:

1.  Probably more than 50% of the 144G is crud that should never have
been checked in, but I have some undisciplined coworkers who like to
blindly check in everything in their work trees.  If/when we moved to
git, I would get rid of all that crud.  I'm also thinking about throwing
out a lot of the history, since those same undisciplined coworkers like
to use empty and/or useless log messages, so a lot of the history isn't
very valuable anyways.
2.  Git of course will store the remaining ~70G much more efficiently
than CVS.  I think git will be especially better than CVS for this repo,
because it contains many instances of the same file(s) being checked in
in multiple directories.

I expect the git repo size to be less than 7G. In addition, all our work is done on site on nfs, so we can use clone -s to avoid copying the whole 7G.

To sum it up, sparse cloning would not be important to me.
James
Jeff King· Jul 25, 2008, 00:49 UTC · re: James Pickens · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path?to do sparse clone

On Fri, Jul 25, 2008 at 12:46:52AM +0000, James Pickens wrote:
> If you're referring to me (I mentioned a 144G CVS repo), then let me
> clarify a couple of things:
> [...]
> To sum it up, sparse cloning would not be important to me.
I was referring to you, so thanks for the clarification.
-Peff
Junio C Hamano· Jul 25, 2008, 08:47 UTC · re: Jeff King · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

Jeff King <peff@peff.net> writes:
Show 15 quoted lines
> On Thu, Jul 24, 2008 at 06:41:03PM +0100, Johannes Schindelin wrote:
>
>> > As a user, I would expect "sparse clone" to also be sparse on the 
>> > fetching. That is, to not even bother fetching tree objects that we are 
>> > not going to check out. But that is a whole other can of worms from 
>> > local sparseness, so I think it is worth saving for a different series.
>> 
>> I think this is not even worth of a series.  Sure, it would have benefits 
>> for those who want sparse checkouts.  But it comes for a high price on 
>> everyone else:
>
> I agree there are a lot of issues. I am just thinking of the person who
> said they had a >100G repository. But I am also not volunteering to do
> it, so I will let somebody who really cares about it try to defend the
> idea.

I think sparse fetch is a lot worse than grafts and shallow clones which are already bad. These are all ways to introduce local inconsistency at the object level and pretend everything is Ok, but the latter two do so only at commit boundary and it is somewhat more manageable (but we still do not handle it very well). With sparse fetch, you cannot even guarantee the integrity of individual commits with subtrees here and there missing.

I do think shallow checkout that says "I'll have the whole tree in the index but the work tree will have only these paths checked out" makes sense. You do not need a fully populated work tree to create commits or merges -- the only absolute minimum you need is a fully populated index.

In that sense, I think "protect index entries outside of these paths" (I remember that the first round of this series was done around that notion) is a wrong mentality to handle this. We should think of this as more like "you still populate the index with the whole tree, and you are free to update them in any way you want, but we do not touch work tree outside these areas".

This has a few ramifications:
 - If the user can somehow check out a path outside the "sparse" area, it
   is perfectly fine for the user to edit and "git add" it.  Such a method
   to check out a path outside the "sparse" area is a way to widen the
   "sparse" area the user originally set up;
 - When the user runs "merge", and it needs to present the user a working
   tree file because of conflicts at the file level, the user has to agree
   to widen the "sparse" area before being able to do so.  One way to do
   this is to refuse and fail the merge (and then the user needs to do
   that "unspecified way" of widening the "sparse" area first).  Another
   way would be to automatically widen the "sparse" area to include such
   conflicting paths.
 - And you would want to narrow it down after you do such a widening.

For many projects that has src/ and doc/ (git.git being one of them), it is perfectly valid for a code person and a doc person to work in tandem. In such a project, after the code person makes changes in her sparsely checked out repository and making changes only to the src/ area and pushes the results out, the doc person would run "git pull && git log -p ORIG_HEAD" and updates the documentation in his sparsely checked out repository that has only doc/ area. The two parts are tied together and they advance more or less in sync. I think sparse checkout would be a useful feature to help such a configuration.

Having said that, I however think that this can easily be misused as a CVS style "one CVSROOT houses millions of totally unrelated projects" layout. In CVS, the layout is perfectly fine because the system does not track changes at anything higher than the level of individual files, but when you naïvely map the layout to a system with tree-wide atomic commits, such as git, it will defeat the whole point of using such a system. The pace these millions of unrelated projects advance do not have any relationship with each other, but by tying them together in the same top-level tree, the layout is introducing an unnecessary ordering between their commits.

Sverre Rabbelier· Jul 25, 2008, 08:54 UTC · re: Junio C Hamano · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

On Fri, Jul 25, 2008 at 10:47, Junio C Hamano <gitster@pobox.com> wrote:
> For many projects that has src/ and doc/ (git.git being one of them), it

We are? That's great, that'd mean I can actually do a 'ls' in the git.git root! Oh wait... $ ls | wc -l 693

-- 
Cheers,

Sverre Rabbelier
Nguyen Thai Ngoc Duy· Jul 24, 2008, 18:44 UTC · re: Johannes Schindelin · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

On 7/25/08, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 21 quoted lines
> Hi,
>
>  On Thu, 24 Jul 2008, Jeff King wrote:
>
>  > As a user, I would expect "sparse clone" to also be sparse on the
>  > fetching. That is, to not even bother fetching tree objects that we are
>  > not going to check out. But that is a whole other can of worms from
>  > local sparseness, so I think it is worth saving for a different series.
>
>  I think this is not even worth of a series.  Sure, it would have benefits
>  for those who want sparse checkouts.  But it comes for a high price on
>  everyone else:
>
>  - security issues (you'd need to open the git protocol to give you
>   something else than a ref, _including_ refs that were deleted)
>
>  - performance issues (the server would have to do a lot more, faking
>   commits, or in the alternative serving a gazillion more sessions if the
>   client does the reconstruction)
>
>  ... and I am sure there are tons more issues.
Widen checkout won't work and probably more.
-- 
Duy
Petr Baudis· Jul 24, 2008, 18:53 UTC · re: Johannes Schindelin · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

  Hi,
On Thu, Jul 24, 2008 at 06:41:03PM +0100, Johannes Schindelin wrote:
Show 17 quoted lines
> On Thu, 24 Jul 2008, Jeff King wrote:
> 
> > As a user, I would expect "sparse clone" to also be sparse on the 
> > fetching. That is, to not even bother fetching tree objects that we are 
> > not going to check out. But that is a whole other can of worms from 
> > local sparseness, so I think it is worth saving for a different series.
> 
> I think this is not even worth of a series.  Sure, it would have benefits 
> for those who want sparse checkouts.  But it comes for a high price on 
> everyone else:
> 
> - security issues (you'd need to open the git protocol to give you 
>   something else than a ref, _including_ refs that were deleted)
> 
> - performance issues (the server would have to do a lot more, faking 
>   commits, or in the alternative serving a gazillion more sessions if the 
>   client does the reconstruction)
  I don't follow how these two issues arise, if the server will do the
pruning for you. It will just skip entering some tree objects when doing
object traversal; why opening the git protocol or faking commits? This
would be a simple extra capability in the protocol.
  One question is what to do with delta chains including unwanted
objects, but I think that given the objects' associativity for delta
chains, this shouldn't be huge practical issues and it could be
affordable in principle to include even unwanted objects.
> ... and I am sure there are tons more issues.
  I do agree on this. :-)
-- 
				Petr "Pasky" Baudis
As in certain cults it is possible to kill a process if you know
its true name.  -- Ken Thompson and Dennis M. Ritchie
Sverre Rabbelier· Jul 24, 2008, 19:01 UTC · re: Petr Baudis · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

On Thu, Jul 24, 2008 at 8:53 PM, Petr Baudis <pasky@suse.cz> wrote:
>  I don't follow how these two issues arise, if the server will do the
> pruning for you. It will just skip entering some tree objects when doing
> object traversal; why opening the git protocol or faking commits? This
> would be a simple extra capability in the protocol.

Wouldn't that be as simple as passing a pathspec to git-rev-list? Not a lot of overhead there I reckon.

> One question is what to do with delta chains including unwanted
> objects, but I think that given the objects' associativity for delta
> chains, this shouldn't be huge practical issues and it could be
> affordable in principle to include even unwanted objects.

Just keep them? What we're doing here is trying to optimize in the case that someone has a sparse checkout, nothing bad will happen if they get too many info surely? (Save for them not getting as much improvement as would have been possible would the pack have been created differently.)

-- 
Cheers,

Sverre Rabbelier
Johannes Schindelin· Jul 25, 2008, 00:12 UTC · re: Sverre Rabbelier · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

Hi,
On Thu, 24 Jul 2008, Sverre Rabbelier wrote:
Show 8 quoted lines
> On Thu, Jul 24, 2008 at 8:53 PM, Petr Baudis <pasky@suse.cz> wrote:
> >  I don't follow how these two issues arise, if the server will do the 
> > pruning for you. It will just skip entering some tree objects when 
> > doing object traversal; why opening the git protocol or faking 
> > commits? This would be a simple extra capability in the protocol.
> 
> Wouldn't that be as simple as passing a pathspec to git-rev-list? Not a 
> lot of overhead there I reckon.

So the server would _not_ have to deflate the objects to inspect them? I thought you knew more about Git's object database.

Show 6 quoted lines
> > One question is what to do with delta chains including unwanted 
> > objects, but I think that given the objects' associativity for delta 
> > chains, this shouldn't be huge practical issues and it could be 
> > affordable in principle to include even unwanted objects.
> 
> Just keep them?

You'd still have to inspect the objects, which is way more work than the current code has to do. Remember: in the optimal case, upload-pack does not more than just serve the existing deltas/base objects.

Ciao, Dscho

Petr Baudis· Jul 25, 2008, 00:42 UTC · re: Johannes Schindelin · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

  Hi,
On Fri, Jul 25, 2008 at 02:12:31AM +0200, Johannes Schindelin wrote:
Show 13 quoted lines
> On Thu, 24 Jul 2008, Sverre Rabbelier wrote:
> 
> > On Thu, Jul 24, 2008 at 8:53 PM, Petr Baudis <pasky@suse.cz> wrote:
> > >  I don't follow how these two issues arise, if the server will do the 
> > > pruning for you. It will just skip entering some tree objects when 
> > > doing object traversal; why opening the git protocol or faking 
> > > commits? This would be a simple extra capability in the protocol.
> > 
> > Wouldn't that be as simple as passing a pathspec to git-rev-list? Not a 
> > lot of overhead there I reckon.
> 
> So the server would _not_ have to deflate the objects to inspect them?  I 
> thought you knew more about Git's object database.
..snip..
> You'd still have to inspect the objects, which is way more work than the 
> current code has to do.  Remember: in the optimal case, upload-pack does 
> not more than just serve the existing deltas/base objects.
  then right now, exactly how does the server decide that the blob
7a7ff130 should be served along git.git HEAD? I still see upload-pack.c
calling traverse_commit_list() that does process_tree() on every tree,
etc. But the code is not straightforward, maybe I'm missing some
shortcut?
-- 
				Petr "Pasky" Baudis
As in certain cults it is possible to kill a process if you know
its true name.  -- Ken Thompson and Dennis M. Ritchie
Sverre Rabbelier· Jul 25, 2008, 08:14 UTC · re: Johannes Schindelin · lore

Re: sparse fetch, was Re: [PATCH 08/12] git-clone: support --path to do sparse clone

On Fri, Jul 25, 2008 at 02:12, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:

Show 6 quoted lines
> On Thu, 24 Jul 2008, Sverre Rabbelier wrote:
>> Wouldn't that be as simple as passing a pathspec to git-rev-list? Not a
>> lot of overhead there I reckon.
>
> So the server would _not_ have to deflate the objects to inspect them?  I
> thought you knew more about Git's object database.

Nope, I did not know this. I thought that the server already had to do all that to decide what to send, since not every request asks for the same pack (someone might not have updated in 2 month, or someone might might be up to date, or anything in between).

Show 5 quoted lines
>> Just keep them?
>
> You'd still have to inspect the objects, which is way more work than the
> current code has to do.  Remember: in the optimal case, upload-pack does
> not more than just serve the existing deltas/base objects.
Ah, I can see how that would produce overhead then.
-- 
Cheers,

Sverre Rabbelier
Nguyen Thai Ngoc Duy· Jul 24, 2008, 18:47 UTC · re: Jeff King · lore

Re: [PATCH 08/12] git-clone: support --path to do sparse clone

On 7/25/08, Jeff King <peff@peff.net> wrote:
Show 16 quoted lines
> On Wed, Jul 23, 2008 at 09:57:18PM +0700, Nguyen Thai Ngoc Duy wrote:
>
>  > +             if (option_sparse_prefix) {
>  > +                     git_config_set("core.sparsecheckout", option_sparse_prefix);
>  > +                     set_sparse_prefix(option_sparse_prefix);
>  > +             }
>  > +
>
>
> As a user, I would expect "sparse clone" to also be sparse on the
>  fetching. That is, to not even bother fetching tree objects that we are
>  not going to check out. But that is a whole other can of worms from
>  local sparseness, so I think it is worth saving for a different series.
>
>  So instead I would suggest that this be mentioned in the documentation
>  for --path, but there doesn't seem to be any.
Thanks. Will mention it when I write documentation for this.
-- 
Duy

← back to recent threads