Merge branch 'sb/submodule-recommend-shallowness'
authorJunio C Hamano <gitster@pobox.com>
Mon, 20 Jun 2016 18:01:01 +0000 (11:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Jun 2016 18:01:01 +0000 (11:01 -0700)
An upstream project can make a recommendation to shallowly clone
some submodules in the .gitmodules file it ships.

* sb/submodule-recommend-shallowness:
submodule update: learn `--[no-]recommend-shallow` option
submodule-config: keep shallow recommendation around

1  2 
builtin/submodule--helper.c
git-submodule.sh
index 926d2051623be390d5de2611d81d5fe9f39a8169,ca33408f55dd9c8df2e040871ec9297d18239251..c7deb55785ddbf32c378c83c1dc3ed4cacdf26db
@@@ -287,8 -287,10 +287,8 @@@ static int module_list(int argc, const 
        argc = parse_options(argc, argv, prefix, module_list_options,
                             git_submodule_helper_usage, 0);
  
 -      if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) {
 -              printf("#unmatched\n");
 +      if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0)
                return 1;
 -      }
  
        for (i = 0; i < list.nr; i++) {
                const struct cache_entry *ce = list.entries[i];
@@@ -579,6 -581,7 +579,7 @@@ struct submodule_update_clone 
  
        /* configuration parameters which are passed on to the children */
        int quiet;
+       int recommend_shallow;
        const char *reference;
        const char *depth;
        const char *recursive_prefix;
        unsigned quickstop : 1;
  };
  #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
-       SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \
+       SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, NULL, NULL, NULL, NULL, \
        STRING_LIST_INIT_DUP, 0}
  
  
@@@ -696,6 -699,8 +697,8 @@@ static int prepare_to_clone_next_submod
                argv_array_push(&child->args, "--quiet");
        if (suc->prefix)
                argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL);
+       if (suc->recommend_shallow && sub->recommend_shallow == 1)
+               argv_array_push(&child->args, "--depth=1");
        argv_array_pushl(&child->args, "--path", sub->path, NULL);
        argv_array_pushl(&child->args, "--name", sub->name, NULL);
        argv_array_pushl(&child->args, "--url", url, NULL);
@@@ -778,6 -783,8 +781,8 @@@ static int update_clone(int argc, cons
                              "specified number of revisions")),
                OPT_INTEGER('j', "jobs", &max_jobs,
                            N_("parallel jobs")),
+               OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
+                           N_("whether the initial clone should follow the shallow recommendation")),
                OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
                OPT_END()
        };
        return 0;
  }
  
 +static int resolve_relative_path(int argc, const char **argv, const char *prefix)
 +{
 +      struct strbuf sb = STRBUF_INIT;
 +      if (argc != 3)
 +              die("submodule--helper relative_path takes exactly 2 arguments, got %d", argc);
 +
 +      printf("%s", relative_path(argv[1], argv[2], &sb));
 +      strbuf_release(&sb);
 +      return 0;
 +}
 +
  struct cmd_struct {
        const char *cmd;
        int (*fn)(int, const char **, const char *);
@@@ -852,7 -848,6 +857,7 @@@ static struct cmd_struct commands[] = 
        {"name", module_name},
        {"clone", module_clone},
        {"update-clone", update_clone},
 +      {"relative-path", resolve_relative_path},
        {"resolve-relative-url", resolve_relative_url},
        {"resolve-relative-url-test", resolve_relative_url_test},
        {"init", module_init}
diff --combined git-submodule.sh
index 128f22ffb830870fd92751b9b4676f31b042a5e6,42e0e9f63df06453a1515ceaa33b9431c966a23f..b39ac106ec33112b1dbd2bc5cad5767ce73bdc44
@@@ -9,7 -9,7 +9,7 @@@ USAGE="[--quiet] add [-b <branch>] [-f|
     or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] init [--] [<path>...]
     or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
-    or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...]
+    or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
     or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
     or: $dashless [--quiet] foreach [--recursive] <command>
     or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
@@@ -46,6 -46,41 +46,6 @@@ prefix
  custom_name=
  depth=
  
 -# Resolve a path to be relative to another path.  This is intended for
 -# converting submodule paths when git-submodule is run in a subdirectory
 -# and only handles paths where the directory separator is '/'.
 -#
 -# The output is the first argument as a path relative to the second argument,
 -# which defaults to $wt_prefix if it is omitted.
 -relative_path ()
 -{
 -      local target curdir result
 -      target=$1
 -      curdir=${2-$wt_prefix}
 -      curdir=${curdir%/}
 -      result=
 -
 -      while test -n "$curdir"
 -      do
 -              case "$target" in
 -              "$curdir/"*)
 -                      target=${target#"$curdir"/}
 -                      break
 -                      ;;
 -              esac
 -
 -              result="${result}../"
 -              if test "$curdir" = "${curdir%/*}"
 -              then
 -                      curdir=
 -              else
 -                      curdir="${curdir%/*}"
 -              fi
 -      done
 -
 -      echo "$result$target"
 -}
 -
  die_if_unmatched ()
  {
        if test "$1" = "#unmatched"
@@@ -310,23 -345,20 +310,23 @@@ cmd_foreach(
        # command in the subshell (and a recursive call to this function)
        exec 3<&0
  
 -      git submodule--helper list --prefix "$wt_prefix"|
 +      {
 +              git submodule--helper list --prefix "$wt_prefix" ||
 +              echo "#unmatched"
 +      } |
        while read mode sha1 stage sm_path
        do
                die_if_unmatched "$mode"
                if test -e "$sm_path"/.git
                then
 -                      displaypath=$(relative_path "$prefix$sm_path")
 +                      displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
                        say "$(eval_gettext "Entering '\$displaypath'")"
                        name=$(git submodule--helper name "$sm_path")
                        (
                                prefix="$prefix$sm_path/"
                                sanitize_submodule_env
                                cd "$sm_path" &&
 -                              sm_path=$(relative_path "$sm_path") &&
 +                              sm_path=$(git submodule--helper relative-path "$sm_path" "$wt_prefix") &&
                                # we make $path available to scripts ...
                                path=$sm_path &&
                                if test $# -eq 1
@@@ -421,16 -453,13 +421,16 @@@ cmd_deinit(
                die "$(eval_gettext "Use '--all' if you really want to deinitialize all submodules")"
        fi
  
 -      git submodule--helper list --prefix "$wt_prefix" "$@" |
 +      {
 +              git submodule--helper list --prefix "$wt_prefix" "$@" ||
 +              echo "#unmatched"
 +      } |
        while read mode sha1 stage sm_path
        do
                die_if_unmatched "$mode"
                name=$(git submodule--helper name "$sm_path") || exit
  
 -              displaypath=$(relative_path "$sm_path")
 +              displaypath=$(git submodule--helper relative-path "$sm_path" "$wt_prefix")
  
                # Remove the submodule work tree (unless the user already did it)
                if test -d "$sm_path"
@@@ -530,6 -559,12 +530,12 @@@ cmd_update(
                --checkout)
                        update="checkout"
                        ;;
+               --recommend-shallow)
+                       recommend_shallow="--recommend-shallow"
+                       ;;
+               --no-recommend-shallow)
+                       recommend_shallow="--no-recommend-shallow"
+                       ;;
                --depth)
                        case "$2" in '') usage ;; esac
                        depth="--depth=$2"
                ${update:+--update "$update"} \
                ${reference:+--reference "$reference"} \
                ${depth:+--depth "$depth"} \
+               ${recommend_shallow:+"$recommend_shallow"} \
                ${jobs:+$jobs} \
                "$@" || echo "#unmatched"
        } | {
                        fi
                fi
  
 -              displaypath=$(relative_path "$prefix$sm_path")
 +              displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
  
                if test $just_cloned -eq 1
                then
                        if test -z "$nofetch"
                        then
                                # Fetch remote before determining tracking $sha1
 -                              (sanitize_submodule_env; cd "$sm_path" && git-fetch) ||
 +                              fetch_in_submodule "$sm_path" ||
                                die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
                        fi
                        remote_name=$(sanitize_submodule_env; cd "$sm_path" && get_default_remote)
                if test -n "$recursive"
                then
                        (
 -                              prefix=$(relative_path "$prefix$sm_path/")
 +                              prefix=$(git submodule--helper relative-path "$prefix$sm_path/" "$wt_prefix")
                                wt_prefix=
                                sanitize_submodule_env
                                cd "$sm_path" &&
@@@ -872,7 -908,7 +879,7 @@@ cmd_summary() 
                ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
                missing_dst=t
  
 -              display_name=$(relative_path "$name")
 +              display_name=$(git submodule--helper relative-path "$name" "$wt_prefix")
  
                total_commits=
                case "$missing_src,$missing_dst" in
@@@ -984,16 -1020,13 +991,16 @@@ cmd_status(
                shift
        done
  
 -      git submodule--helper list --prefix "$wt_prefix" "$@" |
 +      {
 +              git submodule--helper list --prefix "$wt_prefix" "$@" ||
 +              echo "#unmatched"
 +      } |
        while read mode sha1 stage sm_path
        do
                die_if_unmatched "$mode"
                name=$(git submodule--helper name "$sm_path") || exit
                url=$(git config submodule."$name".url)
 -              displaypath=$(relative_path "$prefix$sm_path")
 +              displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
                if test "$stage" = U
                then
                        say "U$sha1 $displaypath"
@@@ -1065,10 -1098,7 +1072,10 @@@ cmd_sync(
                esac
        done
        cd_to_toplevel
 -      git submodule--helper list --prefix "$wt_prefix" "$@" |
 +      {
 +              git submodule--helper list --prefix "$wt_prefix" "$@" ||
 +              echo "#unmatched"
 +      } |
        while read mode sha1 stage sm_path
        do
                die_if_unmatched "$mode"
  
                if git config "submodule.$name.url" >/dev/null 2>/dev/null
                then
 -                      displaypath=$(relative_path "$prefix$sm_path")
 +                      displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
                        say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")"
                        git config submodule."$name".url "$super_config_url"