{"thread":{"id":"19101","subject":"[PATCH] Add --reference option to git submodule","startedAt":"2009-04-28T06:52:37Z","lastAt":"2009-04-28T13:12:40Z","messageCount":5,"participants":["Michael S. Tsirkin","Michael J Gruber"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"112493","messageId":"20090428065237.GA5972@redhat.com","threadId":"19101","inReplyTo":null,"subject":"[PATCH] Add --reference option to git submodule","fromName":"Michael S. Tsirkin","fromEmail":"mst@redhat.com","sentAt":"2009-04-28T06:52:37Z","receivedAt":"2009-04-28T06:52:37Z","isPatch":true,"sender":{"key":"mst@kernel.org","avatar":null},"body":"This adds --reference option to 'git submodule add' and\n'git submodule update' commands, which is passed on to git clone.\nThis option is useful when the submodule is large, such as linux kernel.\n\nSigned-off-by: Michael S. Tsirkin <mst@redhat.com>\n---\n\nI noticed that there's no easy way to specify a reference\nfor submodule repositories. Here's a patch to add this option.\n\n Documentation/git-submodule.txt |   14 ++++++++++++--\n git-submodule.sh                |   31 ++++++++++++++++++++++++++++---\n 2 files changed, 40 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex 3b8df44..0584cb7 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 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] --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..32be246 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 \"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@@ -321,6 +337,15 @@ cmd_update()\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=\"$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@@ -351,7 +376,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-- \n1.6.3.rc3.dirty\n"},{"id":"112508","messageId":"49F6E419.1020308@drmicha.warpmail.net","threadId":"19101","inReplyTo":"20090428065237.GA5972@redhat.com","subject":"Re: [PATCH] Add --reference option to git submodule","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-04-28T11:10:17Z","receivedAt":"2009-04-28T11:10:17Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Michael S. Tsirkin venit, vidit, dixit 28.04.2009 08:52:\n> This adds --reference option to 'git submodule add' and\n> 'git submodule update' commands, which is passed on to git clone.\n> This option is useful when the submodule is large, such as linux kernel.\n> \n> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>\n> ---\n> \n> I noticed that there's no easy way to specify a reference\n> for submodule repositories. Here's a patch to add this option.\n\nCertainly useful. Just a few suggestions:\n\n> \n>  Documentation/git-submodule.txt |   14 ++++++++++++--\n>  git-submodule.sh                |   31 ++++++++++++++++++++++++++++---\n>  2 files changed, 40 insertions(+), 5 deletions(-)\n> \n> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> index 3b8df44..0584cb7 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\nThis option applies only to add...\n\n> +\tcommands sometimes need to clone a remote repository. In this case,\n> +\tthis option will be passed to linkgit:git-clone[1] command.\n\n...to the...\n\n> ++\n> +*NOTE*: Do *not* use this option unless you have read the note\n> +for linkgit:git-clone[1] --reference and --shared options carefully.\n\n...clone[1]\\'s --reference...\n\n> +\n>  <path>...::\n>  \tPaths to submodule(s). When specified this will restrict the command\n\nEither \"Path(s) to submodule(s)\" or \"Paths to submodules\". I prefer the\nlatter.\n\n>  \tto only operate on the submodules found at the specified paths.\n\n..to operate on... paths only.\n\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 8e234a4..32be246 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 \"reference\"\n\nI'm sure you want to test $reference here. I'm not sure how portable\ntesting for non-empty without -n is.\n\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> @@ -321,6 +337,15 @@ cmd_update()\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=\"$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> @@ -351,7 +376,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\nCheers,\nMichael\n"},{"id":"112510","messageId":"20090428112519.GB27513@redhat.com","threadId":"19101","inReplyTo":"49F6E419.1020308@drmicha.warpmail.net","subject":"Re: [PATCH] Add --reference option to git submodule","fromName":"Michael S. Tsirkin","fromEmail":"mst@redhat.com","sentAt":"2009-04-28T11:25:19Z","receivedAt":"2009-04-28T11:25:19Z","isPatch":true,"sender":{"key":"mst@kernel.org","avatar":null},"body":"On Tue, Apr 28, 2009 at 01:10:17PM +0200, Michael J Gruber wrote:\n> > +\n> >  <path>...::\n> >  \tPaths to submodule(s). When specified this will restrict the command\n> \n> Either \"Path(s) to submodule(s)\" or \"Paths to submodules\". I prefer the\n> latter.\n> \n> >  \tto only operate on the submodules found at the specified paths.\n> \n> ..to operate on... paths only.\n> \n\nI didn't touch these lines, so ... patch?\n\n-- \nMST\n"},{"id":"112511","messageId":"20090428112738.GC27513@redhat.com","threadId":"19101","inReplyTo":"49F6E419.1020308@drmicha.warpmail.net","subject":"Re: [PATCH] Add --reference option to git submodule","fromName":"Michael S. Tsirkin","fromEmail":"mst@redhat.com","sentAt":"2009-04-28T11:27:38Z","receivedAt":"2009-04-28T11:27:38Z","isPatch":true,"sender":{"key":"mst@kernel.org","avatar":null},"body":"On Tue, Apr 28, 2009 at 01:10:17PM +0200, Michael J Gruber wrote:\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> \n> This option applies only to add...\n\nThe rest of the documentation has 'is only valid' language.\nI guess we need to be consistent? Rewrite these as well?\n\n-- \nMST\n"},{"id":"112517","messageId":"49F700C8.10200@drmicha.warpmail.net","threadId":"19101","inReplyTo":"20090428112519.GB27513@redhat.com","subject":"Re: [PATCH] Add --reference option to git submodule","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-04-28T13:12:40Z","receivedAt":"2009-04-28T13:12:40Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Michael S. Tsirkin venit, vidit, dixit 28.04.2009 13:25:\n> On Tue, Apr 28, 2009 at 01:10:17PM +0200, Michael J Gruber wrote:\n>>> +\n>>>  <path>...::\n>>>  \tPaths to submodule(s). When specified this will restrict the command\n>>\n>> Either \"Path(s) to submodule(s)\" or \"Paths to submodules\". I prefer the\n>> latter.\n>>\n>>>  \tto only operate on the submodules found at the specified paths.\n>>\n>> ..to operate on... paths only.\n>>\n> \n> I didn't touch these lines, so ... patch?\n> \n\nYou're right, they were only context (I got hyperactive it seems). It's\nbetter to leave that for an overall style spring clean.\n\nMichael\n"}]}