threads / discuss / 18025

Does cloning a shallow repo require special setting in the cloned one?

Subject: Does cloning a shallow repo require special setting in the cloned one?

## tl;dr

8 messages between Feb 26, 2009 and Feb 27, 2009.

replies: 7people: 5as markdown or json

roylee17· Feb 26, 2009, 03:49 UTC · lore
Hi,
I have a question about cloning shallow repo.

$ git clone --depth 1 git://git2.kernel.org/pub/scm/git/git.git git-shallow ok, 'git log' gives a 2-revision history.

$ git clone git://git2.kernel.org/pub/scm/git/git.git git-full 'git log' gives a full history

$ git clone --depth 1 git-full git-shallow2 'git log' still gives a full history

Why can't I clone a shallow repo from the git-full? Does it requires some settings in the git-full repo?

Regards, Roy Roy

-- 
View this message in context: http://n2.nabble.com/Does-cloning-a-shallow-repo-require-special-setting-in-the-cloned-one--tp2387799p2387799.html
Sent from the git mailing list archive at Nabble.com.
Teemu Likonen· Feb 26, 2009, 06:34 UTC · re: roylee17 · lore

Re: Does cloning a shallow repo require special setting in the cloned one?

On 2009-02-25 19:49 (-0800), roylee17 wrote:
Show 5 quoted lines
> $ git clone --depth 1 git-full git-shallow2
> 'git log' still gives a full history
>
> Why can't I clone a shallow repo from the git-full?
> Does it requires some settings in the git-full repo?
I don't know the "why" part but using file:// URL should work:
    git clone --depth 1 file:///path/to/git-full git-shallow2
Roy Lee· Feb 26, 2009, 07:33 UTC · re: Teemu Likonen · lore

Re: Does cloning a shallow repo require special setting in the cloned one?

On Thu, Feb 26, 2009 at 2:34 PM, Teemu Likonen <tlikonen@iki.fi> wrote:
Show 12 quoted lines
> On 2009-02-25 19:49 (-0800), roylee17 wrote:
>
>> $ git clone --depth 1 git-full git-shallow2
>> 'git log' still gives a full history
>>
>> Why can't I clone a shallow repo from the git-full?
>> Does it requires some settings in the git-full repo?
>
> I don't know the "why" part but using file:// URL should work:
>
>    git clone --depth 1 file:///path/to/git-full git-shallow2
>
Thanks, Teemu. file:///path/to/git-full works.
Jeff King· Feb 26, 2009, 10:46 UTC · re: Teemu Likonen · lore

Re: Does cloning a shallow repo require special setting in the cloned one?

On Thu, Feb 26, 2009 at 08:34:51AM +0200, Teemu Likonen wrote:
Show 11 quoted lines
> On 2009-02-25 19:49 (-0800), roylee17 wrote:
> 
> > $ git clone --depth 1 git-full git-shallow2
> > 'git log' still gives a full history
> >
> > Why can't I clone a shallow repo from the git-full?
> > Does it requires some settings in the git-full repo?
> 
> I don't know the "why" part but using file:// URL should work:
> 
>     git clone --depth 1 file:///path/to/git-full git-shallow2

I don't think the behavior is intentional, but a side effect of the fact that git takes some shortcuts when cloning locally. In particular, it will try to copy or hardlink the object database rather than transmitting over the git protocol locally. Using file:// has always been the way to suppress that shortcut.

Perhaps to avoid surprise, that optimization should be turned off for options which cause it to behave differently (like --depth). But I have to wonder what the point of --depth is locally; if you are worried about space, hardlinks (the default) or alternates ("clone -s") are a better solution.

-Peff
Johannes Schindelin· Feb 26, 2009, 11:17 UTC · re: Jeff King · lore

Re: Does cloning a shallow repo require special setting in the cloned one?

Hi,
On Thu, 26 Feb 2009, Jeff King wrote:
Show 25 quoted lines
> On Thu, Feb 26, 2009 at 08:34:51AM +0200, Teemu Likonen wrote:
> 
> > On 2009-02-25 19:49 (-0800), roylee17 wrote:
> > 
> > > $ git clone --depth 1 git-full git-shallow2
> > > 'git log' still gives a full history
> > >
> > > Why can't I clone a shallow repo from the git-full?
> > > Does it requires some settings in the git-full repo?
> > 
> > I don't know the "why" part but using file:// URL should work:
> > 
> >     git clone --depth 1 file:///path/to/git-full git-shallow2
> 
> I don't think the behavior is intentional, but a side effect of the
> fact that git takes some shortcuts when cloning locally. In particular,
> it will try to copy or hardlink the object database rather than
> transmitting over the git protocol locally. Using file:// has always
> been the way to suppress that shortcut.
> 
> Perhaps to avoid surprise, that optimization should be turned off for
> options which cause it to behave differently (like --depth). But I have
> to wonder what the point of --depth is locally; if you are worried about
> space, hardlinks (the default) or alternates ("clone -s") are a better
> solution.

I think it is way better to warn, since "--depth" is usually passed out of concerns about disk space. And --shared should shut that concern up rather nicely.

diff --git a/builtin-clone.c b/builtin-clone.c
index c338910..5831034 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -511,8 +511,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	refspec.src = src_ref_prefix;
 	refspec.dst = branch_top.buf;
 
-	if (path && !is_bundle)
+	if (path && !is_bundle) {
+		if (option_depth)
+			warning("Ignoring --depth for local clone");
 		refs = clone_local(path, git_dir);
+	}
 	else {
 		struct remote *remote = remote_get(argv[0]);
 		transport = transport_get(remote, remote->url[0]);

Lacks tests,
Dscho
Jeff King· Feb 26, 2009, 13:19 UTC · re: Johannes Schindelin · lore

Re: Does cloning a shallow repo require special setting in the cloned one?

On Thu, Feb 26, 2009 at 12:17:36PM +0100, Johannes Schindelin wrote:
Show 21 quoted lines
> I think it is way better to warn, since "--depth" is usually passed out of 
> concerns about disk space.  And --shared should shut that concern up 
> rather nicely.
> 
> diff --git a/builtin-clone.c b/builtin-clone.c
> index c338910..5831034 100644
> --- a/builtin-clone.c
> +++ b/builtin-clone.c
> @@ -511,8 +511,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  	refspec.src = src_ref_prefix;
>  	refspec.dst = branch_top.buf;
>  
> -	if (path && !is_bundle)
> +	if (path && !is_bundle) {
> +		if (option_depth)
> +			warning("Ignoring --depth for local clone");
>  		refs = clone_local(path, git_dir);
> +	}
>  	else {
>  		struct remote *remote = remote_get(argv[0]);
>  		transport = transport_get(remote, remote->url[0]);
That seems reasonable to me.
-Peff
Roy Lee· Feb 26, 2009, 13:01 UTC · re: Jeff King · lore

Re: Does cloning a shallow repo require special setting in the cloned one?

On Thu, Feb 26, 2009 at 6:46 PM, Jeff King <peff@peff.net> wrote:
Show 28 quoted lines
> On Thu, Feb 26, 2009 at 08:34:51AM +0200, Teemu Likonen wrote:
>
>> On 2009-02-25 19:49 (-0800), roylee17 wrote:
>>
>> > $ git clone --depth 1 git-full git-shallow2
>> > 'git log' still gives a full history
>> >
>> > Why can't I clone a shallow repo from the git-full?
>> > Does it requires some settings in the git-full repo?
>>
>> I don't know the "why" part but using file:// URL should work:
>>
>>     git clone --depth 1 file:///path/to/git-full git-shallow2
>
> I don't think the behavior is intentional, but a side effect of the
> fact that git takes some shortcuts when cloning locally. In particular,
> it will try to copy or hardlink the object database rather than
> transmitting over the git protocol locally. Using file:// has always
> been the way to suppress that shortcut.
>
> Perhaps to avoid surprise, that optimization should be turned off for
> options which cause it to behave differently (like --depth). But I have
> to wonder what the point of --depth is locally; if you are worried about
> space, hardlinks (the default) or alternates ("clone -s") are a better
> solution.
>
> -Peff
>

Actully, the original intention was to find a quick way to checkout and build several projects regularly. The first thing came to me was cloning shallow repos for saving some time. So I tried it with my local repo first.

Later, one of my co-works suggested me to try git archive, and that did reallly fit my needs.

Thanks for clarifying my confusion.
Roy
Jakub Narebski· Feb 27, 2009, 00:42 UTC · re: Roy Lee · lore

Re: Does cloning a shallow repo require special setting in the cloned one?

Roy Lee <roylee17@gmail.com> writes:
Show 32 quoted lines
> On Thu, Feb 26, 2009 at 6:46 PM, Jeff King <peff@peff.net> wrote:
>> On Thu, Feb 26, 2009 at 08:34:51AM +0200, Teemu Likonen wrote:
>>> On 2009-02-25 19:49 (-0800), roylee17 wrote:
>>>
>>>> $ git clone --depth 1 git-full git-shallow2
>>>> 'git log' still gives a full history
>>>>
>>>> Why can't I clone a shallow repo from the git-full?
>>>> Does it requires some settings in the git-full repo?
>>>
>>> I don't know the "why" part but using file:// URL should work:
>>>
>>>     git clone --depth 1 file:///path/to/git-full git-shallow2
>>
>> I don't think the behavior is intentional, but a side effect of the
>> fact that git takes some shortcuts when cloning locally. In particular,
>> it will try to copy or hardlink the object database rather than
>> transmitting over the git protocol locally. Using file:// has always
>> been the way to suppress that shortcut.
>>
>> Perhaps to avoid surprise, that optimization should be turned off for
>> options which cause it to behave differently (like --depth). But I have
>> to wonder what the point of --depth is locally; if you are worried about
>> space, hardlinks (the default) or alternates ("clone -s") are a better
>> solution.
> 
> Actully, the original intention was to find a quick way to checkout and
> build several projects regularly. The first thing came to me was cloning
> shallow repos for saving some time. So I tried it with my local repo first.
> 
> Later, one of my co-works suggested me to try git archive, and that did
> reallly fit my needs.

Perhaps you would be interested then in contrib/workdir/git-new-workdir script then, which allows for multiple checked out copies from a single repository? Be aware that if you work in those copies, and are not careful, it can lead to confusion; but if all but one of checkouts are read only it could be the best solution.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

← back to recent threads