{"thread":{"id":"9489","subject":"[PATCH] submodule update - don't run git-fetch if sha1 available","startedAt":"2007-08-11T17:48:37Z","lastAt":"2007-08-19T20:56:28Z","messageCount":7,"participants":["Torgil Svensson","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"50488","messageId":"e7bda7770708111048s77fbf416k9d0352486aee6b4a@mail.gmail.com","threadId":"9489","inReplyTo":null,"subject":"[PATCH] submodule update - don't run git-fetch if sha1 available","fromName":"Torgil Svensson","fromEmail":"torgil.svensson@gmail.com","sentAt":"2007-08-11T17:48:37Z","receivedAt":"2007-08-11T17:48:37Z","isPatch":true,"sender":{"key":"torgil.svensson@gmail.com","avatar":null},"body":"It's un-necessary (both time-consuming and annoying if you are\ndisconnected) for git submodule update to always running git-fetch\nprior to the detached head checkout of the submodule if the commit\nalready exists.\n\nSigned-off-by: Torgil Svensson <torgil.svensson@gmail.com>\n---\n git-submodule.sh |    9 +++++++--\n 1 files changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 2cfeadd..dc2ed4b 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -39,6 +39,11 @@ get_repo_base() {\n        ) 2>/dev/null\n }\n\n+has_sha1()\n+{\n+       git rev-list 2>/dev/null --max-count=0 $1\n+}\n+\n #\n # Map submodule path to submodule name\n #\n@@ -193,9 +198,9 @@ modules_update()\n\n                if test \"$subsha1\" != \"$sha1\"\n                then\n-                       (unset GIT_DIR && cd \"$path\" && git-fetch &&\n+                       (unset GIT_DIR && cd \"$path\" && (has_sha1\n\"$sha1\" || git-fetch) &&\n                                git-checkout -q \"$sha1\") ||\n-                       die \"Unable to checkout '$sha1' in submodule\npath '$path'\"\n+                       die \"Unable to checkout '$sha1' in submodule\npath '$path'\"\n\n                        say \"Submodule path '$path': checked out '$sha1'\"\n                fi\n--\n1.5.3.rc4.730.ga8c3-dirty\n"},{"id":"50490","messageId":"e7bda7770708111123m6e497450yaa91ccb600d37d53@mail.gmail.com","threadId":"9489","inReplyTo":"e7bda7770708111048s77fbf416k9d0352486aee6b4a@mail.gmail.com","subject":"Re: [PATCH] submodule update - don't run git-fetch if sha1 available","fromName":"Torgil Svensson","fromEmail":"torgil.svensson@gmail.com","sentAt":"2007-08-11T18:23:12Z","receivedAt":"2007-08-11T18:23:12Z","isPatch":true,"sender":{"key":"torgil.svensson@gmail.com","avatar":null},"body":"Hi\n\nSorry for a broken patch [inserted line-feeds]. If anyone knows how to\ndisable that in gmail web client, please let me know.\n\nI also tried to follow \"Using msmtp to send your patches\"\n[http://git.or.cz/gitwiki/GitTips ] on msys/mingw/WindowsXP with the\nfollowing result (at best) from git-send-email:\n\n\"Can't call method \"mail\" on an undefined value at\nC:/msysgit/git/git-send-email line 551.\"\n\nSo I would appreciate if someone that has used the combination gmail\nSMTP+Windows+git-send-email successfully (cygwin,msys or \"pure\") to\nlet us know how you did it.\n\nBest Regards,\n\n//Torgil\n\n\nOn 8/11/07, Torgil Svensson <torgil.svensson@gmail.com> wrote:\n> It's un-necessary (both time-consuming and annoying if you are\n> disconnected) for git submodule update to always running git-fetch\n> prior to the detached head checkout of the submodule if the commit\n> already exists.\n>\n> Signed-off-by: Torgil Svensson <torgil.svensson@gmail.com>\n> ---\n>  git-submodule.sh |    9 +++++++--\n>  1 files changed, 7 insertions(+), 2 deletions(-)\n>\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 2cfeadd..dc2ed4b 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -39,6 +39,11 @@ get_repo_base() {\n>         ) 2>/dev/null\n>  }\n>\n> +has_sha1()\n> +{\n> +       git rev-list 2>/dev/null --max-count=0 $1\n> +}\n> +\n>  #\n>  # Map submodule path to submodule name\n>  #\n> @@ -193,9 +198,9 @@ modules_update()\n>\n>                 if test \"$subsha1\" != \"$sha1\"\n>                 then\n> -                       (unset GIT_DIR && cd \"$path\" && git-fetch &&\n> +                       (unset GIT_DIR && cd \"$path\" && (has_sha1\n> \"$sha1\" || git-fetch) &&\n>                                 git-checkout -q \"$sha1\") ||\n> -                       die \"Unable to checkout '$sha1' in submodule\n> path '$path'\"\n> +                       die \"Unable to checkout '$sha1' in submodule\n> path '$path'\"\n>\n>                         say \"Submodule path '$path': checked out '$sha1'\"\n>                 fi\n> --\n> 1.5.3.rc4.730.ga8c3-dirty\n>\n"},{"id":"50494","messageId":"7vfy2pn9eb.fsf@assigned-by-dhcp.cox.net","threadId":"9489","inReplyTo":"e7bda7770708111048s77fbf416k9d0352486aee6b4a@mail.gmail.com","subject":"Re: [PATCH] submodule update - don't run git-fetch if sha1 available","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-11T19:44:44Z","receivedAt":"2007-08-11T19:44:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Torgil Svensson\" <torgil.svensson@gmail.com> writes:\n\n> It's un-necessary (both time-consuming and annoying if you are\n> disconnected) for git submodule update to always running git-fetch\n> prior to the detached head checkout of the submodule if the commit\n> already exists.\n\nThis is wrong.  Existence of the commit object alone does not\nmean the necessary tree and blob objects to check out that\ncommit, let alone all the history that leads to the commit,\nexist in the repository (think of a commit walker fetch that was\ninterrupted in the middle).  You need to make sure that the\ncommit exists *AND* is reachable from one of the refs.\n"},{"id":"50522","messageId":"e7bda7770708111703u40f89c1fx17bfac4b9aed9d2e@mail.gmail.com","threadId":"9489","inReplyTo":"7vfy2pn9eb.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] submodule update - don't run git-fetch if sha1 available","fromName":"Torgil Svensson","fromEmail":"torgil.svensson@gmail.com","sentAt":"2007-08-12T00:03:17Z","receivedAt":"2007-08-12T00:03:17Z","isPatch":true,"sender":{"key":"torgil.svensson@gmail.com","avatar":null},"body":"On 8/11/07, Junio C Hamano <gitster@pobox.com> wrote:\n\n> This is wrong.  Existence of the commit object alone does not\n> mean the necessary tree and blob objects to check out that\n> commit, let alone all the history that leads to the commit,\n> exist in the repository (think of a commit walker fetch that was\n> interrupted in the middle).  You need to make sure that the\n> commit exists *AND* is reachable from one of the refs.\n\nThat made sense. Good point. Consider this case:\n\n$ git clone <superproject>\n$ git submodule init\n$ git submodule update\n$ cd <submodule>\n$ git checkout master\n$ cd ..\n$ git status\nModified <submodule>\n$ git submodule update\n\nDo we know in this state that the ref can be reached from a reference?\nSay you've managed to do this:\n\n$ cd <submodule>\n$ git checkout master\n$ work.. commit .. work ..commit\n$ cd ..\n$ git add <submodule>\n$ git commit\n$ cd <submodule>\n$ git reset --hard HEAD~2\n\nIs it okay to fail the supermodule update in this state? Obviously\nwe've thrown away things for a purpose.\n\n//Torgil\n"},{"id":"50525","messageId":"7vfy2plfb4.fsf@assigned-by-dhcp.cox.net","threadId":"9489","inReplyTo":"e7bda7770708111703u40f89c1fx17bfac4b9aed9d2e@mail.gmail.com","subject":"Re: [PATCH] submodule update - don't run git-fetch if sha1 available","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-12T01:19:59Z","receivedAt":"2007-08-12T01:19:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Torgil Svensson\" <torgil.svensson@gmail.com> writes:\n\n> Do we know in this state that the ref can be reached from a reference?\n> Say you've managed to do this:\n>\n> $ cd <submodule>\n> $ git checkout master\n> $ work.. commit .. work ..commit\n> $ cd ..\n> $ git add <submodule>\n> $ git commit\n> $ cd <submodule>\n> $ git reset --hard HEAD~2\n>\n> Is it okay to fail the supermodule update in this state? Obviously\n> we've thrown away things for a purpose.\n\nIt would make more sense if the last command you ran in the\nsubproject directory were \"git checkout HEAD~2\".  If you have\nchecked out the subproject in the context of the superproject,\nyou have no business *resetting* its branches.  Then the updated\nHEAD is reachable from the branch tip.\n\nBut even when you did \"reset --hard\" to rewind, you _could_\navoid fetching if you wanted to.  In fact, this alternative\ntechnique is probably needed if you built new commits on top of\nexisting refs of the 'origin' repository of subproject, or even\non a detached HEAD.\n\nWhat you need to prove is that whatever commit the superproject\nwants to check out can be checked out.  Strictly speaking, the\ncommit does not even have to have histories leading to it in the\nrepository.  So in addition to the check you initially proposed\nin your patch (by the way, I would do \"git cat-file -t $commit\"\nand see if it is a commit object, instead of \"rev-list\" of count\nzero), minimally you need to prove that all trees and blobs\nexist in the repository.\n\nThat can be done from the script level by doing something silly\nlike:\n\n\tgit archive \"$commit^{tree}\" >/dev/null\n\nTo make it more efficient (the above proves all the trees and\nblobs exist by actually extracting all of them, which is an\nunnecessary work), you may want to add a more lightweight\nbuilt-in command to do so.  Perhaps...\n\n-- >8 --\nSubject: ls-tree --check\n\nYou can run \"ls-tree --check\" to make sure that all necessary\nobjects exist in the repository to complete a tree object.  This\nmay be useful to make sure that the subproject commit bound to a\nsuperproject index can be checked out in its entirety.\n\n---\n\n builtin-ls-tree.c |   21 +++++++++++++++++----\n 1 files changed, 17 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-ls-tree.c b/builtin-ls-tree.c\nindex cb4be4f..4a19e86 100644\n--- a/builtin-ls-tree.c\n+++ b/builtin-ls-tree.c\n@@ -16,6 +16,7 @@ static int line_termination = '\\n';\n #define LS_SHOW_TREES 4\n #define LS_NAME_ONLY 8\n #define LS_SHOW_SIZE 16\n+#define LS_CHECK 32\n static int abbrev;\n static int ls_options;\n static const char **pathspec;\n@@ -23,7 +24,7 @@ static int chomp_prefix;\n static const char *ls_tree_prefix;\n \n static const char ls_tree_usage[] =\n-\t\"git-ls-tree [-d] [-r] [-t] [-l] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]\";\n+\t\"git-ls-tree [-d] [-r] [-t] [-l] [-z] [--check] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]\";\n \n static int show_recursive(const char *base, int baselen, const char *pathname)\n {\n@@ -107,6 +108,16 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,\n \t\t\t\t       abbrev ? find_unique_abbrev(sha1, abbrev)\n \t\t\t\t              : sha1_to_hex(sha1),\n \t\t\t\t       '-');\n+\t\t} else if (ls_options & LS_CHECK) {\n+\t\t\tif (S_ISGITLINK(mode))\n+\t\t\t\t/*\n+\t\t\t\t * subproject commit does not have to be\n+\t\t\t\t * in this repository.\n+\t\t\t\t */\n+\t\t\t\t; /* noop */\n+\t\t\telse if (sha1_object_info(sha1, &size) < 0)\n+\t\t\t\tretval = -1;\n+\t\t\treturn retval;\n \t\t} else\n \t\t\tprintf(\"%06o %s %s\\t\", mode, type,\n \t\t\t       abbrev ? find_unique_abbrev(sha1, abbrev)\n@@ -171,6 +182,10 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)\n \t\t\t\tabbrev = DEFAULT_ABBREV;\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t\tif (!strcmp(argv[1]+2, \"check\")) {\n+\t\t\t\tls_options = LS_CHECK|LS_RECURSIVE;\n+\t\t\t\tbreak;\n+\t\t\t}\n \t\t\t/* otherwise fallthru */\n \t\tdefault:\n \t\t\tusage(ls_tree_usage);\n@@ -191,7 +206,5 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)\n \ttree = parse_tree_indirect(sha1);\n \tif (!tree)\n \t\tdie(\"not a tree object\");\n-\tread_tree_recursive(tree, \"\", 0, 0, pathspec, show_tree);\n-\n-\treturn 0;\n+\treturn read_tree_recursive(tree, \"\", 0, 0, pathspec, show_tree);\n }\n"},{"id":"51009","messageId":"e7bda7770708191157v54c2c2a3k8e17208a1d5b6dc9@mail.gmail.com","threadId":"9489","inReplyTo":"7vfy2plfb4.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] submodule update - don't run git-fetch if sha1 available","fromName":"Torgil Svensson","fromEmail":"torgil.svensson@gmail.com","sentAt":"2007-08-19T18:57:09Z","receivedAt":"2007-08-19T18:57:09Z","isPatch":true,"sender":{"key":"torgil.svensson@gmail.com","avatar":null},"body":"On 8/12/07, Junio C Hamano <gitster@pobox.com> wrote:\n\n> unnecessary work), you may want to add a more lightweight\n> built-in command to do so.  Perhaps...\n>\n> -- >8 --\n> Subject: ls-tree --check\n>\n> You can run \"ls-tree --check\" to make sure that all necessary\n> objects exist in the repository to complete a tree object.  This\n> may be useful to make sure that the subproject commit bound to a\n> superproject index can be checked out in its entirety.\n\nThis looks good, and the subproject part of it should be trivial to\nimplement but i'm struggling with applying your patch.\n\nIf I copy the whole mail with headers (I get them with a menu item\n\"show original\" in gmail web client), paste it into a file (\"*p in\nvim) I get the following:\n\n$ git apply junio.mail\nAdds trailing whitespace.\njunio.mail:103:#define LS_CHECK 32\nAdds trailing whitespace.\njunio.mail:112: \"git-ls-tree [-d] [-r] [-t] [-l] [-z] [--check]\n[--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-i\nsh> [path...]\";\nAdds trailing whitespace.\njunio.mail:120:         } else if (ls_options & LS_CHECK) {\nAdds trailing whitespace.\njunio.mail:121:                 if (S_ISGITLINK(mode))\nAdds trailing whitespace.\njunio.mail:122:                         /*\nerror: patch failed: builtin-ls-tree.c:16\nerror: builtin-ls-tree.c: patch does not apply\n\ngit am gives me similar behaviour.\n\n$ git am junio.mail\n\nApplying submodule update - don't run git-fetch if sha1 available\n\nAdds trailing whitespace.\n.dotest/patch:14:#define LS_CHECK 32\nAdds trailing whitespace.\n.dotest/patch:23:       \"git-ls-tree [-d] [-r] [-t] [-l] [-z]\n[--check] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]]\n <tree-ish> [path...]\";\nAdds trailing whitespace.\n.dotest/patch:31:               } else if (ls_options & LS_CHECK) {\nAdds trailing whitespace.\n.dotest/patch:32:                       if (S_ISGITLINK(mode))\nAdds trailing whitespace.\n.dotest/patch:33:                               /*\nerror: patch failed: builtin-ls-tree.c:16\nerror: builtin-ls-tree.c: patch does not apply\nPatch failed at 0001.\nWhen you have resolved this problem run \"git-am --resolved\".\nIf you would prefer to skip this patch, instead run \"git-am --skip\".\n\n\n\nIs the \"-- >8 --\" -line something git-apply looks for?\n\nShort of manual patching, abandoning the web-client or switch to\nanother mail-account, is there any simple way to get around the above\nissues ?    [I'm trying to do this on windows/msysgit]\n\n\nThank you for good support on this list!\n\n//Torgil\n"},{"id":"51017","messageId":"7v8x87b5vn.fsf@gitster.siamese.dyndns.org","threadId":"9489","inReplyTo":"e7bda7770708191157v54c2c2a3k8e17208a1d5b6dc9@mail.gmail.com","subject":"Re: [PATCH] submodule update - don't run git-fetch if sha1 available","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-19T20:56:28Z","receivedAt":"2007-08-19T20:56:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Torgil Svensson\" <torgil.svensson@gmail.com> writes:\n\n> $ git apply junio.mail\n\nI have no idea how you saved the junio.mail file.  \"git am\"\nknows how to grok e-mails in mbox and maildir formats.\n\n> ...\n> Is the \"-- >8 --\" -line something git-apply looks for?\n\ngit-apply does not have anything to do with any of this.  You\nare looking for \"git am\".\n\n\"git-am\" does not currently pay attention to the \"-- >8 --\"\nmarker, either.  It is there primarily so that you can do the\ninteractive \"git am -i\" so that you know up to which point you\nwould want to remove with its [e]dit subcommand.\n"}]}