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

Subsystems: the rest

STALE3707d

16 messages, 7 authors, 2016-06-15 · open the first message on its own page

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

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:45:00

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 builtin-clone.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
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

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

From: Jeff King <hidden>
Date: 2016-06-15 22:45:00

On Wed, Jul 23, 2008 at 09:57:18PM +0700, Nguyễn Thái Ngọc 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.

-Peff

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

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:45:00

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

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

From: Jeff King <hidden>
Date: 2016-06-15 22:45:00

On Thu, Jul 24, 2008 at 06:41:03PM +0100, Johannes Schindelin wrote:
quoted
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

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

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:45:00

On 7/25/08, Johannes Schindelin [off-list ref] wrote:
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

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

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:45:00

On 7/25/08, Jeff King [off-list ref] wrote:
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

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

From: Petr Baudis <hidden>
Date: 2016-06-15 22:45:00

  Hi,

On Thu, Jul 24, 2008 at 06:41:03PM +0100, Johannes Schindelin wrote:
On Thu, 24 Jul 2008, Jeff King wrote:
quoted
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

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

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:45:00

On Thu, Jul 24, 2008 at 8:53 PM, Petr Baudis [off-list ref] 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

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

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:45:01

Hi,

On Thu, 24 Jul 2008, Jeff King wrote:
On Thu, Jul 24, 2008 at 06:41:03PM +0100, Johannes Schindelin wrote:
quoted
quoted
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

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

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:45:01

Hi,

On Thu, 24 Jul 2008, Sverre Rabbelier wrote:
On Thu, Jul 24, 2008 at 8:53 PM, Petr Baudis [off-list ref] wrote:
quoted
 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.
quoted
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

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

From: Petr Baudis <hidden>
Date: 2016-06-15 22:45:01

  Hi,

On Fri, Jul 25, 2008 at 02:12:31AM +0200, Johannes Schindelin wrote:
On Thu, 24 Jul 2008, Sverre Rabbelier wrote:
quoted
On Thu, Jul 24, 2008 at 8:53 PM, Petr Baudis [off-list ref] wrote:
quoted
 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

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

From: James Pickens <hidden>
Date: 2016-06-15 22:45:01

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

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

From: Jeff King <hidden>
Date: 2016-06-15 22:45:01

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

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

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:45:02

On Fri, Jul 25, 2008 at 02:12, Johannes Schindelin
[off-list ref] wrote:
On Thu, 24 Jul 2008, Sverre Rabbelier wrote:
quoted
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).
quoted
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

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:02

Jeff King [off-list ref] writes:
On Thu, Jul 24, 2008 at 06:41:03PM +0100, Johannes Schindelin wrote:
quoted
quoted
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.

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

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:45:02

On Fri, Jul 25, 2008 at 10:47, Junio C Hamano [off-list ref] 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help