{"thread":{"id":"19177","subject":"[PATCHv3] Add --reference option to git submodule.","startedAt":"2009-05-04T19:30:01Z","lastAt":"2009-05-07T23:55:04Z","messageCount":4,"participants":["Michael S. Tsirkin","Michael J Gruber","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"113001","messageId":"20090504193001.GA13719@redhat.com","threadId":"19177","inReplyTo":null,"subject":"[PATCHv3] Add --reference option to git submodule.","fromName":"Michael S. Tsirkin","fromEmail":"mst@redhat.com","sentAt":"2009-05-04T19:30:01Z","receivedAt":"2009-05-04T19:30:01Z","isPatch":false,"sender":{"key":"mst@kernel.org","avatar":null},"body":"This adds --reference option to git submodule add and\ngit submodule update commands, which is passed to git clone.\n\nSigned-off-by: Michael S. Tsirkin <mst@redhat.com>\n---\n\nI think it's ready now :) Comments?\n\nChanges from v2: added test script, fixed update --reference with --init.\n\nChanges from v1: fixes in documentation, fix test usage and\nmake it portable.\n\n Documentation/git-submodule.txt |   14 ++++++-\n git-submodule.sh                |   38 ++++++++++++++++--\n t/t7406-submodule-reference.sh  |   81 +++++++++++++++++++++++++++++++++++++++\n 3 files changed, 127 insertions(+), 6 deletions(-)\n create mode 100755 t/t7406-submodule-reference.sh\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex 3b8df44..14256c6 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -9,10 +9,12 @@ git-submodule - Initialize, update or inspect submodules\n SYNOPSIS\n --------\n [verse]\n-'git submodule' [--quiet] add [-b branch] [--] <repository> <path>\n+'git submodule' [--quiet] add [-b branch]\n+\t      [--reference <repository>] [--] <repository> <path>\n 'git submodule' [--quiet] status [--cached] [--] [<path>...]\n 'git submodule' [--quiet] init [--] [<path>...]\n-'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--] [<path>...]\n+'git submodule' [--quiet] update [--init] [-N|--no-fetch]\n+\t      [--reference <repository>] [--] [<path>...]\n 'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]\n 'git submodule' [--quiet] foreach <command>\n 'git submodule' [--quiet] sync [--] [<path>...]\n@@ -177,6 +179,14 @@ OPTIONS\n \tThis option is only valid for the update command.\n \tDon't fetch new objects from the remote site.\n \n+--reference <repository>::\n+\tThis option is only valid for add and update commands.  These\n+\tcommands sometimes need to clone a remote repository. In this case,\n+\tthis option will be passed to the linkgit:git-clone[1] command.\n++\n+*NOTE*: Do *not* use this option unless you have read the note\n+for linkgit:git-clone[1]'s --reference and --shared options carefully.\n+\n <path>...::\n \tPaths to submodule(s). When specified this will restrict the command\n \tto only operate on the submodules found at the specified paths.\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 8e234a4..ab1ed02 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -15,6 +15,7 @@ require_work_tree\n command=\n branch=\n quiet=\n+reference=\n cached=\n nofetch=\n \n@@ -91,6 +92,7 @@ module_clone()\n {\n \tpath=$1\n \turl=$2\n+\treference=\"$3\"\n \n \t# If there already is a directory at the submodule path,\n \t# expect it to be empty (since that is the default checkout\n@@ -106,7 +108,12 @@ module_clone()\n \ttest -e \"$path\" &&\n \tdie \"A file already exist at path '$path'\"\n \n-\tgit-clone -n \"$url\" \"$path\" ||\n+\tif test -n \"$reference\"\n+\tthen\n+\t\tgit-clone \"$reference\" -n \"$url\" \"$path\"\n+\telse\n+\t\tgit-clone -n \"$url\" \"$path\"\n+\tfi ||\n \tdie \"Clone of '$url' into submodule path '$path' failed\"\n }\n \n@@ -131,6 +138,15 @@ cmd_add()\n \t\t-q|--quiet)\n \t\t\tquiet=1\n \t\t\t;;\n+\t\t--reference)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\treference=\"--reference=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--reference=*)\n+\t\t\treference=\"$1\"\n+\t\t\tshift\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -203,7 +219,7 @@ cmd_add()\n \t\tgit config submodule.\"$path\".url \"$url\"\n \telse\n \n-\t\tmodule_clone \"$path\" \"$realrepo\" || exit\n+\t\tmodule_clone \"$path\" \"$realrepo\" \"$reference\" || exit\n \t\t(\n \t\t\tunset GIT_DIR\n \t\t\tcd \"$path\" &&\n@@ -314,13 +330,22 @@ cmd_update()\n \t\t\tquiet=1\n \t\t\t;;\n \t\t-i|--init)\n+\t\t\tinit=1\n \t\t\tshift\n-\t\t\tcmd_init \"$@\" || return\n \t\t\t;;\n \t\t-N|--no-fetch)\n \t\t\tshift\n \t\t\tnofetch=1\n \t\t\t;;\n+\t\t--reference)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\treference=\"--reference=$2\"\n+\t\t\tshift 2\n+\t\t\t;;\n+\t\t--reference=*)\n+\t\t\treference=\"$1\"\n+\t\t\tshift\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -334,6 +359,11 @@ cmd_update()\n \t\tesac\n \tdone\n \n+\tif test -n \"$init\"\n+\tthen\n+\t\tcmd_init \"--\" \"$@\" || return\n+\tfi\n+\n \tmodule_list \"$@\" |\n \twhile read mode sha1 stage path\n \tdo\n@@ -351,7 +381,7 @@ cmd_update()\n \n \t\tif ! test -d \"$path\"/.git -o -f \"$path\"/.git\n \t\tthen\n-\t\t\tmodule_clone \"$path\" \"$url\" || exit\n+\t\t\tmodule_clone \"$path\" \"$url\" \"$reference\"|| exit\n \t\t\tsubsha1=\n \t\telse\n \t\t\tsubsha1=$(unset GIT_DIR; cd \"$path\" &&\ndiff --git a/t/t7406-submodule-reference.sh b/t/t7406-submodule-reference.sh\nnew file mode 100755\nindex 0000000..cc16d3f\n--- /dev/null\n+++ b/t/t7406-submodule-reference.sh\n@@ -0,0 +1,81 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)\n+#\n+\n+test_description='test clone --reference'\n+. ./test-lib.sh\n+\n+base_dir=`pwd`\n+\n+U=$base_dir/UPLOAD_LOG\n+\n+test_expect_success 'preparing first repository' \\\n+'test_create_repo A && cd A &&\n+echo first > file1 &&\n+git add file1 &&\n+git commit -m A-initial'\n+\n+cd \"$base_dir\"\n+\n+test_expect_success 'preparing second repository' \\\n+'git clone A B && cd B &&\n+echo second > file2 &&\n+git add file2 &&\n+git commit -m B-addition &&\n+git repack -a -d &&\n+git prune'\n+\n+cd \"$base_dir\"\n+\n+test_expect_success 'preparing supermodule' \\\n+'test_create_repo super && cd super &&\n+echo file > file &&\n+git add file &&\n+git commit -m B-super-initial'\n+\n+cd \"$base_dir\"\n+\n+test_expect_success 'submodule add --reference' \\\n+'cd super && git submodule add --reference ../B \"file://$base_dir/A\" sub &&\n+git commit -m B-super-added'\n+\n+cd \"$base_dir\"\n+\n+test_expect_success 'after add: existence of info/alternates' \\\n+'test `wc -l <super/sub/.git/objects/info/alternates` = 1'\n+\n+cd \"$base_dir\"\n+\n+test_expect_success 'that reference gets used with add' \\\n+'cd super/sub &&\n+echo \"0 objects, 0 kilobytes\" > expected &&\n+git count-objects > current &&\n+diff expected current'\n+\n+cd \"$base_dir\"\n+\n+test_expect_success 'cloning supermodule' \\\n+'git clone super super-clone'\n+\n+cd \"$base_dir\"\n+\n+test_expect_success 'update with reference' \\\n+'cd super-clone && git submodule update --init --reference ../B'\n+\n+cd \"$base_dir\"\n+\n+test_expect_success 'after update: existence of info/alternates' \\\n+'test `wc -l <super-clone/sub/.git/objects/info/alternates` = 1'\n+\n+cd \"$base_dir\"\n+\n+test_expect_success 'that reference gets used with update' \\\n+'cd super-clone/sub &&\n+echo \"0 objects, 0 kilobytes\" > expected &&\n+git count-objects > current &&\n+diff expected current'\n+\n+cd \"$base_dir\"\n+\n+test_done\n-- \n1.6.3.rc3.1.g830204\n"},{"id":"113023","messageId":"49FFE771.1030208@drmicha.warpmail.net","threadId":"19177","inReplyTo":"20090504193001.GA13719@redhat.com","subject":"Re: [PATCHv3] Add --reference option to git submodule.","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-05-05T07:14:57Z","receivedAt":"2009-05-05T07:14:57Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Michael S. Tsirkin venit, vidit, dixit 04.05.2009 21:30:\n> This adds --reference option to git submodule add and\n> git submodule update commands, which is passed to git clone.\n> \n> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>\n> ---\n> \n> I think it's ready now :) Comments?\n\nPlease don't expect Junio to look at this now, shortly before 1.6.3. I\nthink only regression fixes would go in now, not even other bug fixes.\nHolding on to your patch and re-posting after the upcoming release of\n1.6.3 should be your best option.\n\nCheers,\nMichael\n\n> \n> Changes from v2: added test script, fixed update --reference with --init.\n> \n> Changes from v1: fixes in documentation, fix test usage and\n> make it portable.\n> \n>  Documentation/git-submodule.txt |   14 ++++++-\n>  git-submodule.sh                |   38 ++++++++++++++++--\n>  t/t7406-submodule-reference.sh  |   81 +++++++++++++++++++++++++++++++++++++++\n>  3 files changed, 127 insertions(+), 6 deletions(-)\n>  create mode 100755 t/t7406-submodule-reference.sh\n> \n> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> index 3b8df44..14256c6 100644\n> --- a/Documentation/git-submodule.txt\n> +++ b/Documentation/git-submodule.txt\n> @@ -9,10 +9,12 @@ git-submodule - Initialize, update or inspect submodules\n>  SYNOPSIS\n>  --------\n>  [verse]\n> -'git submodule' [--quiet] add [-b branch] [--] <repository> <path>\n> +'git submodule' [--quiet] add [-b branch]\n> +\t      [--reference <repository>] [--] <repository> <path>\n>  'git submodule' [--quiet] status [--cached] [--] [<path>...]\n>  'git submodule' [--quiet] init [--] [<path>...]\n> -'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--] [<path>...]\n> +'git submodule' [--quiet] update [--init] [-N|--no-fetch]\n> +\t      [--reference <repository>] [--] [<path>...]\n>  'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]\n>  'git submodule' [--quiet] foreach <command>\n>  'git submodule' [--quiet] sync [--] [<path>...]\n> @@ -177,6 +179,14 @@ OPTIONS\n>  \tThis option is only valid for the update command.\n>  \tDon't fetch new objects from the remote site.\n>  \n> +--reference <repository>::\n> +\tThis option is only valid for add and update commands.  These\n> +\tcommands sometimes need to clone a remote repository. In this case,\n> +\tthis option will be passed to the linkgit:git-clone[1] command.\n> ++\n> +*NOTE*: Do *not* use this option unless you have read the note\n> +for linkgit:git-clone[1]'s --reference and --shared options carefully.\n> +\n>  <path>...::\n>  \tPaths to submodule(s). When specified this will restrict the command\n>  \tto only operate on the submodules found at the specified paths.\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 8e234a4..ab1ed02 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -15,6 +15,7 @@ require_work_tree\n>  command=\n>  branch=\n>  quiet=\n> +reference=\n>  cached=\n>  nofetch=\n>  \n> @@ -91,6 +92,7 @@ module_clone()\n>  {\n>  \tpath=$1\n>  \turl=$2\n> +\treference=\"$3\"\n>  \n>  \t# If there already is a directory at the submodule path,\n>  \t# expect it to be empty (since that is the default checkout\n> @@ -106,7 +108,12 @@ module_clone()\n>  \ttest -e \"$path\" &&\n>  \tdie \"A file already exist at path '$path'\"\n>  \n> -\tgit-clone -n \"$url\" \"$path\" ||\n> +\tif test -n \"$reference\"\n> +\tthen\n> +\t\tgit-clone \"$reference\" -n \"$url\" \"$path\"\n> +\telse\n> +\t\tgit-clone -n \"$url\" \"$path\"\n> +\tfi ||\n>  \tdie \"Clone of '$url' into submodule path '$path' failed\"\n>  }\n>  \n> @@ -131,6 +138,15 @@ cmd_add()\n>  \t\t-q|--quiet)\n>  \t\t\tquiet=1\n>  \t\t\t;;\n> +\t\t--reference)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\treference=\"--reference=$2\"\n> +\t\t\tshift\n> +\t\t\t;;\n> +\t\t--reference=*)\n> +\t\t\treference=\"$1\"\n> +\t\t\tshift\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -203,7 +219,7 @@ cmd_add()\n>  \t\tgit config submodule.\"$path\".url \"$url\"\n>  \telse\n>  \n> -\t\tmodule_clone \"$path\" \"$realrepo\" || exit\n> +\t\tmodule_clone \"$path\" \"$realrepo\" \"$reference\" || exit\n>  \t\t(\n>  \t\t\tunset GIT_DIR\n>  \t\t\tcd \"$path\" &&\n> @@ -314,13 +330,22 @@ cmd_update()\n>  \t\t\tquiet=1\n>  \t\t\t;;\n>  \t\t-i|--init)\n> +\t\t\tinit=1\n>  \t\t\tshift\n> -\t\t\tcmd_init \"$@\" || return\n>  \t\t\t;;\n>  \t\t-N|--no-fetch)\n>  \t\t\tshift\n>  \t\t\tnofetch=1\n>  \t\t\t;;\n> +\t\t--reference)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\treference=\"--reference=$2\"\n> +\t\t\tshift 2\n> +\t\t\t;;\n> +\t\t--reference=*)\n> +\t\t\treference=\"$1\"\n> +\t\t\tshift\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -334,6 +359,11 @@ cmd_update()\n>  \t\tesac\n>  \tdone\n>  \n> +\tif test -n \"$init\"\n> +\tthen\n> +\t\tcmd_init \"--\" \"$@\" || return\n> +\tfi\n> +\n>  \tmodule_list \"$@\" |\n>  \twhile read mode sha1 stage path\n>  \tdo\n> @@ -351,7 +381,7 @@ cmd_update()\n>  \n>  \t\tif ! test -d \"$path\"/.git -o -f \"$path\"/.git\n>  \t\tthen\n> -\t\t\tmodule_clone \"$path\" \"$url\" || exit\n> +\t\t\tmodule_clone \"$path\" \"$url\" \"$reference\"|| exit\n>  \t\t\tsubsha1=\n>  \t\telse\n>  \t\t\tsubsha1=$(unset GIT_DIR; cd \"$path\" &&\n> diff --git a/t/t7406-submodule-reference.sh b/t/t7406-submodule-reference.sh\n> new file mode 100755\n> index 0000000..cc16d3f\n> --- /dev/null\n> +++ b/t/t7406-submodule-reference.sh\n> @@ -0,0 +1,81 @@\n> +#!/bin/sh\n> +#\n> +# Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)\n> +#\n> +\n> +test_description='test clone --reference'\n> +. ./test-lib.sh\n> +\n> +base_dir=`pwd`\n> +\n> +U=$base_dir/UPLOAD_LOG\n> +\n> +test_expect_success 'preparing first repository' \\\n> +'test_create_repo A && cd A &&\n> +echo first > file1 &&\n> +git add file1 &&\n> +git commit -m A-initial'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_expect_success 'preparing second repository' \\\n> +'git clone A B && cd B &&\n> +echo second > file2 &&\n> +git add file2 &&\n> +git commit -m B-addition &&\n> +git repack -a -d &&\n> +git prune'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_expect_success 'preparing supermodule' \\\n> +'test_create_repo super && cd super &&\n> +echo file > file &&\n> +git add file &&\n> +git commit -m B-super-initial'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_expect_success 'submodule add --reference' \\\n> +'cd super && git submodule add --reference ../B \"file://$base_dir/A\" sub &&\n> +git commit -m B-super-added'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_expect_success 'after add: existence of info/alternates' \\\n> +'test `wc -l <super/sub/.git/objects/info/alternates` = 1'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_expect_success 'that reference gets used with add' \\\n> +'cd super/sub &&\n> +echo \"0 objects, 0 kilobytes\" > expected &&\n> +git count-objects > current &&\n> +diff expected current'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_expect_success 'cloning supermodule' \\\n> +'git clone super super-clone'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_expect_success 'update with reference' \\\n> +'cd super-clone && git submodule update --init --reference ../B'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_expect_success 'after update: existence of info/alternates' \\\n> +'test `wc -l <super-clone/sub/.git/objects/info/alternates` = 1'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_expect_success 'that reference gets used with update' \\\n> +'cd super-clone/sub &&\n> +echo \"0 objects, 0 kilobytes\" > expected &&\n> +git count-objects > current &&\n> +diff expected current'\n> +\n> +cd \"$base_dir\"\n> +\n> +test_done\n"},{"id":"113221","messageId":"20090507141656.GA1770@redhat.com","threadId":"19177","inReplyTo":"49FFE771.1030208@drmicha.warpmail.net","subject":"Re: [PATCHv3] Add --reference option to git submodule.","fromName":"Michael S. Tsirkin","fromEmail":"mst@redhat.com","sentAt":"2009-05-07T14:16:56Z","receivedAt":"2009-05-07T14:16:56Z","isPatch":false,"sender":{"key":"mst@kernel.org","avatar":null},"body":"On Tue, May 05, 2009 at 09:14:57AM +0200, Michael J Gruber wrote:\n> Michael S. Tsirkin venit, vidit, dixit 04.05.2009 21:30:\n> > This adds --reference option to git submodule add and\n> > git submodule update commands, which is passed to git clone.\n> > \n> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>\n> > ---\n> > \n> > I think it's ready now :) Comments?\n> \n> Please don't expect Junio to look at this now, shortly before 1.6.3.\n\nHey Junio, now that 1.6.3 is out, could you please give this patch\na consideration? Should I repost?\n\n-- \nMST\n"},{"id":"113283","messageId":"7vr5z0cvtz.fsf@alter.siamese.dyndns.org","threadId":"19177","inReplyTo":"20090507141656.GA1770@redhat.com","subject":"Re: [PATCHv3] Add --reference option to git submodule.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-07T23:55:04Z","receivedAt":"2009-05-07T23:55:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Michael S. Tsirkin\" <mst@redhat.com> writes:\n\n> On Tue, May 05, 2009 at 09:14:57AM +0200, Michael J Gruber wrote:\n>> Michael S. Tsirkin venit, vidit, dixit 04.05.2009 21:30:\n>> > This adds --reference option to git submodule add and\n>> > git submodule update commands, which is passed to git clone.\n>> > \n>> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>\n>> > ---\n>> > \n>> > I think it's ready now :) Comments?\n>> \n>> Please don't expect Junio to look at this now, shortly before 1.6.3.\n>\n> Hey Junio, now that 1.6.3 is out, could you please give this patch\n> a consideration? Should I repost?\n\nI have Message-ID: <20090504193001.GA13719@redhat.com> in my reviewbox;\nunless you have updates, you do not have to.\n"}]}