{"thread":{"id":"15647","subject":"Re: Git submodule enhancements","startedAt":"2008-09-24T09:13:59Z","lastAt":"2008-09-24T16:39:53Z","messageCount":5,"participants":["Lars Hjemli","P. Christeas","René Scharfe"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"91452","messageId":"8c5c35580809240213v5198d2abh489915dc1133c75@mail.gmail.com","threadId":"15647","inReplyTo":"200809241100.30758.p_christ@hol.gr","subject":"Re: Git submodule enhancements","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2008-09-24T09:13:59Z","receivedAt":"2008-09-24T09:13:59Z","isPatch":false,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"On Wed, Sep 24, 2008 at 10:00 AM, P. Christeas <p_christ@hol.gr> wrote:\n> In my attempt to take some source off a submoduled repo, I tried writting a\n> few lines of code into git-submodule.\n\nThanks, but please also send this to git@vger.kernel.org. And please\ntry do inline the patches, it makes it much easier to review; I've\npasted the patches below and inserted a few comments prefixed with\n'lh>'.\n\n\n>From 9edad86468933a21264ab7bed4608ea8a6e992e4 Mon Sep 17 00:00:00 2001\nFrom: P. Christeas <p_christ@hol.gr>\nDate: Wed, 24 Sep 2008 10:05:45 +0300\nSubject: [PATCH] Git submodule archive: create series of archives, for\neach module\n\nThis is a temporary solution to creating archives from repos\ncontaining submodules. It will just create a series of archives,\neach named after the name of the submodule.\n---\n git-submodule.sh |   87 +++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 86 insertions(+), 1 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 1c39b59..2bce7f9 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -602,6 +602,91 @@ cmd_status()\n \t\tfi\n \tdone\n }\n+\n+cmd_archive() {\n+\t# parse $args after \"submodule ... archive\".\n+\tsmodules=\"\"\n+\tverbose=\"\"\n+\tformat=tar\n+\tdo_exec=\n+\tbase_prefix=\"\"\n+\toutname=\n+\twhile test $# -ne 0\n+\tdo\n+\t\tcase \"$1\" in\n+\t\t-q|--quiet)\n+\t\t\tquiet=1\n+\t\t\t;;\n+\t\t-m|--module)\n+\t\t\tshift\n+\t\t\tsmodules+=\"$1 \"\n+\t\t\t;;\n\nlh> Other submodule commands take optional module paths as final\nlh> arguments. Why not use the same for `archive`?\n\n\n+\t\t--format)\n+\t\t\tshift\n+\t\t\tformat=\"$1\"\n+\t\t\t;;\n+\t\t--exec)\n+\t\t\tshift\n+\t\t\tdo_exec=\"--exec=$1\"\n+\t\t\t;;\n+\t\t--prefix)\n+\t\t\tshift\n+\t\t\tbase_prefix=\"$1\"\n+\t\t\t;;\n+\t\t-v|--verbose)\n+\t\t\tverbose=\"-v\"\n+\t\t\t;;\n+\t\t-o|--output)\n+\t\t\tshift\n+\t\t\toutname=\"$1\"\n+\t\t\t;;\n+\t\t--)\n+\t\t\tshift\n+\t\t\tbreak\n+\t\t\t;;\n+\t\t-*)\n+\t\t\tusage\n+\t\t\t;;\n+\t\t*)\n+\t\t\tbreak\n+\t\t\t;;\n+\t\tesac\n+\t\tshift\n+\tdone\n+\tif [ -z $outname ] ; then\n+\t\toutname=$(basename $(pwd))-%m.$format\n+\tfi\n+\n+\tif ! (echo $outname | grep '%m') > /dev/null  ; then\n+\t\toutname+=\"-%m\"\n+\tfi\n+\tif ! (echo $outname | grep '^/') > /dev/null  ; then\n+\t\toutname=$(pwd)/\"$outname\"\n+\tfi\n+\t\n+\t#echo \"Modules: $smodules\"\n+\t#echo \"Params: $@\"\n+\t#echo \"Outname: $outname\"\n\nlh> Please remove debug comments.\n\n\n+\t\n+\tmodule_list \"$smodules\" |\n+\twhile read mode sha1 stage path\n+\tdo\n+\t\tname=$(module_name \"$path\") || exit\n+# \t\turl=$(git config submodule.\"$name\".url)\n+# \t\tif test -z \"$url\" || ! test -d \"$path\"/.git -o -f \"$path\"/.git\n+# \t\tthen\n+# \t\t\tsay \"-$sha1 $path\"\n+# \t\t\tcontinue;\n+# \t\tfi\n\nlh> This should probably work similar to `update`, i.e. exit\nlh> with an error if a submodule path is explicitly specified\nlh> and the submodule isn't registered in .git/config, and\nlh> silently skip any non-registered submodules if no\nlh> paths were specified. And if the submodule is not\nlh> skipped it probably should be an error if the submodule\nlh>  isn't checked out.\n\n\n+\t\t\n+\t\tfname=$(echo $outname |sed 's/%m/'$name'/')\n\nlh> This should probably be documented ;-)\n\n\n+\t\tsay $fname\n+\t\tpushd \"$path\" > /dev/null\n+\t\tgit archive --format=$format $do_exec $verbose\n--prefix=\"$base_prefix$path/\" $sha1 > \\\n+\t\t\t\"$fname\"\n+\t\tpopd > /dev/null\n\nlh> What does `git archive` do when --exec is specified without\nlh> --remote? What about error checking?\n\n\n+\tdone\n+}\n #\n # Sync remote urls for submodules\n # This makes the value for remote.$remote.url match the value\n@@ -656,7 +741,7 @@ cmd_sync()\n while test $# != 0 && test -z \"$command\"\n do\n \tcase \"$1\" in\n-\tadd | foreach | init | update | status | summary | sync)\n+\tadd | foreach | init | update | status | summary | sync | archive)\n \t\tcommand=$1\n \t\t;;\n \t-q|--quiet)\n--\n1.6.0.1\n\n\n\n>From 87b75f003d31994d0de6502342e4d0ad68665e80 Mon Sep 17 00:00:00 2001\nFrom: P. Christeas <p_christ@hol.gr>\nDate: Wed, 24 Sep 2008 10:48:04 +0300\nSubject: [PATCH] Submodule init: cloned mode\n\nIf we try to clone a repo with git submodules, the 'submodule init'\ncommand should bind the submodules to the source repo, rather than\nthe source's origin.\n\nSigned-off-by: P. Christeas <p_christ@hol.gr>\n---\n git-submodule.sh |   37 +++++++++++++++++++++++++------------\n 1 files changed, 25 insertions(+), 12 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 2bce7f9..df5fcac 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -241,6 +241,12 @@ cmd_init()\n \t\t-q|--quiet)\n \t\t\tquiet=1\n \t\t\t;;\n+\t\t-f|--force)\n+\t\t\tforce=1\n+\t\t\t;;\n+\t\t--cloned)\n+\t\t\tcloned=1\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -261,19 +267,26 @@ cmd_init()\n \t\t# Skip already registered paths\n \t\tname=$(module_name \"$path\") || exit\n \t\turl=$(git config submodule.\"$name\".url)\n-\t\ttest -z \"$url\" || continue\n-\n-\t\turl=$(git config -f .gitmodules submodule.\"$name\".url)\n-\t\ttest -z \"$url\" &&\n-\t\tdie \"No url found for submodule path '$path' in .gitmodules\"\n-\n-\t\t# Possibly a url relative to parent\n-\t\tcase \"$url\" in\n-\t\t./*|../*)\n-\t\t\turl=$(resolve_relative_url \"$url\") || exit\n-\t\t\t;;\n-\t\tesac\n+\t\ttest -z \"$url\" || test -n \"$force\" || continue\n\n+\t\tif [ \"x$cloned\" != \"x1\" ] ; then\n+\t\t\turl=$(git config -f .gitmodules submodule.\"$name\".url)\n+\t\t\ttest -z \"$url\" &&\n+\t\t\tdie \"No url found for submodule path '$path' in .gitmodules\"\n+\t\n+\t\t\t# Possibly a url relative to parent\n+\t\t\tcase \"$url\" in\n+\t\t\t./*|../*)\n+\t\t\t\turl=$(resolve_relative_url \"$url\") || exit\n+\t\t\t\t;;\n+\t\t\tesac\n+\t\telse\n+\t\t\t# Cloned mode: we try to figure out the submodule\n+\t\t\t# path in the remote origin.\n+\t\t\t# FIXME: we do use \"../\" because the remote is the .git/\n+\t\t\turl=$(resolve_relative_url \"../$path/.git\")\n+\t\tfi\n+\t\t\n \t\tgit config submodule.\"$name\".url \"$url\" ||\n \t\tdie \"Failed to register url for submodule path '$path'\"\n--\n1.6.0.1\n\n\nIt looks like --cloned requires the downstream to know which\nsubmodules are available from the same remote as the supermodule (and\nwith the same path as registered in the supermodule), i.e. quite a\nspecific configuration. Is this really common enough to justify a\nspecial option to `submodule init`?\n\nMaybe the .gitmodules file could be extended to contain multiple urls\ninstead (i.e. both absolute and relative ones)? Then `submodule init`\ncould get options like --prefer-relative-url, --prefer-absolute-url\nand --interactive. What do you think?\n\n--\nlarsh\n"},{"id":"91453","messageId":"8c5c35580809240225ld59fe28g10ecd09d1962ef3c@mail.gmail.com","threadId":"15647","inReplyTo":"8c5c35580809240213v5198d2abh489915dc1133c75@mail.gmail.com","subject":"Re: Git submodule enhancements","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2008-09-24T09:25:21Z","receivedAt":"2008-09-24T09:25:21Z","isPatch":false,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"On Wed, Sep 24, 2008 at 11:13 AM, Lars Hjemli <hjemli@gmail.com> wrote:\n> On Wed, Sep 24, 2008 at 10:00 AM, P. Christeas <p_christ@hol.gr> wrote:\n> +                       # Cloned mode: we try to figure out the submodule\n> +                       # path in the remote origin.\n> +                       # FIXME: we do use \"../\" because the remote is the .git/\n> +                       url=$(resolve_relative_url \"../$path/.git\")\n> +               fi\n> +\n>                git config submodule.\"$name\".url \"$url\" ||\n>                die \"Failed to register url for submodule path '$path'\"\n> --\n> 1.6.0.1\n>\n>\n> It looks like --cloned requires the downstream to know which\n> submodules are available from the same remote as the supermodule (and\n> with the same path as registered in the supermodule)\n\nHmm, after reading through this once more I guess you're trying to\nclone a non-bare repository, possibly also lacking a .gitmodules file\n(hence the --force)?\n\n--\nlarsh\n"},{"id":"91456","messageId":"8c5c35580809240246p1aede11n31cb693d7393b6ee@mail.gmail.com","threadId":"15647","inReplyTo":"8c5c35580809240213v5198d2abh489915dc1133c75@mail.gmail.com","subject":"Re: Git submodule enhancements","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2008-09-24T09:46:09Z","receivedAt":"2008-09-24T09:46:09Z","isPatch":false,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"On Wed, Sep 24, 2008 at 11:13 AM, Lars Hjemli <hjemli@gmail.com> wrote:\n> On Wed, Sep 24, 2008 at 10:00 AM, P. Christeas <p_christ@hol.gr> wrote:\n> Subject: [PATCH] Git submodule archive: create series of archives, for\n> each module\n\nBtw: why doesn't\n\n  $ git submodule foreach 'git archive HEAD > somewhere/$path.tar'\n\nwork for you?\n\n\n--\nlarsh\n"},{"id":"91458","messageId":"200809241314.29661.p_christ@hol.gr","threadId":"15647","inReplyTo":"8c5c35580809240213v5198d2abh489915dc1133c75@mail.gmail.com","subject":"Re: Git submodule enhancements","fromName":"P. Christeas","fromEmail":"p_christ@hol.gr","sentAt":"2008-09-24T10:14:27Z","receivedAt":"2008-09-24T10:14:27Z","isPatch":false,"sender":{"key":"p_christ@hol.gr","avatar":null},"body":"On Wednesday 24 September 2008, Lars Hjemli wrote:\n> It looks like --cloned requires the downstream to know which\n> submodules are available from the same remote as the supermodule (and\n> with the same path as registered in the supermodule), i.e. quite a\n> specific configuration. Is this really common enough to justify a\n> special option to `submodule init`?\nI agree. My patch is only a temporary fix for the situation and may not cover \nall needs.\n\n> Maybe the .gitmodules file could be extended to contain multiple urls\n> instead (i.e. both absolute and relative ones)? Then `submodule init`\n> could get options like --prefer-relative-url, --prefer-absolute-url\n> and --interactive. What do you think?\nI guess there is much room for improvement wrt. with the .gitmodules . For \none, they should try to mimic the 'git clone' refspec logic, instead of being \na static file. (in fact, the hooks could let us do that using scripts alone)\n\n> Hmm, after reading through this once more I guess you're trying to\n> clone a non-bare repository, possibly also lacking a .gitmodules file\n> (hence the --force)?\nNot really. I was trying to have the git-submodule script re-write the conf \nwith a different url. Merely like running a 'submodule sync' at the same \ntime.\n\n> Btw: why doesn't\n>   $ git submodule foreach 'git archive HEAD > somewhere/$path.tar'\n> work for you?\nIn fact, it could. You could also replace HEAD with the $sha1 ..\n\nIn general, my comment on submodules is that it is a very powerful concept, \nbut still lacks many real-life features. Reading the C code, I realized that \nwe would have to rework all the core plumbing of git in order to have it work \naccross different git repos inside the same C process. That is a stopper. \nOtherwise, if we could only have read_tree_recursive() span to different gits, \nwe could do really beautiful things.\n\nSorry for posting many ideas and only few patches!\n"},{"id":"91490","messageId":"48DA6D59.60904@lsrfire.ath.cx","threadId":"15647","inReplyTo":"200809241314.29661.p_christ@hol.gr","subject":"Re: Git submodule enhancements","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-09-24T16:39:53Z","receivedAt":"2008-09-24T16:39:53Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"P. Christeas schrieb:\n> On Wednesday 24 September 2008, Lars Hjemli wrote:\n>> Btw: why doesn't\n>>   $ git submodule foreach 'git archive HEAD > somewhere/$path.tar'\n>> work for you?\n> In fact, it could. You could also replace HEAD with the $sha1 ..\n\nBy the way, have you tried git-archive-all.sh (announced here a month\nago and hosted here: http://github.com/meitar/git-archive-all.sh/wikis)?\n\nRené\n"}]}