* [PATCHv3] Add --reference option to git submodule.
@ 2009-05-04 19:30 Michael S. Tsirkin
2009-05-05 7:14 ` Michael J Gruber
0 siblings, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2009-05-04 19: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 to git clone.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
I think it's ready now :) Comments?
Changes from v2: added test script, fixed update --reference with --init.
Changes from v1: fixes in documentation, fix test usage and
make it portable.
Documentation/git-submodule.txt | 14 ++++++-
git-submodule.sh | 38 ++++++++++++++++--
t/t7406-submodule-reference.sh | 81 +++++++++++++++++++++++++++++++++++++++
3 files changed, 127 insertions(+), 6 deletions(-)
create mode 100755 t/t7406-submodule-reference.sh
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..ab1ed02 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" &&
@@ -314,13 +330,22 @@ cmd_update()
quiet=1
;;
-i|--init)
+ init=1
shift
- cmd_init "$@" || return
;;
-N|--no-fetch)
shift
nofetch=1
;;
+ --reference)
+ case "$2" in '') usage ;; esac
+ reference="--reference=$2"
+ shift 2
+ ;;
+ --reference=*)
+ reference="$1"
+ shift
+ ;;
--)
shift
break
@@ -334,6 +359,11 @@ cmd_update()
esac
done
+ if test -n "$init"
+ then
+ cmd_init "--" "$@" || return
+ fi
+
module_list "$@" |
while read mode sha1 stage path
do
@@ -351,7 +381,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" &&
diff --git a/t/t7406-submodule-reference.sh b/t/t7406-submodule-reference.sh
new file mode 100755
index 0000000..cc16d3f
--- /dev/null
+++ b/t/t7406-submodule-reference.sh
@@ -0,0 +1,81 @@
+#!/bin/sh
+#
+# Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)
+#
+
+test_description='test clone --reference'
+. ./test-lib.sh
+
+base_dir=`pwd`
+
+U=$base_dir/UPLOAD_LOG
+
+test_expect_success 'preparing first repository' \
+'test_create_repo A && cd A &&
+echo first > file1 &&
+git add file1 &&
+git commit -m A-initial'
+
+cd "$base_dir"
+
+test_expect_success 'preparing second repository' \
+'git clone A B && cd B &&
+echo second > file2 &&
+git add file2 &&
+git commit -m B-addition &&
+git repack -a -d &&
+git prune'
+
+cd "$base_dir"
+
+test_expect_success 'preparing supermodule' \
+'test_create_repo super && cd super &&
+echo file > file &&
+git add file &&
+git commit -m B-super-initial'
+
+cd "$base_dir"
+
+test_expect_success 'submodule add --reference' \
+'cd super && git submodule add --reference ../B "file://$base_dir/A" sub &&
+git commit -m B-super-added'
+
+cd "$base_dir"
+
+test_expect_success 'after add: existence of info/alternates' \
+'test `wc -l <super/sub/.git/objects/info/alternates` = 1'
+
+cd "$base_dir"
+
+test_expect_success 'that reference gets used with add' \
+'cd super/sub &&
+echo "0 objects, 0 kilobytes" > expected &&
+git count-objects > current &&
+diff expected current'
+
+cd "$base_dir"
+
+test_expect_success 'cloning supermodule' \
+'git clone super super-clone'
+
+cd "$base_dir"
+
+test_expect_success 'update with reference' \
+'cd super-clone && git submodule update --init --reference ../B'
+
+cd "$base_dir"
+
+test_expect_success 'after update: existence of info/alternates' \
+'test `wc -l <super-clone/sub/.git/objects/info/alternates` = 1'
+
+cd "$base_dir"
+
+test_expect_success 'that reference gets used with update' \
+'cd super-clone/sub &&
+echo "0 objects, 0 kilobytes" > expected &&
+git count-objects > current &&
+diff expected current'
+
+cd "$base_dir"
+
+test_done
--
1.6.3.rc3.1.g830204
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCHv3] Add --reference option to git submodule.
2009-05-04 19:30 [PATCHv3] Add --reference option to git submodule Michael S. Tsirkin
@ 2009-05-05 7:14 ` Michael J Gruber
2009-05-07 14:16 ` Michael S. Tsirkin
0 siblings, 1 reply; 4+ messages in thread
From: Michael J Gruber @ 2009-05-05 7:14 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: git, Junio C Hamano
Michael S. Tsirkin venit, vidit, dixit 04.05.2009 21:30:
> This adds --reference option to git submodule add and
> git submodule update commands, which is passed to git clone.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>
> I think it's ready now :) Comments?
Please don't expect Junio to look at this now, shortly before 1.6.3. I
think only regression fixes would go in now, not even other bug fixes.
Holding on to your patch and re-posting after the upcoming release of
1.6.3 should be your best option.
Cheers,
Michael
>
> Changes from v2: added test script, fixed update --reference with --init.
>
> Changes from v1: fixes in documentation, fix test usage and
> make it portable.
>
> Documentation/git-submodule.txt | 14 ++++++-
> git-submodule.sh | 38 ++++++++++++++++--
> t/t7406-submodule-reference.sh | 81 +++++++++++++++++++++++++++++++++++++++
> 3 files changed, 127 insertions(+), 6 deletions(-)
> create mode 100755 t/t7406-submodule-reference.sh
>
> 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..ab1ed02 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" &&
> @@ -314,13 +330,22 @@ cmd_update()
> quiet=1
> ;;
> -i|--init)
> + init=1
> shift
> - cmd_init "$@" || return
> ;;
> -N|--no-fetch)
> shift
> nofetch=1
> ;;
> + --reference)
> + case "$2" in '') usage ;; esac
> + reference="--reference=$2"
> + shift 2
> + ;;
> + --reference=*)
> + reference="$1"
> + shift
> + ;;
> --)
> shift
> break
> @@ -334,6 +359,11 @@ cmd_update()
> esac
> done
>
> + if test -n "$init"
> + then
> + cmd_init "--" "$@" || return
> + fi
> +
> module_list "$@" |
> while read mode sha1 stage path
> do
> @@ -351,7 +381,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" &&
> diff --git a/t/t7406-submodule-reference.sh b/t/t7406-submodule-reference.sh
> new file mode 100755
> index 0000000..cc16d3f
> --- /dev/null
> +++ b/t/t7406-submodule-reference.sh
> @@ -0,0 +1,81 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)
> +#
> +
> +test_description='test clone --reference'
> +. ./test-lib.sh
> +
> +base_dir=`pwd`
> +
> +U=$base_dir/UPLOAD_LOG
> +
> +test_expect_success 'preparing first repository' \
> +'test_create_repo A && cd A &&
> +echo first > file1 &&
> +git add file1 &&
> +git commit -m A-initial'
> +
> +cd "$base_dir"
> +
> +test_expect_success 'preparing second repository' \
> +'git clone A B && cd B &&
> +echo second > file2 &&
> +git add file2 &&
> +git commit -m B-addition &&
> +git repack -a -d &&
> +git prune'
> +
> +cd "$base_dir"
> +
> +test_expect_success 'preparing supermodule' \
> +'test_create_repo super && cd super &&
> +echo file > file &&
> +git add file &&
> +git commit -m B-super-initial'
> +
> +cd "$base_dir"
> +
> +test_expect_success 'submodule add --reference' \
> +'cd super && git submodule add --reference ../B "file://$base_dir/A" sub &&
> +git commit -m B-super-added'
> +
> +cd "$base_dir"
> +
> +test_expect_success 'after add: existence of info/alternates' \
> +'test `wc -l <super/sub/.git/objects/info/alternates` = 1'
> +
> +cd "$base_dir"
> +
> +test_expect_success 'that reference gets used with add' \
> +'cd super/sub &&
> +echo "0 objects, 0 kilobytes" > expected &&
> +git count-objects > current &&
> +diff expected current'
> +
> +cd "$base_dir"
> +
> +test_expect_success 'cloning supermodule' \
> +'git clone super super-clone'
> +
> +cd "$base_dir"
> +
> +test_expect_success 'update with reference' \
> +'cd super-clone && git submodule update --init --reference ../B'
> +
> +cd "$base_dir"
> +
> +test_expect_success 'after update: existence of info/alternates' \
> +'test `wc -l <super-clone/sub/.git/objects/info/alternates` = 1'
> +
> +cd "$base_dir"
> +
> +test_expect_success 'that reference gets used with update' \
> +'cd super-clone/sub &&
> +echo "0 objects, 0 kilobytes" > expected &&
> +git count-objects > current &&
> +diff expected current'
> +
> +cd "$base_dir"
> +
> +test_done
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCHv3] Add --reference option to git submodule.
2009-05-05 7:14 ` Michael J Gruber
@ 2009-05-07 14:16 ` Michael S. Tsirkin
2009-05-07 23:55 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2009-05-07 14:16 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Junio C Hamano
On Tue, May 05, 2009 at 09:14:57AM +0200, Michael J Gruber wrote:
> Michael S. Tsirkin venit, vidit, dixit 04.05.2009 21:30:
> > This adds --reference option to git submodule add and
> > git submodule update commands, which is passed to git clone.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >
> > I think it's ready now :) Comments?
>
> Please don't expect Junio to look at this now, shortly before 1.6.3.
Hey Junio, now that 1.6.3 is out, could you please give this patch
a consideration? Should I repost?
--
MST
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCHv3] Add --reference option to git submodule.
2009-05-07 14:16 ` Michael S. Tsirkin
@ 2009-05-07 23:55 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2009-05-07 23:55 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: Michael J Gruber, git
"Michael S. Tsirkin" <mst@redhat.com> writes:
> On Tue, May 05, 2009 at 09:14:57AM +0200, Michael J Gruber wrote:
>> Michael S. Tsirkin venit, vidit, dixit 04.05.2009 21:30:
>> > This adds --reference option to git submodule add and
>> > git submodule update commands, which is passed to git clone.
>> >
>> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>> > ---
>> >
>> > I think it's ready now :) Comments?
>>
>> Please don't expect Junio to look at this now, shortly before 1.6.3.
>
> Hey Junio, now that 1.6.3 is out, could you please give this patch
> a consideration? Should I repost?
I have Message-ID: <20090504193001.GA13719@redhat.com> in my reviewbox;
unless you have updates, you do not have to.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-05-07 23:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-04 19:30 [PATCHv3] Add --reference option to git submodule Michael S. Tsirkin
2009-05-05 7:14 ` Michael J Gruber
2009-05-07 14:16 ` Michael S. Tsirkin
2009-05-07 23:55 ` Junio C Hamano
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.