Merge branch 'sb/clone-shallow-passthru'
authorJunio C Hamano <gitster@pobox.com>
Fri, 6 May 2016 21:45:43 +0000 (14:45 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 May 2016 21:45:43 +0000 (14:45 -0700)
"git clone" learned "--shallow-submodules" option.

* sb/clone-shallow-passthru:
clone: add `--shallow-submodules` flag

1  2 
Documentation/git-clone.txt
builtin/clone.c
index 45d74be29705bae9ecd3028f4dff5755638741f7,e1a21b7de176bf7782ee5b3c7346f5a232f2b211..1b15cd7b16620e588d21e1c69a01e2e5d880729e
@@@ -14,8 -14,8 +14,8 @@@ SYNOPSI
          [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
          [--dissociate] [--separate-git-dir <git dir>]
          [--depth <depth>] [--[no-]single-branch]
-         [--recursive | --recurse-submodules] [--jobs <n>] [--] <repository>
-         [<directory>]
+         [--recursive | --recurse-submodules] [--[no-]shallow-submodules]
+         [--jobs <n>] [--] <repository> [<directory>]
  
  DESCRIPTION
  -----------
@@@ -115,7 -115,8 +115,7 @@@ objects from the source repository int
  --quiet::
  -q::
        Operate quietly.  Progress is not reported to the standard
 -      error stream. This flag is also passed to the `rsync'
 -      command when given.
 +      error stream.
  
  --verbose::
  -v::
  
  --depth <depth>::
        Create a 'shallow' clone with a history truncated to the
 -      specified number of revisions. Implies `--single-branch` unless
 +      specified number of commits. Implies `--single-branch` unless
        `--no-single-branch` is given to fetch the histories near the
-       tips of all branches.
+       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,
        either specified by the `--branch` option or the primary
 -      branch remote's `HEAD` points at. When creating a shallow
 -      clone with the `--depth` option, this is the default, unless
 -      `--no-single-branch` is given to fetch the histories near the
 -      tips of all branches.
 +      branch remote's `HEAD` points at.
        Further fetches into the resulting repository will only update the
        remote-tracking branch for the branch this option was used for the
        initial cloning.  If the HEAD at the remote did not point at any
        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=<git dir>::
        Instead of placing the cloned repository where it is supposed
        to be, place the cloned repository at the specified directory,
diff --combined builtin/clone.c
index 6576ecf34309db4135c7a41ad6d0ef70e4a21f24,ecdf3080a50103adba0dd1dfcff48bb6efe9f32b..5f867e67d8066fe70fdd67c3d8e2853ea6c3eaa1
@@@ -40,6 -40,7 +40,7 @@@ static const char * const builtin_clone
  
  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;
@@@ -47,7 -48,6 +48,7 @@@ static const char *real_git_dir
  static char *option_upload_pack = "git-upload-pack";
  static int option_verbosity;
  static int option_progress = -1;
 +static enum transport_family family;
  static struct string_list option_config;
  static struct string_list option_reference;
  static int option_dissociate;
@@@ -92,14 -92,12 +93,16 @@@ static struct option builtin_clone_opti
                    N_("create a shallow clone of that depth")),
        OPT_BOOL(0, "single-branch", &option_single_branch,
                    N_("clone only one branch, HEAD or --branch")),
+       OPT_BOOL(0, "shallow-submodules", &option_shallow_submodules,
+                   N_("any cloned submodules will be shallow")),
        OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
                   N_("separate git dir from working tree")),
        OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
                        N_("set config inside the new repository")),
 +      OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
 +                      TRANSPORT_FAMILY_IPV4),
 +      OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
 +                      TRANSPORT_FAMILY_IPV6),
        OPT_END()
  };
  
@@@ -235,8 -233,8 +238,8 @@@ static char *guess_dir_name(const char 
        strip_suffix_mem(start, &len, is_bundle ? ".bundle" : ".git");
  
        if (!len || (len == 1 && *start == '/'))
 -          die("No directory name could be guessed.\n"
 -              "Please specify a directory on the command line");
 +              die(_("No directory name could be guessed.\n"
 +                    "Please specify a directory on the command line"));
  
        if (is_bare)
                dir = xstrfmt("%.*s.git", (int)len, start);
@@@ -343,7 -341,7 +346,7 @@@ static void copy_alternates(struct strb
        FILE *in = fopen(src->buf, "r");
        struct strbuf line = STRBUF_INIT;
  
 -      while (strbuf_getline(&line, in, '\n') != EOF) {
 +      while (strbuf_getline(&line, in) != EOF) {
                char *abs_path;
                if (!line.len || line.buf[0] == '#')
                        continue;
@@@ -640,11 -638,9 +643,11 @@@ static void update_remote_refs(const st
                struct strbuf head_ref = STRBUF_INIT;
                strbuf_addstr(&head_ref, branch_top);
                strbuf_addstr(&head_ref, "HEAD");
 -              create_symref(head_ref.buf,
 -                            remote_head_points_at->peer_ref->name,
 -                            msg);
 +              if (create_symref(head_ref.buf,
 +                                remote_head_points_at->peer_ref->name,
 +                                msg) < 0)
 +                      die(_("unable to update %s"), head_ref.buf);
 +              strbuf_release(&head_ref);
        }
  }
  
@@@ -654,8 -650,7 +657,8 @@@ static void update_head(const struct re
        const char *head;
        if (our && skip_prefix(our->name, "refs/heads/", &head)) {
                /* Local default branch link */
 -              create_symref("HEAD", our->name, NULL);
 +              if (create_symref("HEAD", our->name, NULL) < 0)
 +                      die(_("unable to update HEAD"));
                if (!option_bare) {
                        update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0,
                                   UPDATE_REFS_DIE_ON_ERR);
@@@ -735,6 -730,10 +738,10 @@@ static int checkout(void
                struct argv_array args = ARGV_ARRAY_INIT;
                argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
  
+               if (option_shallow_submodules == 1
+                   || (option_shallow_submodules == -1 && option_depth))
+                       argv_array_push(&args, "--depth=1");
                if (max_jobs != -1)
                        argv_array_pushf(&args, "--jobs=%d", max_jobs);
  
  
  static int write_one_config(const char *key, const char *value, void *data)
  {
 -      return git_config_set_multivar(key, value ? value : "true", "^$", 0);
 +      return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0);
  }
  
  static void write_config(struct string_list *config)
        for (i = 0; i < config->nr; i++) {
                if (git_config_parse_parameter(config->items[i].string,
                                               write_one_config, NULL) < 0)
 -                      die("unable to write parameters to config file");
 +                      die(_("unable to write parameters to config file"));
        }
  }
  
@@@ -982,7 -981,6 +989,7 @@@ int cmd_clone(int argc, const char **ar
        remote = remote_get(option_origin);
        transport = transport_get(remote, remote->url[0]);
        transport_set_verbosity(transport, option_verbosity, option_progress);
 +      transport->family = family;
  
        path = get_repo_path(remote->url[0], &is_bundle);
        is_local = option_local != 0 && path && !is_bundle;