{"thread":{"id":"15601","subject":"[PATCH] bash: use for-each-ref format 'refname:short'","startedAt":"2008-09-19T22:15:25Z","lastAt":"2008-09-19T23:51:54Z","messageCount":2,"participants":["SZEDER Gábor","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"91149","messageId":"1221862525-20574-1-git-send-email-szeder@ira.uka.de","threadId":"15601","inReplyTo":null,"subject":"[PATCH] bash: use for-each-ref format 'refname:short'","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-09-19T22:15:25Z","receivedAt":"2008-09-19T22:15:25Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Using this format simplifies the code for completing refs and (in some\ncases) improves performance significantly.\n\nFor repositories like the current git.git (with more than 200 refs)\nthere is no real performance difference, but for a repository with 2000\nrefs the total time needed to complete the refs is reduced by ~25% (from\naround 400ms to around 305ms).\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n\n OK, so after the refname:short patch hit master, here is the updated\n patch to use it in bash completion.  The patch itself is the same as\n the original one, except, of course, the for-each-ref format name.  I\n have also adjusted the performance numbers in the commit message.\n\n contrib/completion/git-completion.bash |   26 ++++++--------------------\n 1 files changed, 6 insertions(+), 20 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex d3fb6ae..fccb499 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -154,11 +154,8 @@ __git_heads ()\n {\n \tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n \tif [ -d \"$dir\" ]; then\n-\t\tfor i in $(git --git-dir=\"$dir\" \\\n-\t\t\tfor-each-ref --format='%(refname)' \\\n-\t\t\trefs/heads ); do\n-\t\t\techo \"${i#refs/heads/}\"\n-\t\tdone\n+\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n+\t\t\trefs/heads\n \t\treturn\n \tfi\n \tfor i in $(git ls-remote \"$1\" 2>/dev/null); do\n@@ -175,11 +172,8 @@ __git_tags ()\n {\n \tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n \tif [ -d \"$dir\" ]; then\n-\t\tfor i in $(git --git-dir=\"$dir\" \\\n-\t\t\tfor-each-ref --format='%(refname)' \\\n-\t\t\trefs/tags ); do\n-\t\t\techo \"${i#refs/tags/}\"\n-\t\tdone\n+\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n+\t\t\trefs/tags\n \t\treturn\n \tfi\n \tfor i in $(git ls-remote \"$1\" 2>/dev/null); do\n@@ -197,16 +191,8 @@ __git_refs ()\n \tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n \tif [ -d \"$dir\" ]; then\n \t\tif [ -e \"$dir/HEAD\" ]; then echo HEAD; fi\n-\t\tfor i in $(git --git-dir=\"$dir\" \\\n-\t\t\tfor-each-ref --format='%(refname)' \\\n-\t\t\trefs/tags refs/heads refs/remotes); do\n-\t\t\tcase \"$i\" in\n-\t\t\t\trefs/tags/*)    echo \"${i#refs/tags/}\" ;;\n-\t\t\t\trefs/heads/*)   echo \"${i#refs/heads/}\" ;;\n-\t\t\t\trefs/remotes/*) echo \"${i#refs/remotes/}\" ;;\n-\t\t\t\t*)              echo \"$i\" ;;\n-\t\t\tesac\n-\t\tdone\n+\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n+\t\t\trefs/tags refs/heads refs/remotes\n \t\treturn\n \tfi\n \tfor i in $(git ls-remote \"$dir\" 2>/dev/null); do\n-- \n1.6.0.2.294.g50836f\n"},{"id":"91156","messageId":"20080919235154.GE13139@spearce.org","threadId":"15601","inReplyTo":"1221862525-20574-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH] bash: use for-each-ref format 'refname:short'","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-19T23:51:54Z","receivedAt":"2008-09-19T23:51:54Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"SZEDER GGGbor <szeder@ira.uka.de> wrote:\n> Using this format simplifies the code for completing refs and (in some\n> cases) improves performance significantly.\n> \n> For repositories like the current git.git (with more than 200 refs)\n> there is no real performance difference, but for a repository with 2000\n> refs the total time needed to complete the refs is reduced by ~25% (from\n> around 400ms to around 305ms).\n> \n> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>\n\nNice improvement.\n\nAcked-by: Shawn O. Pearce <spearce@spearce.org>\n\n\n>  OK, so after the refname:short patch hit master, here is the updated\n>  patch to use it in bash completion.  The patch itself is the same as\n>  the original one, except, of course, the for-each-ref format name.  I\n>  have also adjusted the performance numbers in the commit message.\n> \n>  contrib/completion/git-completion.bash |   26 ++++++--------------------\n>  1 files changed, 6 insertions(+), 20 deletions(-)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index d3fb6ae..fccb499 100755\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -154,11 +154,8 @@ __git_heads ()\n>  {\n>  \tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n>  \tif [ -d \"$dir\" ]; then\n> -\t\tfor i in $(git --git-dir=\"$dir\" \\\n> -\t\t\tfor-each-ref --format='%(refname)' \\\n> -\t\t\trefs/heads ); do\n> -\t\t\techo \"${i#refs/heads/}\"\n> -\t\tdone\n> +\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n> +\t\t\trefs/heads\n>  \t\treturn\n>  \tfi\n>  \tfor i in $(git ls-remote \"$1\" 2>/dev/null); do\n> @@ -175,11 +172,8 @@ __git_tags ()\n>  {\n>  \tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n>  \tif [ -d \"$dir\" ]; then\n> -\t\tfor i in $(git --git-dir=\"$dir\" \\\n> -\t\t\tfor-each-ref --format='%(refname)' \\\n> -\t\t\trefs/tags ); do\n> -\t\t\techo \"${i#refs/tags/}\"\n> -\t\tdone\n> +\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n> +\t\t\trefs/tags\n>  \t\treturn\n>  \tfi\n>  \tfor i in $(git ls-remote \"$1\" 2>/dev/null); do\n> @@ -197,16 +191,8 @@ __git_refs ()\n>  \tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n>  \tif [ -d \"$dir\" ]; then\n>  \t\tif [ -e \"$dir/HEAD\" ]; then echo HEAD; fi\n> -\t\tfor i in $(git --git-dir=\"$dir\" \\\n> -\t\t\tfor-each-ref --format='%(refname)' \\\n> -\t\t\trefs/tags refs/heads refs/remotes); do\n> -\t\t\tcase \"$i\" in\n> -\t\t\t\trefs/tags/*)    echo \"${i#refs/tags/}\" ;;\n> -\t\t\t\trefs/heads/*)   echo \"${i#refs/heads/}\" ;;\n> -\t\t\t\trefs/remotes/*) echo \"${i#refs/remotes/}\" ;;\n> -\t\t\t\t*)              echo \"$i\" ;;\n> -\t\t\tesac\n> -\t\tdone\n> +\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n> +\t\t\trefs/tags refs/heads refs/remotes\n>  \t\treturn\n>  \tfi\n>  \tfor i in $(git ls-remote \"$dir\" 2>/dev/null); do\n\n-- \nShawn.\n"}]}