Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] _git: don't treat URI schemes as scp-style remotes



__git_remote_repositories matched any "*:", so https://... became
host "https" and _remote_files performed an unnecessary ssh/DNS lookup
(and could hang if name resolution misbehaves), especially with
continuous autocomplete. Skip known URI schemes for bare scheme,
scheme:, scheme:/, and scheme://...; keep scp-style scheme:path and
scheme:/abs.
---
 Completion/Unix/Command/_git | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index c4ed3c3e9..160128a4a 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -8137,9 +8137,21 @@ __git_tree_files () {
 
 (( $+functions[__git_remote_repositories] )) ||
 __git_remote_repositories () {
+  # scp-style is [user@]host:path; URIs use scheme://...
+  # Matching any "*:" would treat https://... as host "https" and
+  # _remote_files would make an unnecessary ssh/DNS lookup (and can hang if
+  # name resolution misbehaves). For known URI schemes:
+  #   https / https: / https:/ / https://...  -> not scp (return)
+  #   https:path / https:/abs/path           -> still scp-style
   if compset -P '*:'; then
+    if [[ ${IPREFIX%:} == (#i)(http|https|ftp|ftps|git|ssh|file) &&
+          ( -z $PREFIX || $PREFIX == / || $PREFIX == //* ) ]]; then
+      return 1
+    fi
     _remote_files -/ -- ssh
   else
+    # Completing the host part: do not offer a bare URI scheme as an scp host.
+    [[ $PREFIX == (#i)(http|https|ftp|ftps|git|ssh|file) ]] && return 1
     _ssh_hosts -S:
   fi
 }
-- 
2.55.0





Messages sorted by: Reverse Date, Date, Thread, Author