Re: [PATCH v2] [submodule] Add --depth to submodule update/add

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Apparently due to a newly added test at the end of t7400 this patch doesn't
apply cleanly to neither pu, next nor master for me. But it addresses all
issues raised in the first round.

Am 28.06.2013 15:22, schrieb Fredrik Gustafsson:
> When a submodule is clone, clone it width the --depth flag. This is useful

Maybe rephrase this as:
Add the --depth option to the add and update commands of "git submodule",
which is then passed on to the clone command. This is useful e.g.

> when the submodule(s) are huge and you're not really interested in anything
> but the latest commit.
> 
> Tests are added and to make --depth work the path for test "setup a submodule
> tree" had to be modified. Also did some indent adjustments to conform to the
> rest of the testfile on "submodule update can handle symbolic links in pwd".

Having to change existing tests is looking a bit fishy to me. Maybe just
sed the URLs into the file:// form requested by "clone --depth" right after
cloning the superproject in t7406?

> Signed-off-by: Fredrik Gustafsson <iveqy@xxxxxxxxx>
> ---
>  Documentation/git-submodule.txt | 13 +++++++++++--
>  git-submodule.sh                | 24 +++++++++++++++++++++---
>  t/t7400-submodule-basic.sh      | 18 ++++++++++++++++++
>  t/t7406-submodule-update.sh     | 28 ++++++++++++++++++++--------
>  4 files changed, 70 insertions(+), 13 deletions(-)
> 
> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
> index e576713..b17001a 100644
> --- a/Documentation/git-submodule.txt
> +++ b/Documentation/git-submodule.txt
> @@ -10,12 +10,12 @@ SYNOPSIS
>  --------
>  [verse]
>  'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]
> -	      [--reference <repository>] [--] <repository> [<path>]
> +	      [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
>  'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
>  'git submodule' [--quiet] init [--] [<path>...]
>  'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
>  'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
> -	      [-f|--force] [--rebase] [--reference <repository>]
> +	      [-f|--force] [--rebase] [--reference <repository>] [--depth <depth>]
>  	      [--merge] [--recursive] [--] [<path>...]
>  'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
>  	      [commit] [--] [<path>...]
> @@ -328,6 +328,15 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
>  	only in the submodules of the current repo, but also
>  	in any nested submodules inside those submodules (and so on).
>  
> +--depth::
> +	This option is valid for add and update commands. Create a 'shallow'
> +	clone with a history truncated to the specified number of revisions.
> +	A shallow repository has a number of limitations (you cannot clone
> +	or fetch from it, nor push from nor into it), but is adequate if
> +	you are only interested in the recent history of a large project
> +	with a long history.

Nice description, only a "linkgit:git-clone[1]" would be nice here.

> +
> +
>  <path>...::
>  	Paths to submodule(s). When specified this will restrict the command
>  	to only operate on the submodules found at the specified paths.
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 79bfaac..c99bc7c 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -32,6 +32,7 @@ nofetch=
>  update=
>  prefix=
>  custom_name=
> +depth=
>  
>  # The function takes at most 2 arguments. The first argument is the
>  # URL that navigates to the submodule origin repo. When relative, this URL
> @@ -211,6 +212,7 @@ module_clone()
>  	name=$2
>  	url=$3
>  	reference="$4"
> +	depth=$5
>  	quiet=
>  	if test -n "$GIT_QUIET"
>  	then
> @@ -234,7 +236,7 @@ module_clone()
>  		(
>  			clear_local_git_env
>  			git clone $quiet -n ${reference:+"$reference"} \
> -				--separate-git-dir "$gitdir" "$url" "$sm_path"
> +				--separate-git-dir "$gitdir" $depth "$url" "$sm_path"

Maybe also quote $depth here (even though that shouldn't be necessary
because it never should contain spaces, I'd prefer being consistent here).

>  		) ||
>  		die "$(eval_gettext "Clone of '\$url' into submodule path '\$sm_path' failed")"
>  	fi
> @@ -309,6 +311,14 @@ cmd_add()
>  			custom_name=$2
>  			shift
>  			;;
> +		--depth)
> +			case "$2" in '') usage ;; esac
> +			depth="--depth=$2"
> +			shift
> +			;;
> +		--depth=*)
> +			depth="$1"
> +			;;
>  		--)
>  			shift
>  			break
> @@ -405,7 +415,7 @@ Use -f if you really want to add it." >&2
>  				echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")"
>  			fi
>  		fi
> -		module_clone "$sm_path" "$sm_name" "$realrepo" "$reference" || exit
> +		module_clone "$sm_path" "$sm_name" "$realrepo" "$reference" "$depth" || exit
>  		(
>  			clear_local_git_env
>  			cd "$sm_path" &&
> @@ -676,6 +686,14 @@ cmd_update()
>  		--checkout)
>  			update="checkout"
>  			;;
> +		--depth)
> +			case "$2" in '') usage ;; esac
> +			depth="--depth=$2"
> +			shift
> +			;;
> +		--depth=*)
> +			depth="$1"
> +			;;
>  		--)
>  			shift
>  			break
> @@ -735,7 +753,7 @@ Maybe you want to use 'update --init'?")"
>  
>  		if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
>  		then
> -			module_clone "$sm_path" "$name" "$url" "$reference" || exit
> +			module_clone "$sm_path" "$name" "$url" "$reference" "$depth" || exit
>  			cloned_modules="$cloned_modules;$name"
>  			subsha1=
>  		else
> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> index f47cc7b..4502320 100755
> --- a/t/t7400-submodule-basic.sh
> +++ b/t/t7400-submodule-basic.sh
> @@ -868,4 +868,22 @@ test_expect_success 'submodule deinit fails when submodule has a .git directory
>  	test -n "$(git config --get-regexp "submodule\.example\.")"
>  '
>  
> +test_expect_success 'submodule add clone shallow submodule' '
> +	mkdir super &&
> +	pwd=$(pwd)
> +	(
> +		cd super &&
> +		git init &&
> +		git submodule add --depth=1 file://"$pwd"/example2 submodule &&
> +		(
> +			cd submodule &&
> +			if test $(git log --oneline | wc -l) != 1
> +			then
> +				exit 1
> +			fi

>From looking at other tests the following would be preferable (and shorter):

    test 1 = $(git log --oneline | wc -l)

> +		)
> +	)
> +'
> +
> +
>  test_done
> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
> index a4ffea0..b2d0f0e 100755
> --- a/t/t7406-submodule-update.sh
> +++ b/t/t7406-submodule-update.sh
> @@ -31,8 +31,9 @@ test_expect_success 'setup a submodule tree' '
>  	git clone super rebasing &&
>  	git clone super merging &&
>  	git clone super none &&
> +	pwd=$(pwd)
>  	(cd super &&
> -	 git submodule add ../submodule submodule &&
> +	 git submodule add file:///"$pwd"/submodule submodule &&
>  	 test_tick &&
>  	 git commit -m "submodule" &&
>  	 git submodule init submodule
> @@ -685,14 +686,25 @@ test_expect_success 'submodule update properly revives a moved submodule' '
>  test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
>  	mkdir -p linked/dir &&
>  	ln -s linked/dir linkto &&
> -	(
> -		cd linkto &&
> -		git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
> -		(
> -			cd super &&
> -			git submodule update --init --recursive
> -		)
> +	(cd linkto &&
> +	 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
> +	 (cd super &&
> +	  git submodule update --init --recursive
> +	 )
>  	)
>  '
>  
> +test_expect_success 'submodule update clone shallow submodule' '
> +	git clone cloned super3 &&
> +	(cd super3 &&
> +	 git submodule init &&
> +	 git submodule update --depth=3 &&
> +	 (cd submodule &&
> +	  if test $(git log --oneline | wc -l) != 1
> +	  then
> +	   exit 1
> +	  fi

See above.

> +	 )
> +	)
> +'
>  test_done
> 

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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]