* [PATCHv2] Add --reference option to git submodule.
@ 2009-04-28 12:30 Michael S. Tsirkin
2009-04-28 13:21 ` Michael J Gruber
0 siblings, 1 reply; 6+ messages in thread
From: Michael S. Tsirkin @ 2009-04-28 12:30 UTC (permalink / raw)
To: git, Junio C Hamano, Michael J Gruber
This adds --reference option to git submodule add and
git submodule update commands, which is passed on to git clone.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
Here's v2. Ack?
Changes from v1: fixes in documentation, fix test usage and
make it portable.
Documentation/git-submodule.txt | 14 ++++++++++++--
git-submodule.sh | 31 ++++++++++++++++++++++++++++---
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 3b8df44..14256c6 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -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 the linkgit:git-clone[1] command.
++
+*NOTE*: Do *not* use this option unless you have read the note
+for linkgit:git-clone[1]'s --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.
diff --git a/git-submodule.sh b/git-submodule.sh
index 8e234a4..4989d86 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -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 -n "$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" &&
--
1.6.3.rc3.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCHv2] Add --reference option to git submodule.
2009-04-28 12:30 [PATCHv2] Add --reference option to git submodule Michael S. Tsirkin
@ 2009-04-28 13:21 ` Michael J Gruber
2009-04-28 14:51 ` Johannes Sixt
2009-04-28 18:52 ` Junio C Hamano
0 siblings, 2 replies; 6+ messages in thread
From: Michael J Gruber @ 2009-04-28 13:21 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: git, Junio C Hamano
Michael S. Tsirkin venit, vidit, dixit 28.04.2009 14:30:
> This adds --reference option to git submodule add and
> git submodule update commands, which is passed on to git clone.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>
> Here's v2. Ack?
I don't think it's up to me to Ack but you addressed my remarks.
BTW, even dash has "test STRING" so portability doesn't require -n but I
think it's OK either way.
Just be prepared in case someone asks for a test script ;)
Michael
>
> Changes from v1: fixes in documentation, fix test usage and
> make it portable.
>
> Documentation/git-submodule.txt | 14 ++++++++++++--
> git-submodule.sh | 31 ++++++++++++++++++++++++++++---
> 2 files changed, 40 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
> index 3b8df44..14256c6 100644
> --- a/Documentation/git-submodule.txt
> +++ b/Documentation/git-submodule.txt
> @@ -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 the linkgit:git-clone[1] command.
> ++
> +*NOTE*: Do *not* use this option unless you have read the note
> +for linkgit:git-clone[1]'s --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.
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 8e234a4..4989d86 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -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 -n "$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" &&
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCHv2] Add --reference option to git submodule.
2009-04-28 13:21 ` Michael J Gruber
@ 2009-04-28 14:51 ` Johannes Sixt
2009-04-28 17:01 ` Michael J Gruber
2009-04-28 18:52 ` Junio C Hamano
1 sibling, 1 reply; 6+ messages in thread
From: Johannes Sixt @ 2009-04-28 14:51 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Michael S. Tsirkin, git, Junio C Hamano
Michael J Gruber schrieb:
> BTW, even dash has "test STRING" so portability doesn't require -n but I
> think it's OK either way.
It is not if STRING is user input; it could be, e.g., '-f', and then the
command gives a syntax error because of a missing argument.
It's safer to use test -z and test -n unless the string to test is
completely under the control of the script.
-- Hannes
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv2] Add --reference option to git submodule.
2009-04-28 14:51 ` Johannes Sixt
@ 2009-04-28 17:01 ` Michael J Gruber
0 siblings, 0 replies; 6+ messages in thread
From: Michael J Gruber @ 2009-04-28 17:01 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Michael S. Tsirkin, git, Junio C Hamano
Johannes Sixt venit, vidit, dixit 28.04.2009 16:51:
> Michael J Gruber schrieb:
>> BTW, even dash has "test STRING" so portability doesn't require -n but I
>> think it's OK either way.
>
> It is not if STRING is user input; it could be, e.g., '-f', and then the
> command gives a syntax error because of a missing argument.
>
> It's safer to use test -z and test -n unless the string to test is
> completely under the control of the script.
Yep, that's true as a general rule. Here it's always preceeded by
"--reference=". But in any case I'm happy I suggested -n and it's in ;)
Michael
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv2] Add --reference option to git submodule.
2009-04-28 13:21 ` Michael J Gruber
2009-04-28 14:51 ` Johannes Sixt
@ 2009-04-28 18:52 ` Junio C Hamano
2009-05-04 17:57 ` Michael S. Tsirkin
1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2009-04-28 18:52 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Michael S. Tsirkin, git
Michael J Gruber <git@drmicha.warpmail.net> writes:
> Michael S. Tsirkin venit, vidit, dixit 28.04.2009 14:30:
>> This adds --reference option to git submodule add and
>> git submodule update commands, which is passed on to git clone.
>>
>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>> ---
>>
>> Here's v2. Ack?
>
> I don't think it's up to me to Ack but you addressed my remarks.
You can certainly say "Reviewed-by: me" and/or "Tested-by: me".
> BTW, even dash has "test STRING" so portability doesn't require -n but I
> think it's OK either way.
It always is a good discipline and style.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv2] Add --reference option to git submodule.
2009-04-28 18:52 ` Junio C Hamano
@ 2009-05-04 17:57 ` Michael S. Tsirkin
0 siblings, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2009-05-04 17:57 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Michael J Gruber, git
On Tue, Apr 28, 2009 at 11:52:09AM -0700, Junio C Hamano wrote:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
>
> > Michael S. Tsirkin venit, vidit, dixit 28.04.2009 14:30:
> >> This adds --reference option to git submodule add and
> >> git submodule update commands, which is passed on to git clone.
> >>
> >> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >> ---
> >>
> >> Here's v2. Ack?
> >
> > I don't think it's up to me to Ack but you addressed my remarks.
>
> You can certainly say "Reviewed-by: me" and/or "Tested-by: me".
So ... Junio, what do you think about the patch?
--
MST
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-05-04 18:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-28 12:30 [PATCHv2] Add --reference option to git submodule Michael S. Tsirkin
2009-04-28 13:21 ` Michael J Gruber
2009-04-28 14:51 ` Johannes Sixt
2009-04-28 17:01 ` Michael J Gruber
2009-04-28 18:52 ` Junio C Hamano
2009-05-04 17:57 ` Michael S. Tsirkin
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 NNTP newsgroup(s).