{"thread":{"id":"33964","subject":"[PATCH] completion: avoid ls-remote in certain scenarios","startedAt":"2013-05-29T03:20:48Z","lastAt":"2013-06-02T22:57:04Z","messageCount":6,"participants":["Felipe Contreras","SZEDER Gábor","Ramkumar Ramachandra","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"218722","messageId":"1369797648-2921-1-git-send-email-felipe.contreras@gmail.com","threadId":"33964","inReplyTo":null,"subject":"[PATCH] completion: avoid ls-remote in certain scenarios","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-29T03:20:48Z","receivedAt":"2013-05-29T03:20:48Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It's _very_ slow in many cases, and there's really no point in fetching\n*everything* from the remote just for completion. In many cases it might\nbe faster for the user to type the whole thing.\n\nIf the user manually specifies 'refs/*', then the full ls-remote\ncompletion is triggered.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 10 ++--------\n 1 file changed, 2 insertions(+), 8 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 1c35eef..2ce4f7d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -427,14 +427,8 @@ __git_refs ()\n \t\tdone\n \t\t;;\n \t*)\n-\t\tgit ls-remote \"$dir\" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \\\n-\t\twhile read -r hash i; do\n-\t\t\tcase \"$i\" in\n-\t\t\t*^{}) ;;\n-\t\t\trefs/*) echo \"${i#refs/*/}\" ;;\n-\t\t\t*) echo \"$i\" ;;\n-\t\t\tesac\n-\t\tdone\n+\t\techo \"HEAD\"\n+\t\tgit for-each-ref --format=\"%(refname:short)\" -- \"refs/remotes/$dir/\" | sed -e \"s#^$dir/##\"\n \t\t;;\n \tesac\n }\n-- \n1.8.3.rc3.312.g47657de\n"},{"id":"218780","messageId":"20130529074408.GA7955@goldbirke","threadId":"33964","inReplyTo":"1369797648-2921-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] completion: avoid ls-remote in certain scenarios","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-05-29T07:44:08Z","receivedAt":"2013-05-29T07:44:08Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, May 28, 2013 at 10:20:48PM -0500, Felipe Contreras wrote:\n> It's _very_ slow in many cases, and there's really no point in fetching\n> *everything* from the remote just for completion. In many cases it might\n> be faster for the user to type the whole thing.\n> \n> If the user manually specifies 'refs/*', then the full ls-remote\n> completion is triggered.\n> \n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>  contrib/completion/git-completion.bash | 10 ++--------\n>  1 file changed, 2 insertions(+), 8 deletions(-)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 1c35eef..2ce4f7d 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -427,14 +427,8 @@ __git_refs ()\n>  \t\tdone\n>  \t\t;;\n>  \t*)\n> -\t\tgit ls-remote \"$dir\" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \\\n> -\t\twhile read -r hash i; do\n> -\t\t\tcase \"$i\" in\n> -\t\t\t*^{}) ;;\n> -\t\t\trefs/*) echo \"${i#refs/*/}\" ;;\n> -\t\t\t*) echo \"$i\" ;;\n> -\t\t\tesac\n> -\t\tdone\n> +\t\techo \"HEAD\"\n> +\t\tgit for-each-ref --format=\"%(refname:short)\" -- \"refs/remotes/$dir/\" | sed -e \"s#^$dir/##\"\n\nThis case statement is only executed when $dir is not a git directory,\nso what ensures that the cwd is in a git repo or work tree when\nexecuting this brach of the case statement?  What about 'git\n--git-dir=/path/to/repo' invocations or when $GIT_DIR is specified?\n\n\nGábor\n"},{"id":"219135","messageId":"CAMP44s3abuEuXdRsAkuCVZiBkaFc+pT3kfXK9uN-U7tc4CR3tA@mail.gmail.com","threadId":"33964","inReplyTo":"20130529074408.GA7955@goldbirke","subject":"Re: [PATCH] completion: avoid ls-remote in certain scenarios","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-06-01T13:58:28Z","receivedAt":"2013-06-01T13:58:28Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Wed, May 29, 2013 at 2:44 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> On Tue, May 28, 2013 at 10:20:48PM -0500, Felipe Contreras wrote:\n>> It's _very_ slow in many cases, and there's really no point in fetching\n>> *everything* from the remote just for completion. In many cases it might\n>> be faster for the user to type the whole thing.\n>>\n>> If the user manually specifies 'refs/*', then the full ls-remote\n>> completion is triggered.\n>>\n>> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n>> ---\n>>  contrib/completion/git-completion.bash | 10 ++--------\n>>  1 file changed, 2 insertions(+), 8 deletions(-)\n>>\n>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n>> index 1c35eef..2ce4f7d 100644\n>> --- a/contrib/completion/git-completion.bash\n>> +++ b/contrib/completion/git-completion.bash\n>> @@ -427,14 +427,8 @@ __git_refs ()\n>>               done\n>>               ;;\n>>       *)\n>> -             git ls-remote \"$dir\" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \\\n>> -             while read -r hash i; do\n>> -                     case \"$i\" in\n>> -                     *^{}) ;;\n>> -                     refs/*) echo \"${i#refs/*/}\" ;;\n>> -                     *) echo \"$i\" ;;\n>> -                     esac\n>> -             done\n>> +             echo \"HEAD\"\n>> +             git for-each-ref --format=\"%(refname:short)\" -- \"refs/remotes/$dir/\" | sed -e \"s#^$dir/##\"\n>\n> This case statement is only executed when $dir is not a git directory,\n> so what ensures that the cwd is in a git repo or work tree when\n> executing this brach of the case statement?  What about 'git\n> --git-dir=/path/to/repo' invocations or when $GIT_DIR is specified?\n\n'git --git-dir=foo fetch <tab>' doesn't even work. I sent the patches\nto fix it, but as usual, nobody cared about actual real fixes.\n\n$GIT_DIR works fine, why wouldn't it?\n\n-- \nFelipe Contreras\n"},{"id":"219154","messageId":"CALkWK0nXPA7Rhcp1Reb0oBMXmW5SkL7zhy1786L9CjE74x7xTg@mail.gmail.com","threadId":"33964","inReplyTo":"1369797648-2921-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] completion: avoid ls-remote in certain scenarios","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-06-01T18:25:47Z","receivedAt":"2013-06-01T18:25:47Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Felipe Contreras wrote:\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 1c35eef..2ce4f7d 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -427,14 +427,8 @@ __git_refs ()\n>                 done\n>                 ;;\n>         *)\n> -               git ls-remote \"$dir\" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \\\n> -               while read -r hash i; do\n> -                       case \"$i\" in\n> -                       *^{}) ;;\n> -                       refs/*) echo \"${i#refs/*/}\" ;;\n> -                       *) echo \"$i\" ;;\n> -                       esac\n> -               done\n> +               echo \"HEAD\"\n> +               git for-each-ref --format=\"%(refname:short)\" -- \"refs/remotes/$dir/\" | sed -e \"s#^$dir/##\"\n\nYeah, this patch makes sense overall.  I'm curious as to what role\nORG_HEAD had to play originally, and why it's absent now.\n"},{"id":"219194","messageId":"7vip1wmahf.fsf@alter.siamese.dyndns.org","threadId":"33964","inReplyTo":"1369797648-2921-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] completion: avoid ls-remote in certain scenarios","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-06-02T22:08:44Z","receivedAt":"2013-06-02T22:08:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> It's _very_ slow in many cases, and there's really no point in fetching\n> *everything* from the remote just for completion. In many cases it might\n> be faster for the user to type the whole thing.\n\nBesides, if I understand the use of __git_refs correctly, it is\nprimarily about completing things like\n\n\tgit checkout -b topic origin/<TAB>\n\nwhere you actively want _local_ copies of what you currently have in\nrefs/remotes/origin/, not what you would get if you were to fetch\nand then type the command again, so in that sense, using ls-remote\nis a wrong thing to do in the first place.\n\nThis however may need to be made optional if this is also being used\nto complete\n\n\tgit fetch git://g.k.org/pub/scm/git/git.git/ <TAB>\n\nto list what can be fetched, but I do not think that is a very\ncommon thing to do (you either know what you want to fetch, in which\ncase you do not complete but copy & paste, or more likely you have a\nnamed remote and fetch the whole thing).\n\nSo I think overall the above makes sense.\n\n> If the user manually specifies 'refs/*', then the full ls-remote\n> completion is triggered.\n\n>\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>  contrib/completion/git-completion.bash | 10 ++--------\n>  1 file changed, 2 insertions(+), 8 deletions(-)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 1c35eef..2ce4f7d 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -427,14 +427,8 @@ __git_refs ()\n>  \t\tdone\n>  \t\t;;\n>  \t*)\n> -\t\tgit ls-remote \"$dir\" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \\\n> -\t\twhile read -r hash i; do\n> -\t\t\tcase \"$i\" in\n> -\t\t\t*^{}) ;;\n> -\t\t\trefs/*) echo \"${i#refs/*/}\" ;;\n> -\t\t\t*) echo \"$i\" ;;\n> -\t\t\tesac\n> -\t\tdone\n> +\t\techo \"HEAD\"\n> +\t\tgit for-each-ref --format=\"%(refname:short)\" -- \"refs/remotes/$dir/\" | sed -e \"s#^$dir/##\"\n>  \t\t;;\n>  \tesac\n>  }\n"},{"id":"219200","messageId":"CAMP44s0or-wtNc85HPO8hMA47xbcXVOcF0QcWvpLAyay0bB2Ag@mail.gmail.com","threadId":"33964","inReplyTo":"7vip1wmahf.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] completion: avoid ls-remote in certain scenarios","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-06-02T22:57:04Z","receivedAt":"2013-06-02T22:57:04Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Jun 2, 2013 at 5:08 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>\n>> It's _very_ slow in many cases, and there's really no point in fetching\n>> *everything* from the remote just for completion. In many cases it might\n>> be faster for the user to type the whole thing.\n>\n> Besides, if I understand the use of __git_refs correctly, it is\n> primarily about completing things like\n>\n>         git checkout -b topic origin/<TAB>\n>\n> where you actively want _local_ copies of what you currently have in\n> refs/remotes/origin/, not what you would get if you were to fetch\n> and then type the command again, so in that sense, using ls-remote\n> is a wrong thing to do in the first place.\n\nYeah, but we wouldn't use ls-remote in those cases, only when __gitdir\nis not available. Try 'git checkout <TAB>' outside a git repository.\n\n> This however may need to be made optional if this is also being used\n> to complete\n>\n>         git fetch git://g.k.org/pub/scm/git/git.git/ <TAB>\n>\n> to list what can be fetched, but I do not think that is a very\n> common thing to do (you either know what you want to fetch, in which\n> case you do not complete but copy & paste, or more likely you have a\n> named remote and fetch the whole thing).\n\nIndeed. And it doesn't make sense to punish the typical use-cases\nbecause of the atypical ones.\n\nBesides:\n\ngit fetch git://g.k.org/pub/scm/git/git.git/ refs/<TAB>\n\nWould still complete everything.\n\n-- \nFelipe Contreras\n"}]}