1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

Tramp: Refactor environment variable filtering to a separate function

* lisp/net/tramp.el (tramp-local-environment-variable-p):
New function.  (Bug#79413)
(tramp-handle-make-process):
* lisp/net/tramp-sh.el (tramp-sh-handle-make-process)
(tramp-sh-handle-process-file):
* lisp/net/tramp-androidsu.el
(tramp-androidsu-handle-make-process):
Use `tramp-local-environment-variable-p'.
This commit is contained in:
Liu Hui 2025-09-12 12:43:54 +02:00 committed by Michael Albinus
parent 26ad23addb
commit e41eae39ad
3 changed files with 16 additions and 9 deletions

View file

@ -311,9 +311,7 @@ FUNCTION."
(when
(and
(string-search "=" elt)
(not
(member
elt (default-toplevel-value 'process-environment))))
(not (tramp-local-environment-variable-p elt)))
(setq env (cons elt env)))))
;; Add remote path if exists.
(env (let ((remote-path (string-join (tramp-get-remote-path v) ":")))

View file

@ -3052,8 +3052,7 @@ will be used."
;; `process-environment'.
env uenv
(env (dolist (elt (cons prompt process-environment) env)
(or (member
elt (default-toplevel-value 'process-environment))
(or (tramp-local-environment-variable-p elt)
(if (string-search "=" elt)
(setq env (append env `(,elt)))
(setq uenv (cons elt uenv))))))
@ -3288,7 +3287,7 @@ will be used."
(cons program args) " "))
;; We use as environment the difference to toplevel `process-environment'.
(dolist (elt process-environment)
(or (member elt (default-toplevel-value 'process-environment))
(or (tramp-local-environment-variable-p elt)
(if (string-search "=" elt)
(setq env (append env `(,elt)))
(setq uenv (cons elt uenv)))))

View file

@ -5347,6 +5347,18 @@ should be set connection-local.")
(or (not (stringp buffer)) (not (tramp-tramp-file-p buffer)))
(or (not (stringp stderr)) (not (tramp-tramp-file-p stderr))))))
;; This function is used by tramp-*-handle-make-process and
;; tramp-sh-handle-process-file to filter local environment variables
;; that should not be propagated remotely. Users can override this
;; function if necessary, for example, to ensure that a specific
;; environment variable is applied to remote processes, whether it
;; exists locally or not.
(defun tramp-local-environment-variable-p (arg)
"Return non-nil if ARG exists in default `process-environment'.
Tramp does not propagate local environment variables in remote
processes."
(member arg (default-toplevel-value 'process-environment)))
(defun tramp-handle-make-process (&rest args)
"An alternative `make-process' implementation for Tramp files."
(tramp-skeleton-make-process args nil nil
@ -5365,9 +5377,7 @@ should be set connection-local.")
(env (dolist (elt process-environment env)
(when (and
(string-search "=" elt)
(not
(member
elt (default-toplevel-value 'process-environment))))
(not (tramp-local-environment-variable-p elt)))
(setq env (cons elt env)))))
;; Add remote path if exists.
(env (if-let* ((sh-file-name-handler-p)