git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 7/7] git-submodule: Don't die when command fails for one submodule
  2008-03-13 17:56           ` [PATCH 6/7] git-submodule: multi-level module definition Ping Yin
@ 2008-03-13 17:56             ` Ping Yin
  0 siblings, 0 replies; 19+ messages in thread
From: Ping Yin @ 2008-03-13 17:56 UTC (permalink / raw)
  To: git; +Cc: gitster, Ping Yin

When handling multiple modules, init/update/status/add subcommand will
exit when it fails for one submodule. This patch makes the subcommand
continue bypassing the failure and keep right exit status.

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh |   87 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 63 insertions(+), 24 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 79fb30f..e78d797 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -193,15 +193,19 @@ module_clone()
 	# succeed but the rmdir will fail. We might want to fix this.
 	if test -d "$path"
 	then
-		rmdir "$path" 2>/dev/null ||
-		die "Directory '$path' exist, but is neither empty nor a git repository"
+		! rmdir "$path" 2>/dev/null &&
+		say "Directory '$path' exist, but is neither empty nor a git repository" &&
+		return 1
 	fi
 
 	test -e "$path" &&
-	die "A file already exist at path '$path'"
+	say "A file already exist at path '$path'" &&
+	return 1
 
-	git-clone -n "$url" "$path" ||
-	die "Clone of '$url' into submodule path '$path' failed"
+	! git-clone -n "$url" "$path" &&
+	say "Clone of '$url' into submodule path '$path' failed" &&
+	return 1
+	:
 }
 
 #
@@ -227,7 +231,8 @@ module_add() {
 	fi
 
 	git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
-	die "'$path' already exists in the index"
+	say "'$path' already exists in the index" &&
+	return 1
 
 	# perhaps the path exists and is already a git repo, else clone it
 	if test -e "$path"
@@ -237,21 +242,26 @@ module_add() {
 		then
 			echo "Adding existing repo at '$path' to the index"
 		else
-			die "'$path' already exists and is not a valid git repo"
+			say "'$path' already exists and is not a valid git repo"
+			return 1
 		fi
 	else
-		module_clone "$path" "$repo" || exit
-		(unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
-		die "Unable to checkout submodule '$path'"
+		module_clone "$path" "$repo" || return 1
+		! (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) &&
+		say "Unable to checkout submodule '$path'" &&
+		return 1
 	fi
 
-	git add "$path" ||
-	die "Failed to add submodule '$path'"
+	! git add "$path" &&
+	say "Failed to add submodule '$path'" &&
+	return 1
 
 	GIT_CONFIG=.gitmodules git config submodule."$path".path "$path" &&
 	GIT_CONFIG=.gitmodules git config submodule."$path".url "$repo" &&
-	git add .gitmodules ||
-	die "Failed to register submodule '$path'"
+	! git add .gitmodules &&
+	say "Failed to register submodule '$path'" &&
+	return 1
+	:
 }
 
 #
@@ -292,14 +302,17 @@ cmd_add()
 	if test -n "$use_module_name"
 	then
 		module_info "$@" |
+		{
+		exit_status=0
 		while read sha1 path name url
 		do
-			module_add "$url" "$path"
+			module_add "$url" "$path" || exit_status=1
 		done
+		test $exit_status = 0
+		}
 	else
 		module_add "$1" "$2"
 	fi
-
 }
 
 #
@@ -331,20 +344,30 @@ cmd_init()
 	done
 
 	module_info "$@" |
+	{
+	exit_status=0
 	while read sha1 path name url
 	do
-		test -n "$name" || exit
+		test -z "$name" && exit_status=1 && continue
 		test -z "$url" &&
-		die "No url found for submodule path '$path' in .gitmodules"
+		say "No url found for submodule path '$path' in .gitmodules" &&
+		exit_status=1 &&
+		continue
 		# Skip already registered paths
 		git config submodule.$name.url && continue
 
 		url=$(absolute_url "$url")
 		git config submodule."$name".url "$url" ||
-		die "Failed to register url for submodule path '$path'"
+		{
+		say "Failed to register url for submodule path '$path'"
+		exit_status=1
+		continue
+		}
 
 		say "Submodule '$name' ($url) registered for path '$path'"
 	done
+	exit $exit_status
+	}
 }
 
 #
@@ -376,9 +399,11 @@ cmd_update()
 	done
 
 	module_info "$@" |
+	{
+	exit_status=0
 	while read sha1 path name url
 	do
-		test -n "$name" || exit
+		test -z "$name" && exit_status=1 && continue
 		if test $sha1 = 0000000000000000000000000000000000000000
 		then
 			say "Not a submodule: $name @ $path"
@@ -394,23 +419,33 @@ cmd_update()
 
 		if ! test -d "$path"/.git
 		then
-			module_clone "$path" "$url" || exit
+			! module_clone "$path" "$url" && exit_status=1 && continue
 			subsha1=
 		else
 			subsha1=$(unset GIT_DIR; cd "$path" &&
 				git rev-parse --verify HEAD) ||
-			die "Unable to find current revision in submodule path '$path'"
+			{
+				say "Unable to find current revision in submodule path '$path'"
+				exit_status=1
+				continue
+			}
 		fi
 
 		if test "$subsha1" != "$sha1"
 		then
 			(unset GIT_DIR; cd "$path" && git-fetch &&
 				git-checkout -q "$sha1") ||
-			die "Unable to checkout '$sha1' in submodule path '$path'"
+			{
+				say "Unable to checkout '$sha1' in submodule path '$path'"
+				exit_status=1
+				continue
+			}
 
 			say "Submodule path '$path': checked out '$sha1'"
 		fi
 	done
+	exit $exit_status
+	}
 }
 
 set_name_rev () {
@@ -629,9 +664,11 @@ cmd_status()
 		shift
 	done
 	module_info "$@" |
+	{
+	exit_status=0
 	while read sha1 path name url
 	do
-		test -n "$name" || exit
+		test -z "$name" && exit_status=1 && continue
 		if test $sha1 = 0000000000000000000000000000000000000000
 		then
 			say "*$sha1 $path"
@@ -654,6 +691,8 @@ cmd_status()
 			say "+$sha1 $path$revname"
 		fi
 	done
+	exit $exit_status
+	}
 }
 
 # This loop parses the command line arguments to find the
-- 
1.5.4.4.653.g7cf1e

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 0/7] submodule: fallback to .gitmodules and multiple level module definition
@ 2008-04-16 14:19 Ping Yin
  2008-04-16 14:19 ` [PATCH 1/7] git-submodule: Extract functions module_info and module_url Ping Yin
  0 siblings, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-16 14:19 UTC (permalink / raw)
  To: git; +Cc: gitster

This is a resend of the RFC patches some days ago, with only minor
code modification and log refinement. Also swap the order of the last
two patches.

Since there is less feedback these days, i don't know much what you
guys think of this patch series. However, i have use this series for a
long time and think personally it is useful when having many submodules. 

So i resend it, and look forward to its acceptance.

This patch series has following functional improvements for submodule

 - Fall back on .gitmodules if info not found in $GIT_DIR/config
 - multi-level module definition
 - Don't die when subcommand fails for one module

 Actually, they seems three independent improvements. But the first two
 improvements are both dependent on the first two refactoring patches
 and the 3rd improvement is dependent on the implementation of the
 first two improvements. So i have to send them in batch.

Patches 1,2,4 is mainly code refactor but the second one also
has some semantic change.

The other patches do the real functional changes.

Ping Yin (7):
      git-submodule: Extract functions module_info and module_url
      git-submodule: Extract absolute_url & move absolute url logic to module_clone
      git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config
      git-submodule: Extract module_add from cmd_add
      git-submodule: multi-level module definition
      git-submodule: "update --force" to enforce cloning non-submodule
      git-submodule: Don't die when command fails for one submodule

 git-submodule.sh           |  325 ++++++++++++++++++++++++++++++++------------
 t/t7400-submodule-basic.sh |   31 ++++-
 2 files changed, 266 insertions(+), 90 deletions(-)


Following is the diff with former RFC patch series

diff --git a/git-submodule.sh b/git-submodule.sh
index 8bea97a..0ecc4ff 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -354,7 +354,7 @@ cmd_init()
 		exit_status=1 &&
 		continue
 		# Skip already registered paths
-		git config submodule.$name.url && continue
+		test -z "$(git config submodule.$name.url)" || continue
 
 		url=$(absolute_url "$url")
 		git config submodule."$name".url "$url" ||
@@ -442,7 +442,6 @@ cmd_update()
 			}
 		fi
 
-
 		if test "$subsha1" != "$sha1"
 		then
 			(unset GIT_DIR; cd "$path" && git-fetch &&
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index d9b48f7..8b35ff8 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -187,7 +187,7 @@ test_expect_success 'status should be "modified" after submodule reset --hard HE
 	git-submodule status | grep "^+$rev2"
 '
 
-test_expect_success 'update should checkout rev1 when fall back' '
+test_expect_success 'update should checkout rev1 with falling back' '
 	git-config --unset submodule.example.url &&
 	GIT_CONFIG=.gitmodules git config submodule.example.url .subrepo &&
 	git-submodule update init &&

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 1/7] git-submodule: Extract functions module_info and module_url
  2008-04-16 14:19 [PATCH 0/7] submodule: fallback to .gitmodules and multiple level module definition Ping Yin
@ 2008-04-16 14:19 ` Ping Yin
  2008-04-16 14:19   ` [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin
  0 siblings, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-16 14:19 UTC (permalink / raw)
  To: git; +Cc: gitster, Ping Yin

module_info is extracted to remove the logic redundance which acquires
module names and urls by path filter in several places.

module_url is also extracted to prepare for an alternative logic to get url by
module name.

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index a745e42..0d82ec1 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -82,6 +82,25 @@ module_name()
        echo "$name"
 }
 
+module_url() {
+	git config submodule.$1.url
+}
+
+module_info() {
+	git ls-files --stage -- "$@" | grep -e '^160000 ' |
+	while read mode sha1 stage path
+	do
+		name=$(module_name "$path")
+		if test -n "$name"
+		then
+			url=$(module_url "$name")
+			echo "$sha1	$path	$name	$url"
+		else
+			echo "$sha1	$path		"
+		fi
+	done
+}
+
 #
 # Clone a submodule
 #
@@ -232,12 +251,11 @@ cmd_init()
 		shift
 	done
 
-	git ls-files --stage -- "$@" | grep '^160000 ' |
-	while read mode sha1 stage path
+	module_info "$@" |
+	while read sha1 path name url
 	do
+		test -n "$name" || exit
 		# Skip already registered paths
-		name=$(module_name "$path") || exit
-		url=$(git config submodule."$name".url)
 		test -z "$url" || continue
 
 		url=$(GIT_CONFIG=.gitmodules git config submodule."$name".url)
@@ -286,11 +304,10 @@ cmd_update()
 		shift
 	done
 
-	git ls-files --stage -- "$@" | grep '^160000 ' |
-	while read mode sha1 stage path
+	module_info "$@" |
+	while read sha1 path name url
 	do
-		name=$(module_name "$path") || exit
-		url=$(git config submodule."$name".url)
+		test -n "$name" || exit
 		if test -z "$url"
 		then
 			# Only mention uninitialized submodules when its
@@ -538,11 +555,10 @@ cmd_status()
 		shift
 	done
 
-	git ls-files --stage -- "$@" | grep '^160000 ' |
-	while read mode sha1 stage path
+	module_info "$@" |
+	while read sha1 path name url
 	do
-		name=$(module_name "$path") || exit
-		url=$(git config submodule."$name".url)
+		test -n "$name" || exit
 		if test -z "$url" || ! test -d "$path"/.git
 		then
 			say "-$sha1 $path"
-- 
1.5.5.70.gd68a

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-16 14:19 ` [PATCH 1/7] git-submodule: Extract functions module_info and module_url Ping Yin
@ 2008-04-16 14:19   ` Ping Yin
  2008-04-16 14:19     ` [PATCH 3/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config Ping Yin
  2008-04-22  6:10     ` [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Junio C Hamano
  0 siblings, 2 replies; 19+ messages in thread
From: Ping Yin @ 2008-04-16 14:19 UTC (permalink / raw)
  To: git; +Cc: gitster, Ping Yin

Extract function absolute_url to remove code redundance and inconsistence in
cmd_init and cmd_add when resolving relative url/path to absolute one.

Also move resolving absolute url logic from cmd_add to module_clone which
results in a litte behaviour change: cmd_update originally doesn't
resolve absolute url but now it will.

This behaviour change breaks t7400 which uses relative url './.subrepo'.
However, this test originally doesn't mean to test relative url with './',
so fix the url as '.subrepo'.

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh           |   41 ++++++++++++++++++-----------------------
 t/t7400-submodule-basic.sh |    2 +-
 2 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 0d82ec1..d3ae1e4 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -65,6 +65,21 @@ resolve_relative_url ()
 	echo "$remoteurl/$url"
 }
 
+# Resolve relative url/path to absolute one
+absolute_url () {
+	case "$1" in
+	./*|../*)
+		# dereference source url relative to parent's url
+		url="$(resolve_relative_url $1)" ;;
+	*)
+		# Turn the source into an absolute path if it is local
+		url=$(get_repo_base "$1") ||
+		url=$1
+		;;
+	esac
+	echo "$url"
+}
+
 #
 # Map submodule path to submodule name
 #
@@ -112,7 +127,7 @@ module_info() {
 module_clone()
 {
 	path=$1
-	url=$2
+	url=$(absolute_url "$2")
 
 	# If there already is a directory at the submodule path,
 	# expect it to be empty (since that is the default checkout
@@ -195,21 +210,7 @@ cmd_add()
 			die "'$path' already exists and is not a valid git repo"
 		fi
 	else
-		case "$repo" in
-		./*|../*)
-			# dereference source url relative to parent's url
-			realrepo="$(resolve_relative_url $repo)" ;;
-		*)
-			# Turn the source into an absolute path if
-			# it is local
-			if base=$(get_repo_base "$repo"); then
-				repo="$base"
-			fi
-			realrepo=$repo
-			;;
-		esac
-
-		module_clone "$path" "$realrepo" || exit
+		module_clone "$path" "$repo" || exit
 		(unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
 		die "Unable to checkout submodule '$path'"
 	fi
@@ -262,13 +263,7 @@ cmd_init()
 		test -z "$url" &&
 		die "No url found for submodule path '$path' in .gitmodules"
 
-		# Possibly a url relative to parent
-		case "$url" in
-		./*|../*)
-			url="$(resolve_relative_url "$url")"
-			;;
-		esac
-
+		url=$(absolute_url "$url")
 		git config submodule."$name".url "$url" ||
 		die "Failed to register url for submodule path '$path'"
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 2ef85a8..e5d59b8 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -75,7 +75,7 @@ test_expect_success 'init should register submodule url in .git/config' '
 	then
 		echo "[OOPS] init succeeded but submodule url is wrong"
 		false
-	elif ! git config submodule.example.url ./.subrepo
+	elif ! git config submodule.example.url .subrepo
 	then
 		echo "[OOPS] init succeeded but update of url failed"
 		false
-- 
1.5.5.70.gd68a

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config
  2008-04-16 14:19   ` [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin
@ 2008-04-16 14:19     ` Ping Yin
  2008-04-16 14:19       ` [PATCH 4/7] git-submodule: Extract module_add from cmd_add Ping Yin
  2008-04-22  6:10     ` [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Junio C Hamano
  1 sibling, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-16 14:19 UTC (permalink / raw)
  To: git; +Cc: gitster, Ping Yin

Originally, the submodule workflow enforces 'git init' in the beginning
which copies submodule config info from .gitmodules to $GIT_DIR/config.
Then all subcommands except 'init' and 'add' fetch submodule info from
$GIT_DIR/config and .gitmodules can be discarded.

However, there may be inconsistence between .git/config and .gitmodules
when always using 'git init' at first. If upstream .gitmodules changes,
it is not easy to sync the changes to $GIT_DIR/config.

Running 'git init' again may not help much in this case.  Since .git/config
has a whole copy of .gitmodules, the user has no easy way to know which
entries should follow the upstream changes and which entires shouldn't.

Actually, .gitmodules which formly only acted as info hints can and should
play a more important and essential role.

As an analogy to .gitignore and .git/info/excludes which are for colleagues'
and individual wishes separately, .gitmodules is for common requirements and
$GIT_DIR/config is for special requirements.

This patch implements a fall back strategy to satisfy both common and
special requirements as follows.

$GIT_DIR/config only keeps submodule info different from .gitmodules.
And the info from $GIT_DIR/config take higher precedence. The code first
consults $GIT_DIR/config and then fall back on in-tree .gitmodules file.

With this patch, init subcommand becomes not forcefull and less meaningful.
And now it is just a tool to help users copy info to $GIT_DIR/config
(and may modify it later) only when they need.

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh           |    9 ++++-----
 t/t7400-submodule-basic.sh |   29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index d3ae1e4..2276f6b 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -98,7 +98,8 @@ module_name()
 }
 
 module_url() {
-	git config submodule.$1.url
+	git config submodule.$1.url ||
+	GIT_CONFIG=.gitmodules git config submodule.$1.url
 }
 
 module_info() {
@@ -256,12 +257,10 @@ cmd_init()
 	while read sha1 path name url
 	do
 		test -n "$name" || exit
-		# Skip already registered paths
-		test -z "$url" || continue
-
-		url=$(GIT_CONFIG=.gitmodules git config submodule."$name".url)
 		test -z "$url" &&
 		die "No url found for submodule path '$path' in .gitmodules"
+		# Skip already registered paths
+		test -z "$(git config submodule.$name.url)" || continue
 
 		url=$(absolute_url "$url")
 		git config submodule."$name".url "$url" ||
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index e5d59b8..8b35ff8 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -174,6 +174,35 @@ test_expect_success 'status should be "up-to-date" after update' '
 	git-submodule status | grep "^ $rev1"
 '
 
+test_expect_success 'status should be "modified" after submodule reset --hard HEAD@{1}' '
+	cd init &&
+	git reset --hard HEAD@{1}
+	rev2=$(git rev-parse HEAD) &&
+	cd .. &&
+	if test -z "$rev2"
+	then
+		echo "[OOPS] submodule git rev-parse returned nothing"
+		false
+	fi &&
+	git-submodule status | grep "^+$rev2"
+'
+
+test_expect_success 'update should checkout rev1 with falling back' '
+	git-config --unset submodule.example.url &&
+	GIT_CONFIG=.gitmodules git config submodule.example.url .subrepo &&
+	git-submodule update init &&
+	head=$(cd init && git rev-parse HEAD) &&
+	if test -z "$head"
+	then
+		echo "[OOPS] submodule git rev-parse returned nothing"
+		false
+	elif test "$head" != "$rev1"
+	then
+		echo "[OOPS] init did not checkout correct head"
+		false
+	fi
+'
+
 test_expect_success 'checkout superproject with subproject already present' '
 	git-checkout initial &&
 	git-checkout master
-- 
1.5.5.70.gd68a

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 4/7] git-submodule: Extract module_add from cmd_add
  2008-04-16 14:19     ` [PATCH 3/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config Ping Yin
@ 2008-04-16 14:19       ` Ping Yin
  2008-04-16 14:19         ` [PATCH 5/7] git-submodule: multi-level module definition Ping Yin
  0 siblings, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-16 14:19 UTC (permalink / raw)
  To: git; +Cc: gitster, Ping Yin

cmd_add will later handle the case adding multiple modules, so extract
module_add to add a single module.

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh |   67 +++++++++++++++++++++++++++++++----------------------
 1 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 2276f6b..f3a1213 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -155,34 +155,7 @@ module_clone()
 #
 # optional branch is stored in global branch variable
 #
-cmd_add()
-{
-	# parse $args after "submodule ... add".
-	while test $# -ne 0
-	do
-		case "$1" in
-		-b | --branch)
-			case "$2" in '') usage ;; esac
-			branch=$2
-			shift
-			;;
-		-q|--quiet)
-			quiet=1
-			;;
-		--)
-			shift
-			break
-			;;
-		-*)
-			usage
-			;;
-		*)
-			break
-			;;
-		esac
-		shift
-	done
-
+module_add() {
 	repo=$1
 	path=$2
 
@@ -226,6 +199,44 @@ cmd_add()
 }
 
 #
+# Add a new submodule to the working tree, .gitmodules and the index
+#
+# $@ = repo [path]
+#
+# optional branch is stored in global branch variable
+#
+cmd_add()
+{
+	# parse $args after "submodule ... add".
+	while test $# -ne 0
+	do
+		case "$1" in
+		-b | --branch)
+			case "$2" in '') usage ;; esac
+			branch=$2
+			shift
+			;;
+		-q|--quiet)
+			quiet=1
+			;;
+		--)
+			shift
+			break
+			;;
+		-*)
+			usage
+			;;
+		*)
+			break
+			;;
+		esac
+		shift
+	done
+
+	module_add "$1" "$2"
+}
+
+#
 # Register submodules in .git/config
 #
 # $@ = requested paths (default to all)
-- 
1.5.5.70.gd68a

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 5/7] git-submodule: multi-level module definition
  2008-04-16 14:19       ` [PATCH 4/7] git-submodule: Extract module_add from cmd_add Ping Yin
@ 2008-04-16 14:19         ` Ping Yin
  2008-04-16 14:19           ` [PATCH 6/7] git-submodule: "update --force" to enforce cloning non-submodule Ping Yin
  0 siblings, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-16 14:19 UTC (permalink / raw)
  To: git; +Cc: gitster, Ping Yin

This patch introduces multi-level module definition and '--module-name'
option to designate submodules by logical names instead of path filters.
Then the init/update/status/add subcommand is enhanced combined with
this option.

The multi-level module definition in .gitmodules was first suggested by
Linus and etc. in mails "Let .git/config specify the url for submodules"
(http://article.gmane.org/gmane.comp.version-control.git/48939).

Following shows an example of such a .gitmodules which finally comes
from the group notation of 'git remote' which is suggested by Johannes
Schindelin.

.gitmodules with multiple level of indirection
------------------------------------------------------
[submodules]
	service = crawler search
	crawler = util imcrawter
	search = util imsearch
[submodule "util"]
	url = git://xyzzy/util.git
[submodule "imsearch"]
	path = search/imsearch
	url = git://xyzzy/imsearch.git
[submodule "imcrawler"]
	path = crawler/imcrawter
	url = git://xyzzy/imcrawter.git
------------------------------------------------------

By adding the 'submodules' section, we can define multi-level modules
in an infinite levels of indirection.

The "-m|--module-name" option is introduced with which submodules are
designated by logical names instead of real paths as following shows.

Identical commands forms with/without "--module-name"
---------------------------------------------------
$ git submodule XXX util imcrawler              (1)
$ git submodule XXX -m crawler                  (2)
$ git submodule XXX util imcrawler imsearch     (3)
$ git submodule XXX -m service                  (4)
$ git submodule XXX -m crawler search           (5)
---------------------------------------------------
* XXX represents status, update or init, but not add
* (1) and (2) are identical conditionally (explained below)
* (3), (4) and (5) are identical conditionally

There are still minor difference between these two forms.

In the no "--module-name" form, the path parameter may be not the real
submodule path, and it just acts as the filter for real submodule paths.
While in the "--module-name" form, the name parameter must be the logical
name, and the real paths corresponding to the logical name may be neither
a submodule path nor even existent.

This patch handles such a path for different subcommands as follows.

 - status: Output 0{40} as the sha1. Doing this can remind the user to
   add the path as submodule or delete the path from .gitmodules.
 - update: Skip that path and issue a "Not a submodule" warning
 - init: Also init for that path

So in the example above, commands (1) and (2) are identical only when
util and imcrawler are already submodules.

The add subcommand is also enhanced.

The former workflow to add submodules is adding one by one with
"git submodule add url path" which then modifies .gitmodules. However,
sometimes it is more convenient to work in the reverse way: edit
.gitmodules first and then add submodules in batch.

Now "git submodule add --module-name modulename" can help us to do that.
It will find all submodules corresponding to the logical name and add them
in batch by using the paths and urls from .gitmodules. Of course, it will
skip the paths which have already been submodules.

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index f3a1213..87d84fa 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 2007 Lars Hjemli
 
-USAGE="[--quiet] [--cached] \
+USAGE="[--quiet] [--cached] [--module-name] \
 [add <repo> [-b branch]|status|init|update|summary [-n|--summary-limit <n>] [<commit>]] \
 [--] [<path>...]"
 OPTIONS_SPEC=
@@ -15,6 +15,7 @@ command=
 branch=
 quiet=
 cached=
+use_module_name=
 
 #
 # print stuff on stdout unless -q was specified
@@ -97,12 +98,23 @@ module_name()
        echo "$name"
 }
 
+module_path() {
+	git config submodule.$1.path ||
+	GIT_CONFIG=.gitmodules git config submodule.$1.path ||
+	echo "$1"
+}
+
 module_url() {
 	git config submodule.$1.url ||
 	GIT_CONFIG=.gitmodules git config submodule.$1.url
 }
 
 module_info() {
+	if test -n "$use_module_name"
+	then
+		module_info_by_name "$@"
+		return
+	fi
 	git ls-files --stage -- "$@" | grep -e '^160000 ' |
 	while read mode sha1 stage path
 	do
@@ -118,6 +130,50 @@ module_info() {
 }
 
 #
+# List all submodule info line by line by given names as follows
+# sha1<tab>path<tab>name<tab>url
+#
+# Here we assume that module names and paths don't contain space
+# characters
+#
+# $@ = module names
+# When names is not given, list all module info
+#
+module_info_by_name() {
+	if test $# = 0
+	then
+		names=$(
+		{
+			git config --get-regexp 'submodule.*.url'
+			git config -f .gitmodules --get-regexp 'submodule.*.url'
+		} | sed 's/submodule.\(.*\).url .*$/\1/' 2>/dev/null
+		)
+	else
+		names=$(module_children_names "$@")
+	fi
+	for name in $names
+	do
+		url=$(module_url "$name") || continue
+		path=$(module_path "$name")
+		sha1=$(git ls-files --stage "$path" |
+			grep "$path$" | grep '^160000' | awk '{print $2}')
+		test -z "$sha1" && sha1=0000000000000000000000000000000000000000
+		echo "$sha1	$path	$name	$url"
+	done
+}
+
+module_children_names() {
+	for name
+	do
+		echo "$name"
+		module_children_names $(
+			git config "submodules.$name"
+			git config -f .gitmodules "submodules.$name"
+		)
+	done | sort -u
+}
+
+#
 # Clone a submodule
 #
 # Prior to calling, cmd_update checks that a possibly existing
@@ -233,7 +289,17 @@ cmd_add()
 		shift
 	done
 
-	module_add "$1" "$2"
+	if test -n "$use_module_name"
+	then
+		module_info "$@" |
+		while read sha1 path name url
+		do
+			module_add "$url" "$path"
+		done
+	else
+		module_add "$1" "$2"
+	fi
+
 }
 
 #
@@ -313,7 +379,11 @@ cmd_update()
 	while read sha1 path name url
 	do
 		test -n "$name" || exit
-		if test -z "$url"
+		if test $sha1 = 0000000000000000000000000000000000000000
+		then
+			say "Not a submodule: $name @ $path"
+			continue
+		elif test -z "$url"
 		then
 			# Only mention uninitialized submodules when its
 			# path have been specified
@@ -559,12 +629,15 @@ cmd_status()
 		esac
 		shift
 	done
-
 	module_info "$@" |
 	while read sha1 path name url
 	do
 		test -n "$name" || exit
-		if test -z "$url" || ! test -d "$path"/.git
+		if test $sha1 = 0000000000000000000000000000000000000000
+		then
+			say "*$sha1 $path"
+			continue
+		elif test -z "$url" || ! test -d "$path"/.git
 		then
 			say "-$sha1 $path"
 			continue;
@@ -610,6 +683,9 @@ do
 	--cached)
 		cached="$1"
 		;;
+	-m|--module-name)
+		use_module_name=1
+		;;
 	--)
 		break
 		;;
-- 
1.5.5.70.gd68a

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 6/7] git-submodule: "update --force" to enforce cloning non-submodule
  2008-04-16 14:19         ` [PATCH 5/7] git-submodule: multi-level module definition Ping Yin
@ 2008-04-16 14:19           ` Ping Yin
  2008-04-16 14:19             ` [PATCH 7/7] git-submodule: Don't die when command fails for one submodule Ping Yin
  0 siblings, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-16 14:19 UTC (permalink / raw)
  To: git; +Cc: gitster, Ping Yin

If the update subcommand combines with --force, instead of
issuing a "Not a submodule" warning for non-submodules, non-submodules
(i.e. modules existing in .gitmodules or $GIT_DIR/config but not added
to the super module) will also be cloned and the master branch will be
checked out.

However, if a non-submodule has already been cloned before, the update
will be rejected since we don't know what the update means.

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 87d84fa..ed6f698 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -361,6 +361,9 @@ cmd_update()
 		-q|--quiet)
 			quiet=1
 			;;
+		-f | --force)
+			force="$1"
+			;;
 		--)
 			shift
 			break
@@ -381,7 +384,8 @@ cmd_update()
 		test -n "$name" || exit
 		if test $sha1 = 0000000000000000000000000000000000000000
 		then
-			say "Not a submodule: $name @ $path"
+			test -z "$force" &&
+			say "Not a submodule: $name @ $path" &&
 			continue
 		elif test -z "$url"
 		then
@@ -395,8 +399,15 @@ cmd_update()
 		if ! test -d "$path"/.git
 		then
 			module_clone "$path" "$url" || exit
+			test "$sha1" = 0000000000000000000000000000000000000000 &&
+			(unset GIT_DIR; cd "$path" && git checkout -q master) &&
+			say "non-submodule cloned and master checked out: $name @ $path" &&
+			continue
 			subsha1=
 		else
+			test "$sha1" = 0000000000000000000000000000000000000000 &&
+			say "non-submodule already cloned: $name @ $path" &&
+			continue
 			subsha1=$(unset GIT_DIR; cd "$path" &&
 				git rev-parse --verify HEAD) ||
 			die "Unable to find current revision in submodule path '$path'"
-- 
1.5.5.70.gd68a

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 7/7] git-submodule: Don't die when command fails for one submodule
  2008-04-16 14:19           ` [PATCH 6/7] git-submodule: "update --force" to enforce cloning non-submodule Ping Yin
@ 2008-04-16 14:19             ` Ping Yin
  0 siblings, 0 replies; 19+ messages in thread
From: Ping Yin @ 2008-04-16 14:19 UTC (permalink / raw)
  To: git; +Cc: gitster, Ping Yin

When handling multiple modules, init/update/status/add subcommand will
exit when it fails for one submodule. This patch makes the subcommand
continue bypassing the failure and keep right exit status.

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh |   87 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 63 insertions(+), 24 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index ed6f698..0ecc4ff 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -193,15 +193,19 @@ module_clone()
 	# succeed but the rmdir will fail. We might want to fix this.
 	if test -d "$path"
 	then
-		rmdir "$path" 2>/dev/null ||
-		die "Directory '$path' exist, but is neither empty nor a git repository"
+		! rmdir "$path" 2>/dev/null &&
+		say "Directory '$path' exist, but is neither empty nor a git repository" &&
+		return 1
 	fi
 
 	test -e "$path" &&
-	die "A file already exist at path '$path'"
+	say "A file already exist at path '$path'" &&
+	return 1
 
-	git-clone -n "$url" "$path" ||
-	die "Clone of '$url' into submodule path '$path' failed"
+	! git-clone -n "$url" "$path" &&
+	say "Clone of '$url' into submodule path '$path' failed" &&
+	return 1
+	:
 }
 
 #
@@ -227,7 +231,8 @@ module_add() {
 	fi
 
 	git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
-	die "'$path' already exists in the index"
+	say "'$path' already exists in the index" &&
+	return 1
 
 	# perhaps the path exists and is already a git repo, else clone it
 	if test -e "$path"
@@ -237,21 +242,26 @@ module_add() {
 		then
 			echo "Adding existing repo at '$path' to the index"
 		else
-			die "'$path' already exists and is not a valid git repo"
+			say "'$path' already exists and is not a valid git repo"
+			return 1
 		fi
 	else
-		module_clone "$path" "$repo" || exit
-		(unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
-		die "Unable to checkout submodule '$path'"
+		module_clone "$path" "$repo" || return 1
+		! (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) &&
+		say "Unable to checkout submodule '$path'" &&
+		return 1
 	fi
 
-	git add "$path" ||
-	die "Failed to add submodule '$path'"
+	! git add "$path" &&
+	say "Failed to add submodule '$path'" &&
+	return 1
 
 	GIT_CONFIG=.gitmodules git config submodule."$path".path "$path" &&
 	GIT_CONFIG=.gitmodules git config submodule."$path".url "$repo" &&
-	git add .gitmodules ||
-	die "Failed to register submodule '$path'"
+	! git add .gitmodules &&
+	say "Failed to register submodule '$path'" &&
+	return 1
+	:
 }
 
 #
@@ -292,14 +302,17 @@ cmd_add()
 	if test -n "$use_module_name"
 	then
 		module_info "$@" |
+		{
+		exit_status=0
 		while read sha1 path name url
 		do
-			module_add "$url" "$path"
+			module_add "$url" "$path" || exit_status=1
 		done
+		test $exit_status = 0
+		}
 	else
 		module_add "$1" "$2"
 	fi
-
 }
 
 #
@@ -331,20 +344,30 @@ cmd_init()
 	done
 
 	module_info "$@" |
+	{
+	exit_status=0
 	while read sha1 path name url
 	do
-		test -n "$name" || exit
+		test -z "$name" && exit_status=1 && continue
 		test -z "$url" &&
-		die "No url found for submodule path '$path' in .gitmodules"
+		say "No url found for submodule path '$path' in .gitmodules" &&
+		exit_status=1 &&
+		continue
 		# Skip already registered paths
 		test -z "$(git config submodule.$name.url)" || continue
 
 		url=$(absolute_url "$url")
 		git config submodule."$name".url "$url" ||
-		die "Failed to register url for submodule path '$path'"
+		{
+		say "Failed to register url for submodule path '$path'"
+		exit_status=1
+		continue
+		}
 
 		say "Submodule '$name' ($url) registered for path '$path'"
 	done
+	exit $exit_status
+	}
 }
 
 #
@@ -379,9 +402,11 @@ cmd_update()
 	done
 
 	module_info "$@" |
+	{
+	exit_status=0
 	while read sha1 path name url
 	do
-		test -n "$name" || exit
+		test -z "$name" && exit_status=1 && continue
 		if test $sha1 = 0000000000000000000000000000000000000000
 		then
 			test -z "$force" &&
@@ -398,7 +423,7 @@ cmd_update()
 
 		if ! test -d "$path"/.git
 		then
-			module_clone "$path" "$url" || exit
+			! module_clone "$path" "$url" && exit_status=1 && continue
 			test "$sha1" = 0000000000000000000000000000000000000000 &&
 			(unset GIT_DIR; cd "$path" && git checkout -q master) &&
 			say "non-submodule cloned and master checked out: $name @ $path" &&
@@ -410,18 +435,28 @@ cmd_update()
 			continue
 			subsha1=$(unset GIT_DIR; cd "$path" &&
 				git rev-parse --verify HEAD) ||
-			die "Unable to find current revision in submodule path '$path'"
+			{
+				say "Unable to find current revision in submodule path '$path'"
+				exit_status=1
+				continue
+			}
 		fi
 
 		if test "$subsha1" != "$sha1"
 		then
 			(unset GIT_DIR; cd "$path" && git-fetch &&
 				git-checkout -q "$sha1") ||
-			die "Unable to checkout '$sha1' in submodule path '$path'"
+			{
+				say "Unable to checkout '$sha1' in submodule path '$path'"
+				exit_status=1
+				continue
+			}
 
 			say "Submodule path '$path': checked out '$sha1'"
 		fi
 	done
+	exit $exit_status
+	}
 }
 
 set_name_rev () {
@@ -641,9 +676,11 @@ cmd_status()
 		shift
 	done
 	module_info "$@" |
+	{
+	exit_status=0
 	while read sha1 path name url
 	do
-		test -n "$name" || exit
+		test -z "$name" && exit_status=1 && continue
 		if test $sha1 = 0000000000000000000000000000000000000000
 		then
 			say "*$sha1 $path"
@@ -666,6 +703,8 @@ cmd_status()
 			say "+$sha1 $path$revname"
 		fi
 	done
+	exit $exit_status
+	}
 }
 
 # This loop parses the command line arguments to find the
-- 
1.5.5.70.gd68a

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-16 14:19   ` [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin
  2008-04-16 14:19     ` [PATCH 3/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config Ping Yin
@ 2008-04-22  6:10     ` Junio C Hamano
  2008-04-22  6:50       ` Ping Yin
  2008-04-22  7:00       ` Ping Yin
  1 sibling, 2 replies; 19+ messages in thread
From: Junio C Hamano @ 2008-04-22  6:10 UTC (permalink / raw)
  To: Ping Yin; +Cc: git

Ping Yin <pkufranky@gmail.com> writes:

> Extract function absolute_url to remove code redundance and inconsistence in
> cmd_init and cmd_add when resolving relative url/path to absolute one.
>
> Also move resolving absolute url logic from cmd_add to module_clone which
> results in a litte behaviour change: cmd_update originally doesn't
> resolve absolute url but now it will.

Hmmm.  Somehow I find this unreadable and hard to parse.

> This behaviour change breaks t7400 which uses relative url './.subrepo'.
> However, this test originally doesn't mean to test relative url with './',
> so fix the url as '.subrepo'.

Isn't ".subrepo" a relative URL that says "subdirectory of the current
one, whose name is .subrepo", exactly the same way as "./.subrepo" is?
Shouldn't they behave the same?

If the test found they do not behave the same, perhaps the new code is
broken in some way and isn't "fixing" the test simply hiding a bug?

I dunno...

> +# Resolve relative url/path to absolute one
> +absolute_url () {
> +	case "$1" in
> +	./*|../*)
> +		# dereference source url relative to parent's url
> +		url="$(resolve_relative_url $1)" ;;
> +	*)
> +		# Turn the source into an absolute path if it is local
> +		url=$(get_repo_base "$1") ||
> +		url=$1
> +		;;
> +	esac
> +	echo "$url"
> +}
> +
>  #
>  # Map submodule path to submodule name
>  #
> @@ -112,7 +127,7 @@ module_info() {
>  module_clone()
>  {
>  	path=$1
> -	url=$2
> +	url=$(absolute_url "$2")
>  
>  	# If there already is a directory at the submodule path,
>  	# expect it to be empty (since that is the default checkout

Why does this call-site matter?  The URL is given to "git-clone" which I
think does handle the relative URL just fine???

> @@ -195,21 +210,7 @@ cmd_add()
>  			die "'$path' already exists and is not a valid git repo"
>  		fi
>  	else
> -		case "$repo" in
> -		./*|../*)
> -			# dereference source url relative to parent's url
> -			realrepo="$(resolve_relative_url $repo)" ;;
> -		*)
> -			# Turn the source into an absolute path if
> -			# it is local
> -			if base=$(get_repo_base "$repo"); then
> -				repo="$base"
> -			fi
> -			realrepo=$repo
> -			;;
> -		esac
> -
> -		module_clone "$path" "$realrepo" || exit
> +		module_clone "$path" "$repo" || exit
>  		(unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
>  		die "Unable to checkout submodule '$path'"
>  	fi

Ok.

> @@ -262,13 +263,7 @@ cmd_init()
>  		test -z "$url" &&
>  		die "No url found for submodule path '$path' in .gitmodules"
>  
> -		# Possibly a url relative to parent
> -		case "$url" in
> -		./*|../*)
> -			url="$(resolve_relative_url "$url")"
> -			;;
> -		esac
> -
> +		url=$(absolute_url "$url")
>  		git config submodule."$name".url "$url" ||
>  		die "Failed to register url for submodule path '$path'"

Ok.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-22  6:10     ` [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Junio C Hamano
@ 2008-04-22  6:50       ` Ping Yin
  2008-04-22  7:57         ` Junio C Hamano
  2008-04-22  7:00       ` Ping Yin
  1 sibling, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-22  6:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Tue, Apr 22, 2008 at 2:10 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Ping Yin <pkufranky@gmail.com> writes:
>  > This behaviour change breaks t7400 which uses relative url './.subrepo'.
>  > However, this test originally doesn't mean to test relative url with './',
>  > so fix the url as '.subrepo'.
>
>  Isn't ".subrepo" a relative URL that says "subdirectory of the current
>  one, whose name is .subrepo", exactly the same way as "./.subrepo" is?
>  Shouldn't they behave the same?
>
>  If the test found they do not behave the same, perhaps the new code is
>  broken in some way and isn't "fixing" the test simply hiding a bug?
>

I just want to unify the behaviour of handling relative url.

'git submodule add'  treats './foo' and 'foo' as different urls. The
1st one is relative to remote.origin.url, while the 2nd one is
relative the current directory. I think this kind of behaviour is
better for submodules, so i unify the handling of relative urls as
this.

With this kind of behaviour, i can set 'submodule.foo.url=./foo' in
.gitmodules or $GIT_DIR/config. And when remote.origin.url changes, i
have not to change submodule.foo.url if the super project and
submodule foo are always located on the same central host.

>
>  > +# Resolve relative url/path to absolute one
>  > +absolute_url () {
>  > +     case "$1" in
>  > +     ./*|../*)
>  > +             # dereference source url relative to parent's url
>  > +             url="$(resolve_relative_url $1)" ;;
>  > +     *)
>  > +             # Turn the source into an absolute path if it is local
>  > +             url=$(get_repo_base "$1") ||
>  > +             url=$1
>  > +             ;;
>  > +     esac
>  > +     echo "$url"
>  > +}
>  > +
>  >  #
>  >  # Map submodule path to submodule name
>  >  #
>  > @@ -112,7 +127,7 @@ module_info() {
>  >  module_clone()
>  >  {
>  >       path=$1
>  > -     url=$2
>  > +     url=$(absolute_url "$2")
>  >
>  >       # If there already is a directory at the submodule path,
>  >       # expect it to be empty (since that is the default checkout
>
>  Why does this call-site matter?  The URL is given to "git-clone" which I
>  think does handle the relative URL just fine???
>

As said above.



-- 
Ping Yin

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-22  6:10     ` [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Junio C Hamano
  2008-04-22  6:50       ` Ping Yin
@ 2008-04-22  7:00       ` Ping Yin
  1 sibling, 0 replies; 19+ messages in thread
From: Ping Yin @ 2008-04-22  7:00 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Tue, Apr 22, 2008 at 2:10 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Ping Yin <pkufranky@gmail.com> writes:
>
>  > Extract function absolute_url to remove code redundance and inconsistence in
>  > cmd_init and cmd_add when resolving relative url/path to absolute one.
>  >
>  > Also move resolving absolute url logic from cmd_add to module_clone which
>  > results in a litte behaviour change: cmd_update originally doesn't
>  > resolve absolute url but now it will.
>
>  Hmmm.  Somehow I find this unreadable and hard to parse.
>
>
>  > This behaviour change breaks t7400 which uses relative url './.subrepo'.
>  > However, this test originally doesn't mean to test relative url with './',
>  > so fix the url as '.subrepo'.
>
>  Isn't ".subrepo" a relative URL that says "subdirectory of the current
>  one, whose name is .subrepo", exactly the same way as "./.subrepo" is?
>  Shouldn't they behave the same?
>
>  If the test found they do not behave the same, perhaps the new code is
>  broken in some way and isn't "fixing" the test simply hiding a bug?
>
>  I dunno...
>
>
>  > +# Resolve relative url/path to absolute one
>  > +absolute_url () {
>  > +     case "$1" in
>  > +     ./*|../*)
>  > +             # dereference source url relative to parent's url
>  > +             url="$(resolve_relative_url $1)" ;;
>  > +     *)
>  > +             # Turn the source into an absolute path if it is local
>  > +             url=$(get_repo_base "$1") ||
>  > +             url=$1
>  > +             ;;
>  > +     esac
>  > +     echo "$url"
>  > +}
>  > +
>  >  #
>  >  # Map submodule path to submodule name
>  >  #
>  > @@ -112,7 +127,7 @@ module_info() {
>  >  module_clone()
>  >  {
>  >       path=$1
>  > -     url=$2
>  > +     url=$(absolute_url "$2")
>  >
>  >       # If there already is a directory at the submodule path,
>  >       # expect it to be empty (since that is the default checkout
>
>  Why does this call-site matter?  The URL is given to "git-clone" which I
>  think does handle the relative URL just fine???
>

>  Hmmm.  Doesn't "foo" generally mean the same thing as "./foo" in the sense
>  both are relative to the current directory?

Following was my answer days ago

There is a little inconsistence in current logic

1. git submodule add ./foo will expand foo with remote.origin.url and
    init an entry in .gitmodules as "submodule.foo.url=$remoteoriginurl/foo"
2. git submodule update will not expand ./foo if  there is an entry
    "submodule.foo.url=./foo"  in $GIT_DIR/config

I tend to add the url as is when "git submodule add", and then expand
the url when running "git submodule update". So this will result that
the second case expands './foo' as "$remoteoriginurl/foo" instead of
"foo".

And this is the reason i expand './foo' in module_clone.

-- 
Ping Yin

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-22  6:50       ` Ping Yin
@ 2008-04-22  7:57         ` Junio C Hamano
  2008-04-22  9:09           ` Ping Yin
  0 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2008-04-22  7:57 UTC (permalink / raw)
  To: Ping Yin; +Cc: git

"Ping Yin" <pkufranky@gmail.com> writes:

> I just want to unify the behaviour of handling relative url.
>
> 'git submodule add'  treats './foo' and 'foo' as different urls. The
> 1st one is relative to remote.origin.url, while the 2nd one is
> relative the current directory. I think this kind of behaviour is
> better for submodules, so i unify the handling of relative urls as
> this.
>
> With this kind of behaviour, i can set 'submodule.foo.url=./foo' in
> .gitmodules or $GIT_DIR/config. And when remote.origin.url changes, i
> have not to change submodule.foo.url if the super project and
> submodule foo are always located on the same central host.

Please have that kind of justification in the proposed commit log message.
When these changes are made into history, people cannot ask you questions
like I did and expect the history to produce such answer on demand ;-)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-22  7:57         ` Junio C Hamano
@ 2008-04-22  9:09           ` Ping Yin
  2008-04-22 14:38             ` Ping Yin
  0 siblings, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-22  9:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Tue, Apr 22, 2008 at 3:57 PM, Junio C Hamano <gitster@pobox.com> wrote:
> "Ping Yin" <pkufranky@gmail.com> writes:
>
>
> > I just want to unify the behaviour of handling relative url.
>  >
>  > 'git submodule add'  treats './foo' and 'foo' as different urls. The
>  > 1st one is relative to remote.origin.url, while the 2nd one is
>  > relative the current directory. I think this kind of behaviour is
>  > better for submodules, so i unify the handling of relative urls as
>  > this.
>  >
>  > With this kind of behaviour, i can set 'submodule.foo.url=./foo' in
>  > .gitmodules or $GIT_DIR/config. And when remote.origin.url changes, i
>  > have not to change submodule.foo.url if the super project and
>  > submodule foo are always located on the same central host.
>
>  Please have that kind of justification in the proposed commit log message.
>  When these changes are made into history, people cannot ask you questions
>  like I did and expect the history to produce such answer on demand ;-)
>

OK, i'll resend this patch tonight.

-- 
Ping Yin

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-22  9:09           ` Ping Yin
@ 2008-04-22 14:38             ` Ping Yin
  2008-04-22 14:41               ` Ping Yin
  0 siblings, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-22 14:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 319 bytes --]

>  >  Please have that kind of justification in the proposed commit log message.
>  >  When these changes are made into history, people cannot ask you questions
>  >  like I did and expect the history to produce such answer on demand ;-)
>  >
>
>  OK, i'll resend this patch tonight.

See attached patch


-- 
Ping Yin

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-git-submodule-Fix-inconsistent-handling-of-relative.patch --]
[-- Type: text/x-patch; name=0002-git-submodule-Fix-inconsistent-handling-of-relative.patch, Size: 4143 bytes --]

From f89b08edaa44f89a534dcb4fc17344ea49c5dadb Mon Sep 17 00:00:00 2001
From: Ping Yin <pkufranky@gmail.com>
Date: Thu, 13 Mar 2008 00:09:57 +0800
Subject: [PATCH 2/7] git-submodule: Fix inconsistent handling of relative urls with './' prefix

There is a little inconsistence in current handling of relative url
with "./"

- "git submodule add ./foo" will clone the submodule with url
  "${remote.origin.url}/foo" and init an entry 'submodule.foo.url=./foo"
  in .gitmodules

- "git submodule init" will init an entry in $GIT_DIR/config as
  "submodule.foo.url=${remote.origin.url}/foo"

- However, if there is an entry "submodule.foo.url=./foo" in
  $GIT_DIR/config, "git submodule update" will not expand
  "./foo" with remote.origin.url

This patch unifies the behaviour of handling relative urls with './'
prefix. Now "git submodule init" copies urls from .gitmodules to
$GIT_DIR/config as is without expanding. And the url expanding happens
only at runtime, say when "git submodule add" or "git submodule update".

absolute_url is extracted to remove code redundance and fix inconsistence
in cmd_init and cmd_add when resolving relative url/path to absolute one.

Also move resolving absolute url logic from cmd_add to module_clone which
results in the expected behaviour change: cmd_update will resolve url
'./foo' in $GIT_DIR/config as "${remote.origin.url}/foo" instead of
"$(pwd)/foo".

This behaviour change breaks t7400 which uses relative url './.subrepo'.
However, this test originally doesn't mean to test relative url with './'
prefix, so fix the url as '.subrepo'.

Signed-off-by: Ping Yin <pkufranky@gmail.com>
---
 git-submodule.sh           |   41 ++++++++++++++++++-----------------------
 t/t7400-submodule-basic.sh |    2 +-
 2 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index e71e1f0..198ea44 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -65,6 +65,21 @@ resolve_relative_url ()
 	echo "$remoteurl/$url"
 }
 
+# Resolve relative url/path to absolute one
+absolute_url () {
+	case "$1" in
+	./*|../*)
+		# dereference source url relative to parent's url
+		url="$(resolve_relative_url $1)" ;;
+	*)
+		# Turn the source into an absolute path if it is local
+		url=$(get_repo_base "$1") ||
+		url=$1
+		;;
+	esac
+	echo "$url"
+}
+
 #
 # Map submodule path to submodule name
 #
@@ -112,7 +127,7 @@ module_info() {
 module_clone()
 {
 	path=$1
-	url=$2
+	url=$(absolute_url "$2")
 
 	# If there already is a directory at the submodule path,
 	# expect it to be empty (since that is the default checkout
@@ -195,21 +210,7 @@ cmd_add()
 			die "'$path' already exists and is not a valid git repo"
 		fi
 	else
-		case "$repo" in
-		./*|../*)
-			# dereference source url relative to parent's url
-			realrepo="$(resolve_relative_url $repo)" ;;
-		*)
-			# Turn the source into an absolute path if
-			# it is local
-			if base=$(get_repo_base "$repo"); then
-				repo="$base"
-			fi
-			realrepo=$repo
-			;;
-		esac
-
-		module_clone "$path" "$realrepo" || exit
+		module_clone "$path" "$repo" || exit
 		(unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
 		die "Unable to checkout submodule '$path'"
 	fi
@@ -262,13 +263,7 @@ cmd_init()
 		test -z "$url" &&
 		die "No url found for submodule path '$path' in .gitmodules"
 
-		# Possibly a url relative to parent
-		case "$url" in
-		./*|../*)
-			url="$(resolve_relative_url "$url")"
-			;;
-		esac
-
+		url=$(absolute_url "$url")
 		git config submodule."$name".url "$url" ||
 		die "Failed to register url for submodule path '$path'"
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 2ef85a8..e5d59b8 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -75,7 +75,7 @@ test_expect_success 'init should register submodule url in .git/config' '
 	then
 		echo "[OOPS] init succeeded but submodule url is wrong"
 		false
-	elif ! git config submodule.example.url ./.subrepo
+	elif ! git config submodule.example.url .subrepo
 	then
 		echo "[OOPS] init succeeded but update of url failed"
 		false
-- 
1.5.5.70.gd68a


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-22 14:38             ` Ping Yin
@ 2008-04-22 14:41               ` Ping Yin
       [not found]                 ` <alpine.DEB.1.00.0804221609200.4460@eeepc-johanness>
  0 siblings, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-22 14:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Tue, Apr 22, 2008 at 10:38 PM, Ping Yin <pkufranky@gmail.com> wrote:
> >  >  Please have that kind of justification in the proposed commit log message.
>  >  >  When these changes are made into history, people cannot ask you questions
>  >  >  like I did and expect the history to produce such answer on demand ;-)
>  >  >
>  >
>  >  OK, i'll resend this patch tonight.
>
>  See attached patch

Only the commit message changes.


git-submodule: Fix inconsistent handling of relative urls with './' prefix

There is a little inconsistence in current handling of relative url
with "./"

- "git submodule add ./foo" will clone the submodule with url
  "${remote.origin.url}/foo" and init an entry 'submodule.foo.url=./foo"
  in .gitmodules

- "git submodule init" will init an entry in $GIT_DIR/config as
  "submodule.foo.url=${remote.origin.url}/foo"

- However, if there is an entry "submodule.foo.url=./foo" in
  $GIT_DIR/config, "git submodule update" will not expand
  "./foo" with remote.origin.url

This patch unifies the behaviour of handling relative urls with './'
prefix. Now "git submodule init" copies urls from .gitmodules to
$GIT_DIR/config as is without expanding. And the url expanding happens
only at runtime, say when "git submodule add" or "git submodule update".

absolute_url is extracted to remove code redundance and fix inconsistence
in cmd_init and cmd_add when resolving relative url/path to absolute one.

Also move resolving absolute url logic from cmd_add to module_clone which
results in the expected behaviour change: cmd_update will resolve url
'./foo' in $GIT_DIR/config as "${remote.origin.url}/foo" instead of
"$(pwd)/foo".

This behaviour change breaks t7400 which uses relative url './.subrepo'.
However, this test originally doesn't mean to test relative url with './'
prefix, so fix the url as '.subrepo'.



-- 
Ping Yin

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
       [not found]                 ` <alpine.DEB.1.00.0804221609200.4460@eeepc-johanness>
@ 2008-04-22 16:54                   ` Ping Yin
  2008-04-22 17:13                     ` Jakub Narebski
  0 siblings, 1 reply; 19+ messages in thread
From: Ping Yin @ 2008-04-22 16:54 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Git Mailing List

On Tue, Apr 22, 2008 at 11:10 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> Hi Ping,
>
>
>  On Tue, 22 Apr 2008, Ping Yin wrote:
>
>  > On Tue, Apr 22, 2008 at 10:38 PM, Ping Yin <pkufranky@gmail.com> wrote:
>  > > >  >  Please have that kind of justification in the proposed commit log message.
>  > >  >  >  When these changes are made into history, people cannot ask you questions
>  > >  >  >  like I did and expect the history to produce such answer on demand ;-)
>  > >  >  >
>  > >  >
>  > >  >  OK, i'll resend this patch tonight.
>  > >
>  > >  See attached patch
>  >
>  > Only the commit message changes.
>  >
>  > [... only the commit message ...]
>
>  Do you realize how much work you make Junio do?  It would be definitely
>  better if you tried to relieve him of as much burden as you can.

I'm sorry about that. It's just because that i don't have a mail
client at hand. I use gmail which will wrap lines. And if i use
git-sendmail, i can't send this message as a reply to previous
messages.

So, any better way?

-- 
Ping Yin

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-22 16:54                   ` Ping Yin
@ 2008-04-22 17:13                     ` Jakub Narebski
  2008-04-22 17:20                       ` Ping Yin
  0 siblings, 1 reply; 19+ messages in thread
From: Jakub Narebski @ 2008-04-22 17:13 UTC (permalink / raw)
  To: Ping Yin; +Cc: Johannes Schindelin, Git Mailing List

"Ping Yin" <pkufranky@gmail.com> writes:

> On Tue, Apr 22, 2008 at 11:10 PM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
>>  On Tue, 22 Apr 2008, Ping Yin wrote:
[...]
>>> Only the commit message changes.
>>>
>>> [... only the commit message ...]
>>
>>  Do you realize how much work you make Junio do?  It would be definitely
>>  better if you tried to relieve him of as much burden as you can.
> 
> I'm sorry about that. It's just because that i don't have a mail
> client at hand. I use gmail which will wrap lines. And if i use
> git-sendmail, i can't send this message as a reply to previous
> messages.

Errr, '--in-reply-to' option to git-send-email?

Or find some mail client...
-- 
Jakub Narebski
Poland
ShadeHawk on #git

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone
  2008-04-22 17:13                     ` Jakub Narebski
@ 2008-04-22 17:20                       ` Ping Yin
  0 siblings, 0 replies; 19+ messages in thread
From: Ping Yin @ 2008-04-22 17:20 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Johannes Schindelin, Git Mailing List

On Wed, Apr 23, 2008 at 1:13 AM, Jakub Narebski <jnareb@gmail.com> wrote:
> "Ping Yin" <pkufranky@gmail.com> writes:
>
>  > On Tue, Apr 22, 2008 at 11:10 PM, Johannes Schindelin
>  > <Johannes.Schindelin@gmx.de> wrote:
>
> >>  On Tue, 22 Apr 2008, Ping Yin wrote:
>  [...]
>
> >>> Only the commit message changes.
>  >>>
>  >>> [... only the commit message ...]
>  >>
>  >>  Do you realize how much work you make Junio do?  It would be definitely
>  >>  better if you tried to relieve him of as much burden as you can.
>  >
>  > I'm sorry about that. It's just because that i don't have a mail
>  > client at hand. I use gmail which will wrap lines. And if i use
>  > git-sendmail, i can't send this message as a reply to previous
>  > messages.
>
>  Errr, '--in-reply-to' option to git-send-email?
>
3x, i think this makes sense.


-- 
Ping Yin

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2008-04-22 17:21 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-16 14:19 [PATCH 0/7] submodule: fallback to .gitmodules and multiple level module definition Ping Yin
2008-04-16 14:19 ` [PATCH 1/7] git-submodule: Extract functions module_info and module_url Ping Yin
2008-04-16 14:19   ` [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin
2008-04-16 14:19     ` [PATCH 3/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config Ping Yin
2008-04-16 14:19       ` [PATCH 4/7] git-submodule: Extract module_add from cmd_add Ping Yin
2008-04-16 14:19         ` [PATCH 5/7] git-submodule: multi-level module definition Ping Yin
2008-04-16 14:19           ` [PATCH 6/7] git-submodule: "update --force" to enforce cloning non-submodule Ping Yin
2008-04-16 14:19             ` [PATCH 7/7] git-submodule: Don't die when command fails for one submodule Ping Yin
2008-04-22  6:10     ` [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Junio C Hamano
2008-04-22  6:50       ` Ping Yin
2008-04-22  7:57         ` Junio C Hamano
2008-04-22  9:09           ` Ping Yin
2008-04-22 14:38             ` Ping Yin
2008-04-22 14:41               ` Ping Yin
     [not found]                 ` <alpine.DEB.1.00.0804221609200.4460@eeepc-johanness>
2008-04-22 16:54                   ` Ping Yin
2008-04-22 17:13                     ` Jakub Narebski
2008-04-22 17:20                       ` Ping Yin
2008-04-22  7:00       ` Ping Yin
  -- strict thread matches above, loose matches on Subject: below --
2008-03-13 17:56 [PATCH 0/7] git-submodule enhancements Ping Yin
2008-03-13 17:56 ` [PATCH 1/7] git-submodule: Avoid 'fatal: cannot describe' message Ping Yin
2008-03-13 17:56   ` [PATCH 2/7] git-submodule: Extract functions module_info and module_url Ping Yin
2008-03-13 17:56     ` [PATCH 3/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin
2008-03-13 17:56       ` [PATCH 4/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config Ping Yin
2008-03-13 17:56         ` [PATCH 5/7] git-submodule: Extract module_add from cmd_add Ping Yin
2008-03-13 17:56           ` [PATCH 6/7] git-submodule: multi-level module definition Ping Yin
2008-03-13 17:56             ` [PATCH 7/7] git-submodule: Don't die when command fails for one submodule Ping Yin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).