Skip to contentSkip to conversation

Add --reference option to git submodule

PATCH In review Michael S. Tsirkin 2 participants 5 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add --reference option to git submodule

This adds --reference option to 'git submodule add' and
'git submodule update' commands, which is passed on to git clone. This option is useful when the submodule is large, such as linux kernel.

---

I noticed that there's no easy way to specify a reference for submodule repositories. Here's a patch to add this option.

 Documentation/git-submodule.txt |   14 ++++++++++++--
 git-submodule.sh                |   31 ++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 5 deletions(-)
Documentation/git-submodule.txt +12 -2
index 3b8df44..0584cb7 100644
@@ -9,10 +9,12 @@ git-submodule - Initialize, update or inspect submodules
 SYNOPSIS
 --------
 [verse]
-'git submodule' [--quiet] add [-b branch] [--] <repository> <path>
+'git submodule' [--quiet] add [-b branch]
+	      [--reference <repository>] [--] <repository> <path>
 'git submodule' [--quiet] status [--cached] [--] [<path>...]
 'git submodule' [--quiet] init [--] [<path>...]
-'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--] [<path>...]
+'git submodule' [--quiet] update [--init] [-N|--no-fetch]
+	      [--reference <repository>] [--] [<path>...]
 'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]
 'git submodule' [--quiet] foreach <command>
 'git submodule' [--quiet] sync [--] [<path>...]
@@ -177,6 +179,14 @@ OPTIONS
 	This option is only valid for the update command.
 	Don't fetch new objects from the remote site.
 
+--reference <repository>::
+	This option is only valid for add and update commands.  These
+	commands sometimes need to clone a remote repository. In this case,
+	this option will be passed to linkgit:git-clone[1] command.
++
+*NOTE*: Do *not* use this option unless you have read the note
+for linkgit:git-clone[1] --reference and --shared options carefully.
+
 <path>...::
 	Paths to submodule(s). When specified this will restrict the command
 	to only operate on the submodules found at the specified paths.
git-submodule.sh +28 -3
index 8e234a4..32be246 100755
@@ -15,6 +15,7 @@ require_work_tree
 command=
 branch=
 quiet=
+reference=
 cached=
 nofetch=
 
@@ -91,6 +92,7 @@ module_clone()
 {
 	path=$1
 	url=$2
+	reference="$3"
 
 	# If there already is a directory at the submodule path,
 	# expect it to be empty (since that is the default checkout
@@ -106,7 +108,12 @@ module_clone()
 	test -e "$path" &&
 	die "A file already exist at path '$path'"
 
-	git-clone -n "$url" "$path" ||
+	if test "reference"
+	then
+		git-clone "$reference" -n "$url" "$path"
+	else
+		git-clone -n "$url" "$path"
+	fi ||
 	die "Clone of '$url' into submodule path '$path' failed"
 }
 
@@ -131,6 +138,15 @@ cmd_add()
 		-q|--quiet)
 			quiet=1
 			;;
+		--reference)
+			case "$2" in '') usage ;; esac
+			reference="--reference=$2"
+			shift
+			;;
+		--reference=*)
+			reference="$1"
+			shift
+			;;
 		--)
 			shift
 			break
@@ -203,7 +219,7 @@ cmd_add()
 		git config submodule."$path".url "$url"
 	else
 
-		module_clone "$path" "$realrepo" || exit
+		module_clone "$path" "$realrepo" "$reference" || exit
 		(
 			unset GIT_DIR
 			cd "$path" &&
@@ -321,6 +337,15 @@ cmd_update()
 			shift
 			nofetch=1
 			;;
+		--reference)
+			case "$2" in '') usage ;; esac
+			reference="$2"
+			shift 2
+			;;
+		--reference=*)
+			reference="$1"
+			shift
+			;;
 		--)
 			shift
 			break
@@ -351,7 +376,7 @@ cmd_update()
 
 		if ! test -d "$path"/.git -o -f "$path"/.git
 		then
-			module_clone "$path" "$url" || exit
+			module_clone "$path" "$url" "$reference"|| exit
 			subsha1=
 		else
 			subsha1=$(unset GIT_DIR; cd "$path" &&
Signature · 1 line
1.6.3.rc3.dirty
#1 lore raw

Michael S. Tsirkin venit, vidit, dixit 28.04.2009 08:52:

Quoted 9 lines

This adds --reference option to 'git submodule add' and
'git submodule update' commands, which is passed on to git clone. This option is useful when the submodule is large, such as linux kernel.

---

I noticed that there's no easy way to specify a reference for submodule repositories. Here's a patch to add this option.

Certainly useful. Just a few suggestions:

Quoted 25 lines
 Documentation/git-submodule.txt |   14 ++++++++++++--
 git-submodule.sh                |   31 ++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 5 deletions(-)
Documentation/git-submodule.txt +4 -2
index 3b8df44..0584cb7 100644
@@ -9,10 +9,12 @@ git-submodule - Initialize, update or inspect submodules
 SYNOPSIS
 --------
 [verse]
-'git submodule' [--quiet] add [-b branch] [--] <repository> <path>
+'git submodule' [--quiet] add [-b branch]
+	      [--reference <repository>] [--] <repository> <path>
 'git submodule' [--quiet] status [--cached] [--] [<path>...]
 'git submodule' [--quiet] init [--] [<path>...]
-'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--] [<path>...]
+'git submodule' [--quiet] update [--init] [-N|--no-fetch]
+	      [--reference <repository>] [--] [<path>...]
 'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]
 'git submodule' [--quiet] foreach <command>
 'git submodule' [--quiet] sync [--] [<path>...]

Documentation/git-submodule.txt OPTIONS · line 183

Quoted 5 lines
Documentation/git-submodule.txt +2 -0
@@ -177,6 +179,14 @@ OPTIONS
 	This option is only valid for the update command.
 	Don't fetch new objects from the remote site.
 
+--reference <repository>::
+	This option is only valid for add and update commands.  These

This option applies only to add...

Documentation/git-submodule.txt OPTIONS · line 185

Quoted 2 lines
Documentation/git-submodule.txt +2 -0
+	commands sometimes need to clone a remote repository. In this case,
+	this option will be passed to linkgit:git-clone[1] command.

...to the...

Documentation/git-submodule.txt OPTIONS · line 188

Quoted 3 lines
Documentation/git-submodule.txt +3 -0
++
+*NOTE*: Do *not* use this option unless you have read the note
+for linkgit:git-clone[1] --reference and --shared options carefully.

...clone[1]\'s --reference...

Documentation/git-submodule.txt OPTIONS · line 191

Quoted 3 lines
Documentation/git-submodule.txt +1 -0
+
 <path>...::
 	Paths to submodule(s). When specified this will restrict the command

Either "Path(s) to submodule(s)" or "Paths to submodules". I prefer the latter.

Documentation/git-submodule.txt OPTIONS · line 192

Quoted 1 line
Documentation/git-submodule.txt +0 -0
 	to only operate on the submodules found at the specified paths.

..to operate on... paths only.

Quoted 21 lines
git-submodule.sh +2 -0
index 8e234a4..32be246 100755
@@ -15,6 +15,7 @@ require_work_tree
 command=
 branch=
 quiet=
+reference=
 cached=
 nofetch=
 
@@ -91,6 +92,7 @@ module_clone()
 {
 	path=$1
 	url=$2
+	reference="$3"
 
 	# If there already is a directory at the submodule path,
 	# expect it to be empty (since that is the default checkout

git-submodule.sh module_clone() · line 111

Quoted 5 lines
git-submodule.sh +1 -1
@@ -106,7 +108,12 @@ module_clone()
 	test -e "$path" &&
 	die "A file already exist at path '$path'"
 
-	git-clone -n "$url" "$path" ||
+	if test "reference"

I'm sure you want to test $reference here. I'm not sure how portable testing for non-empty without -n is.

Quoted 50 lines
git-submodule.sh +24 -1
+	then
+		git-clone "$reference" -n "$url" "$path"
+	else
+		git-clone -n "$url" "$path"
+	fi ||
 	die "Clone of '$url' into submodule path '$path' failed"
 }
 
@@ -131,6 +138,15 @@ cmd_add()
 		-q|--quiet)
 			quiet=1
 			;;
+		--reference)
+			case "$2" in '') usage ;; esac
+			reference="--reference=$2"
+			shift
+			;;
+		--reference=*)
+			reference="$1"
+			shift
+			;;
 		--)
 			shift
 			break
@@ -203,7 +219,7 @@ cmd_add()
 		git config submodule."$path".url "$url"
 	else
 
-		module_clone "$path" "$realrepo" || exit
+		module_clone "$path" "$realrepo" "$reference" || exit
 		(
 			unset GIT_DIR
 			cd "$path" &&
@@ -321,6 +337,15 @@ cmd_update()
 			shift
 			nofetch=1
 			;;
+		--reference)
+			case "$2" in '') usage ;; esac
+			reference="$2"
+			shift 2
+			;;
+		--reference=*)
+			reference="$1"
+			shift
+			;;
 		--)
 			shift
 			break

git-submodule.sh cmd_update() · line 382

Quoted 8 lines
git-submodule.sh +1 -1
@@ -351,7 +376,7 @@ cmd_update()
 
 		if ! test -d "$path"/.git -o -f "$path"/.git
 		then
-			module_clone "$path" "$url" || exit
+			module_clone "$path" "$url" "$reference"|| exit
 			subsha1=
 		else
 			subsha1=$(unset GIT_DIR; cd "$path" &&

Cheers,
Michael

#2 lore raw
Quoted 11 lines · Michael J Gruber

Documentation/git-submodule.txt OPTIONS · line 191

Quoted 3 lines
Documentation/git-submodule.txt +1 -0
+
 <path>...::
 	Paths to submodule(s). When specified this will restrict the command

Either "Path(s) to submodule(s)" or "Paths to submodules". I prefer the latter.

Quoted 1 line

to only operate on the submodules found at the specified paths.

..to operate on... paths only.

I didn't touch these lines, so ... patch?

Signature · 1 line
MST
#3 lore raw

Michael S. Tsirkin venit, vidit, dixit 28.04.2009 13:25:

Quoted 8 lines · Michael J Gruber
Quoted 7 lines

Documentation/git-submodule.txt OPTIONS · line 191

Quoted 3 lines
Documentation/git-submodule.txt +1 -0
+
 <path>...::
 	Paths to submodule(s). When specified this will restrict the command

Either "Path(s) to submodule(s)" or "Paths to submodules". I prefer the latter.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

to only operate on the submodules found at the specified paths.

..to operate on... paths only.

I didn't touch these lines, so ... patch?

You're right, they were only context (I got hyperactive it seems). It's better to leave that for an overall style spring clean.

Michael

#4 lore raw
In reply to Michael J Gruber
Quoted 8 lines · Michael J Gruber

Documentation/git-submodule.txt OPTIONS · line 183

Quoted 6 lines
Documentation/git-submodule.txt +2 -0
@@ -177,6 +179,14 @@ OPTIONS
 	This option is only valid for the update command.
 	Don't fetch new objects from the remote site.
 
+--reference <repository>::
+	This option is only valid for add and update commands.  These

This option applies only to add...

The rest of the documentation has 'is only valid' language. I guess we need to be consistent? Rewrite these as well?

Signature · 1 line
MST