Re: [PATCHv2] clone: add `--shallow-submodules` flag

2016-04-26 Thread Stefan Beller
On Tue, Apr 26, 2016 at 10:46 AM, Junio C Hamano  wrote:
> Stefan Beller  writes:
>
>>  I did not rebase this on 85705cfb (Merge branch 'ss/clone-depth-single-doc',
>>  2016-01-20) or later, but worked on it with the base unchanged.
>
> Thanks, will replace.
>
>> diff --git a/t/t5614-clone-submodules.sh b/t/t5614-clone-submodules.sh
>> new file mode 100755
>> index 000..62044c5
>> --- /dev/null
>> +++ b/t/t5614-clone-submodules.sh
>> @@ -0,0 +1,85 @@
>> +#!/bin/sh
>> +
>> +test_description='Test shallow cloning of repos with submodules'
>> +
>> +. ./test-lib.sh
>> +
>> +pwd=$(pwd)
>> +
>> +test_expect_success 'setup' '
>> + git checkout -b master &&
>> + test_commit commit1 &&
>> + test_commit commit2 &&
>> + mkdir sub &&
>> + (
>> + cd sub &&
>> + git init &&
>> + test_commit subcommit1 &&
>> + test_commit subcommit2 &&
>> + test_commit subcommit3
>> + ) &&
>> + git submodule add "file://$pwd/sub" sub &&
>> + git commit -m "add submodule"
>> +'
>> +
>> +test_expect_success 'nonshallow clone implies nonshallow submodule' '
>> + test_when_finished "rm -rf super_clone" &&
>> + git clone --recurse-submodules "file://$pwd/." super_clone &&
>
> All of these "$path/." made me wonder one thing.  I know these URLs
> that ends with slash-dot ought to work, but shouldn't they work
> without them, too?  The "consistency" in this test that ends
> anything that would have ended with "$pwd" with "$pwd/." somewhat
> bothered me.
>

Another case of me not thinking it through. There used to be just '.'
in the former
series with the --no-local option. And to make it a file url I just
prefixed that dot
without thinking if the dot is still needed.

In case another reroll is needed, I'll fix that up, too.

Thanks,
Stefan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2] clone: add `--shallow-submodules` flag

2016-04-26 Thread Junio C Hamano
Stefan Beller  writes:

>  I did not rebase this on 85705cfb (Merge branch 'ss/clone-depth-single-doc',
>  2016-01-20) or later, but worked on it with the base unchanged.

Thanks, will replace.

> diff --git a/t/t5614-clone-submodules.sh b/t/t5614-clone-submodules.sh
> new file mode 100755
> index 000..62044c5
> --- /dev/null
> +++ b/t/t5614-clone-submodules.sh
> @@ -0,0 +1,85 @@
> +#!/bin/sh
> +
> +test_description='Test shallow cloning of repos with submodules'
> +
> +. ./test-lib.sh
> +
> +pwd=$(pwd)
> +
> +test_expect_success 'setup' '
> + git checkout -b master &&
> + test_commit commit1 &&
> + test_commit commit2 &&
> + mkdir sub &&
> + (
> + cd sub &&
> + git init &&
> + test_commit subcommit1 &&
> + test_commit subcommit2 &&
> + test_commit subcommit3
> + ) &&
> + git submodule add "file://$pwd/sub" sub &&
> + git commit -m "add submodule"
> +'
> +
> +test_expect_success 'nonshallow clone implies nonshallow submodule' '
> + test_when_finished "rm -rf super_clone" &&
> + git clone --recurse-submodules "file://$pwd/." super_clone &&

All of these "$path/." made me wonder one thing.  I know these URLs
that ends with slash-dot ought to work, but shouldn't they work
without them, too?  The "consistency" in this test that ends
anything that would have ended with "$pwd" with "$pwd/." somewhat
bothered me.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv2] clone: add `--shallow-submodules` flag

2016-04-25 Thread Stefan Beller
When creating a shallow clone of a repository with submodules, the depth
argument does not influence the submodules, i.e. the submodules are done
as non-shallow clones. It is unclear what the best default is for the
depth of submodules of a shallow clone, so we need to have the possibility
to do all kinds of combinations:

* shallow super project with shallow submodules
  e.g. build bots starting always from scratch. They want to transmit
  the least amount of network data as well as using the least amount
  of space on their hard drive.
* shallow super project with unshallow submodules
  e.g. The superproject is just there to track a collection of repositories
  and it is not important to have the relationship between the repositories
  intact. However the history of the individual submodules matter.
* unshallow super project with shallow submodules
  e.g. The superproject is the actual project and the submodule is a
  library which is rarely touched.

The new switch to select submodules to be shallow or unshallow supports
all of these three cases.

It is easy to transition from the first to the second case by just
unshallowing the submodules (`git submodule foreach git fetch
--unshallow`), but it is not possible to transition from the second to the
first case (as we would have already transmitted the non shallow over
the network). That is why we want to make the first case the default in
case of a shallow super project. This leads to the inconvenience in the
second case with the shallow super project and unshallow submodules,
as you need to pass `--no-shallow-submodules`.

Signed-off-by: Stefan Beller 
Signed-off-by: Junio C Hamano 
---

 This is origin/sb/clone-shallow-passthru, with $pwd instead of $p
 in the tests.
 
 I did not rebase this on 85705cfb (Merge branch 'ss/clone-depth-single-doc',
 2016-01-20) or later, but worked on it with the base unchanged.

 Documentation/git-clone.txt | 13 +--
 builtin/clone.c |  7 
 t/t5614-clone-submodules.sh | 85 +
 3 files changed, 102 insertions(+), 3 deletions(-)
 create mode 100755 t/t5614-clone-submodules.sh

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 6db7b6d..e1a21b7 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -14,8 +14,8 @@ SYNOPSIS
  [-o ] [-b ] [-u ] [--reference ]
  [--dissociate] [--separate-git-dir ]
  [--depth ] [--[no-]single-branch]
- [--recursive | --recurse-submodules] [--jobs ] [--] 
- []
+ [--recursive | --recurse-submodules] [--[no-]shallow-submodules]
+ [--jobs ] [--]  []
 
 DESCRIPTION
 ---
@@ -190,7 +190,11 @@ objects from the source repository into a pack in the 
cloned repository.
 
 --depth ::
Create a 'shallow' clone with a history truncated to the
-   specified number of revisions.
+   specified number of revisions. Implies `--single-branch` unless
+   `--no-single-branch` is given to fetch the histories near the
+   tips of all branches. This implies `--shallow-submodules`. If
+   you want to have a shallow superproject clone, but full submodules,
+   also pass `--no-shallow-submodules`.
 
 --[no-]single-branch::
Clone only the history leading to the tip of a single branch,
@@ -214,6 +218,9 @@ objects from the source repository into a pack in the 
cloned repository.
repository does not have a worktree/checkout (i.e. if any of
`--no-checkout`/`-n`, `--bare`, or `--mirror` is given)
 
+--[no-]shallow-submodules::
+   All submodules which are cloned will be shallow with a depth of 1.
+
 --separate-git-dir=::
Instead of placing the cloned repository where it is supposed
to be, place the cloned repository at the specified directory,
diff --git a/builtin/clone.c b/builtin/clone.c
index b004fb4..ecdf308 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -40,6 +40,7 @@ static const char * const builtin_clone_usage[] = {
 
 static int option_no_checkout, option_bare, option_mirror, 
option_single_branch = -1;
 static int option_local = -1, option_no_hardlinks, option_shared, 
option_recursive;
+static int option_shallow_submodules = -1;
 static char *option_template, *option_depth;
 static char *option_origin = NULL;
 static char *option_branch = NULL;
@@ -91,6 +92,8 @@ static struct option builtin_clone_options[] = {
N_("create a shallow clone of that depth")),
OPT_BOOL(0, "single-branch", _single_branch,
N_("clone only one branch, HEAD or --branch")),
+   OPT_BOOL(0, "shallow-submodules", _shallow_submodules,
+   N_("any cloned submodules will be shallow")),
OPT_STRING(0, "separate-git-dir", _git_dir, N_("gitdir"),
   N_("separate git dir from working tree")),
OPT_STRING_LIST('c', "config", _config, N_("key=value"),
@@ -727,6 +730,10