git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] completion: avoid ls-remote in certain scenarios

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 29, 2013, 03:20 UTC
Message-ID
<1369797648-2921-1-git-send-email-felipe.contreras@gmail.com>

It's _very_ slow in many cases, and there's really no point in fetching *everything* from the remote just for completion. In many cases it might be faster for the user to type the whole thing.

If the user manually specifies 'refs/*', then the full ls-remote completion is triggered.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1c35eef..2ce4f7d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -427,14 +427,8 @@ __git_refs ()
 		done
 		;;
 	*)
-		git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
-		while read -r hash i; do
-			case "$i" in
-			*^{}) ;;
-			refs/*) echo "${i#refs/*/}" ;;
-			*) echo "$i" ;;
-			esac
-		done
+		echo "HEAD"
+		git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
 		;;
 	esac
 }
-- 
1.8.3.rc3.312.g47657de
Next: SZEDER Gábor
Message 1 of 6 in “completion: avoid ls-remote in certain scenarios”
  1. completion: avoid ls-remote in certain scenariosFelipe Contreras, May 29, 2013
  2. SZEDER GáborMay 29, 2013
  3. Felipe ContrerasJun 1, 2013
  4. Ramkumar RamachandraJun 1, 2013
  5. Junio C HamanoJun 2, 2013
  6. Felipe ContrerasJun 2, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.