>From 761d90a2cdef562576a66fc16060b653adacd676 Mon Sep 17 00:00:00 2001 From: Andrey Portnoy Date: Tue, 1 Oct 2024 20:48:35 -0400 Subject: [PATCH] Use tramp-optimize-remote-path in a separate function --- lisp/tramp-sh.el | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lisp/tramp-sh.el b/lisp/tramp-sh.el index 9e813ecc..9e5ccc4d 100644 --- a/lisp/tramp-sh.el +++ b/lisp/tramp-sh.el @@ -4129,6 +4129,9 @@ This function expects to be in the right *tramp* buffer." (setq result (buffer-substring (point) (line-end-position))))) result))) +(defvar tramp-optimize-remote-path t + "Whether to remove duplicate and non-existing directories from remote PATH.") + ;; On hydra.nixos.org, the $PATH environment variable is too long to ;; send it. This is likely not due to PATH_MAX, but PIPE_BUF. We ;; check it, and use a temporary file in case of. See Bug#33781. @@ -4162,6 +4165,11 @@ variable PATH." (tramp-send-command vec (format ". %s" tmpfile)) (tramp-send-command vec (format "rm -f %s" tmpfile))))) +(defun tramp-maybe-set-remote-path (vec) + (if (or tramp-optimize-remote-path + (not (equal tramp-remote-path '(tramp-own-remote-path)))) + (tramp-set-remote-path vec))) + ;; ------------------------------------------------------------ ;; -- Communication with external shell -- ;; ------------------------------------------------------------ @@ -4511,7 +4519,7 @@ process to set up. VEC specifies the connection." (if (string-match-p (rx (| "FreeBSD" "DragonFly")) uname) 500 0)))) ;; Set remote PATH variable. - (tramp-set-remote-path vec) + (tramp-maybe-set-remote-path vec) ;; Search for a good shell before searching for a command which ;; checks if a file exists. This is done because Tramp wants to @@ -5610,17 +5618,21 @@ Nonexistent directories are removed from spec." (cdr elt2))) (setq remote-path (delq 'tramp-own-remote-path remote-path))) - ;; Remove double entries. - (setq remote-path - (cl-remove-duplicates - remote-path :test #'string-equal :from-end t)) - - ;; Remove non-existing directories. - (let (remote-file-name-inhibit-cache) - (tramp-bundle-read-file-names vec remote-path) - (cl-remove-if - (lambda (x) (not (tramp-get-file-property vec x "file-directory-p"))) - remote-path)))))) + (when tramp-optimize-remote-path + ;; Remove double entries. + (setq remote-path + (cl-remove-duplicates + remote-path :test #'string-equal :from-end t)) + + ;; Remove non-existing directories. + (let (remote-file-name-inhibit-cache) + (tramp-bundle-read-file-names vec remote-path) + (setq remote-path + (cl-remove-if + (lambda (x) + (not (tramp-get-file-property vec x "file-directory-p"))) + remote-path)))) + remote-path)))) ;; The PIPE_BUF in POSIX [1] can be as low as 512 [2]. Here are the values ;; on various platforms: -- 2.39.5 (Apple Git-154)