aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2024-11-09 10:29:42 +0100
committerMichael Albinus2024-11-09 10:29:42 +0100
commit6cde51f1bbcfd55fe8d189b045247b9d80dee4ea (patch)
tree50dbfdb104191ccab847fd83864f8dc211db07d9
parent200214ca68f00722bf906bbf2a2afa81d139d5dc (diff)
downloademacs-6cde51f1bbcfd55fe8d189b045247b9d80dee4ea.tar.gz
emacs-6cde51f1bbcfd55fe8d189b045247b9d80dee4ea.zip
Tramp: Support different proxies for the same destination
* doc/misc/tramp.texi (Ad-hoc multi-hops): New subsection "Using different proxies for the same destination". * etc/NEWS: Tramp supports different proxies for the same destination host name in parallel. Fix typos. * lisp/net/tramp-cmds.el (tramp-cleanup-connection): Fix docstring. * lisp/net/tramp.el (tramp-make-tramp-file-name): Don't call `tramp-add-hops' during file name completion. (tramp-handle-file-name-as-directory) (tramp-handle-file-name-directory): Use `tramp-cache-undefined' for an empty `tramp-default-proxies-alist'. (tramp-add-hops): Extend. Remove existing entries with same target and different proxy, if needed. (Bug#74219)
-rw-r--r--doc/misc/tramp.texi24
-rw-r--r--etc/NEWS39
-rw-r--r--lisp/net/tramp-cmds.el10
-rw-r--r--lisp/net/tramp.el35
4 files changed, 81 insertions, 27 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 96ec6d60b9e..a014319c02c 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -3914,6 +3914,30 @@ shall be taken, add a proper rule to the user option
3914@end lisp 3914@end lisp
3915 3915
3916 3916
3917@subsection Using different proxies for the same destination
3918
3919@strong{Note}: This feature is experimental, don't use it in
3920production systems!
3921
3922Sometimes, it is needed to specify different proxies for the same
3923destination host name. This can happen for the same destination when
3924the local host is located in different networks over the time. This
3925can also happen when the remote destination is specified by the remote
3926same file name, although different hosts are meant depending on the
3927used proxy. A typical example are docker containers, which run on
3928different hosts under the same docker name.
3929
3930When the user option @code{tramp-show-ad-hoc-proxies} is
3931non-@code{nil}, such ad-hoc multi-hop file names can be used in
3932parallel. In the following, on both remote hosts @samp{host1} and
3933@samp{host2} there is a docker container @samp{name}, respectively:
3934
3935@example
3936@trampfn{ssh@value{postfixhop}user1@@host1|docker,name,}
3937@trampfn{ssh@value{postfixhop}user2@@host2|docker,name,}
3938@end example
3939
3940
3917@node Home directories 3941@node Home directories
3918@section Expanding @file{~} to home directory 3942@section Expanding @file{~} to home directory
3919 3943
diff --git a/etc/NEWS b/etc/NEWS
index 19b8b7bb70b..689f85270c9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -183,8 +183,8 @@ Input methods are now implemented for Haudenosaunee languages in the
183Northern Iroquoian language family: 'mohawk-postfix' (Mohawk 183Northern Iroquoian language family: 'mohawk-postfix' (Mohawk
184[Kanien’kéha / Onkwehonwehnéha]), 'oneida-postfix' (Oneida [Onʌyota:ká: 184[Kanien’kéha / Onkwehonwehnéha]), 'oneida-postfix' (Oneida [Onʌyota:ká:
185/ Ukwehuwehnéha]), 'cayuga-postfix' (Cayuga [Gayogo̱ho:nǫhnéha:ˀ]), 185/ Ukwehuwehnéha]), 'cayuga-postfix' (Cayuga [Gayogo̱ho:nǫhnéha:ˀ]),
186'onondaga-postfix (Onondaga [[Onųdaʔgegáʔ]), and `seneca-postfix' 186'onondaga-postfix' (Onondaga [Onųdaʔgegáʔ]), and 'seneca-postfix'
187[Onödowá’ga:’]). Additionally, there is a general-purpose 187(Seneca [Onödowá’ga:’]). Additionally, there is a general-purpose
188'haudenosaunee-postfix' input method to facilitate writing in the 188'haudenosaunee-postfix' input method to facilitate writing in the
189orthographies of the five languages simultaneously. 189orthographies of the five languages simultaneously.
190 190
@@ -267,7 +267,7 @@ It removes all the buttons in the specified region.
267This command scrolls the screen so that only the current prompt is 267This command scrolls the screen so that only the current prompt is
268visible, optionally erasing all the previous input/output as well. 268visible, optionally erasing all the previous input/output as well.
269Previously, the Eshell built-in command 'eshell/clear' supported this 269Previously, the Eshell built-in command 'eshell/clear' supported this
270(e.g. to call it via 'M-x'), but this new command behaves more 270(e.g., to call it via 'M-x'), but this new command behaves more
271consistently if you have a partially-typed command at the Eshell prompt. 271consistently if you have a partially-typed command at the Eshell prompt.
272 272
273--- 273---
@@ -486,6 +486,19 @@ The host name for Kubernetes connections can be of kind
486used. This overrides the setting in 'tramp-kubernetes-namespace', if 486used. This overrides the setting in 'tramp-kubernetes-namespace', if
487any. 487any.
488 488
489+++
490*** Different proxies for the same destination host name can be specified.
491A typical example are docker containers, which run on different hosts
492under the same docker name. When the user option
493'tramp-show-ad-hoc-proxies' is non-nil, such ad-hoc multi-hop file names
494can be used in parallel. Example: on both remote hosts "host1" and
495"host2" there is a docker container "name", respectively:
496
497 /ssh:user1@host1|docker:name:
498 /ssh:user2@host2|docker:name:
499
500This feature is experimental.
501
489** Diff 502** Diff
490 503
491--- 504---
@@ -562,17 +575,17 @@ be set as a connection-local variable.
562 575
563--- 576---
564*** New user option 'dired-hide-details-hide-absolute-location'. 577*** New user option 'dired-hide-details-hide-absolute-location'.
565When dired's 'dired-hide-details-mode' is enabled, also hide the 578When Dired's 'dired-hide-details-mode' is enabled, also hide the
566'default-directory' absolute location, typically displayed as the first 579'default-directory' absolute location, typically displayed as the first
567line in a dired buffer. 580line in a Dired buffer.
568 581
569With dired-hide-details-hide-absolute-location: 582With 'dired-hide-details-hide-absolute-location':
570 583
571 project: (100 GiB available) 584 project: (100 GiB available)
572 585
573Without dired-hide-details-hide-absolute-location: 586Without 'dired-hide-details-hide-absolute-location':
574 587
575 /absolute/path/to/my/important/project: (100 GiB available) 588 /absolute/path/to/my/important/project: (100 GiB available)
576 589
577** Grep 590** Grep
578 591
@@ -622,7 +635,7 @@ The hardcoded '^' shortcut gets you back to the previous menu.
622--- 635---
623*** New user option 'tmm-shortcut-inside-entry'. 636*** New user option 'tmm-shortcut-inside-entry'.
624When non-nil, highlight the character shortcut in the menu entry's 637When non-nil, highlight the character shortcut in the menu entry's
625string instead of preprending it and `tmm-mid-prompt' to said entry. 638string instead of preprending it and 'tmm-mid-prompt' to said entry.
626 639
627** Foldout 640** Foldout
628 641
@@ -655,8 +668,8 @@ of seconds. Crossfading can be toggled using the command
655*** New user option 'vc-allow-rewriting-published-history'. 668*** New user option 'vc-allow-rewriting-published-history'.
656Some VCS commands can change your copy of published change history 669Some VCS commands can change your copy of published change history
657without warning. In VC we try to detect before that happens, and stop. 670without warning. In VC we try to detect before that happens, and stop.
658You can customize this variable to permit rewriting history 671You can customize this option to permit rewriting history even though
659even though Emacs thinks it is dangerous. 672Emacs thinks it is dangerous.
660 673
661--- 674---
662*** 'vc-clone' is now an interactive command. 675*** 'vc-clone' is now an interactive command.
@@ -846,7 +859,7 @@ variable 'w32-inhibit-dwrite' to t. Also see 'w32-dwrite-available' and
846'w32-dwrite-reinit' to check availability and to configure the 859'w32-dwrite-reinit' to check availability and to configure the
847DirectWrite rendering parameters. 860DirectWrite rendering parameters.
848 861
849To show color Emoji in Emacs, customize the default fontset to use a 862To show color Emojis in Emacs, customize the default fontset to use a
850color Emoji font installed on your system for the 'emoji' script. 863color Emoji font installed on your system for the 'emoji' script.
851 864
852+++ 865+++
diff --git a/lisp/net/tramp-cmds.el b/lisp/net/tramp-cmds.el
index 1b90ba6540b..f2ecf8173be 100644
--- a/lisp/net/tramp-cmds.el
+++ b/lisp/net/tramp-cmds.el
@@ -118,11 +118,11 @@ Each function is called with the current vector as argument.")
118(defun tramp-cleanup-connection 118(defun tramp-cleanup-connection
119 (vec &optional keep-debug keep-password keep-processes) 119 (vec &optional keep-debug keep-password keep-processes)
120 "Flush all connection related objects. 120 "Flush all connection related objects.
121This includes password cache, file cache, connection cache, 121This includes password cache, file cache, connection cache, buffers,
122buffers, processes. KEEP-DEBUG non-nil preserves the debug 122processes. KEEP-DEBUG non-nil preserves the debug and trace buffer.
123buffer. KEEP-PASSWORD non-nil preserves the password cache. 123KEEP-PASSWORD non-nil preserves the password cache. KEEP-PROCESSES
124KEEP-PROCESSES non-nil preserves the asynchronous processes. 124non-nil preserves the asynchronous processes. When called
125When called interactively, a Tramp connection has to be selected." 125interactively, a Tramp connection has to be selected."
126 (declare (completion tramp-active-command-completion-p)) 126 (declare (completion tramp-active-command-completion-p))
127 (interactive 127 (interactive
128 ;; When interactive, select the Tramp remote identification. 128 ;; When interactive, select the Tramp remote identification.
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index a137b5aeadc..0a61ca7e40d 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1886,7 +1886,8 @@ expected to be a string, which will be used."
1886 ;; Assure that the hops are in `tramp-default-proxies-alist'. 1886 ;; Assure that the hops are in `tramp-default-proxies-alist'.
1887 ;; In tramp-archive.el, the slot `hop' is used for the archive 1887 ;; In tramp-archive.el, the slot `hop' is used for the archive
1888 ;; file name. 1888 ;; file name.
1889 (unless (string-equal method tramp-archive-method) 1889 (unless (or minibuffer-completing-file-name
1890 (string-equal method tramp-archive-method))
1890 (tramp-add-hops (car args))))) 1891 (tramp-add-hops (car args)))))
1891 1892
1892 (t (setq method (nth 0 args) 1893 (t (setq method (nth 0 args)
@@ -4177,7 +4178,7 @@ Let-bind it when necessary.")
4177 ;; the empty string. Suppress adding a hop to 4178 ;; the empty string. Suppress adding a hop to
4178 ;; `tramp-default-proxies-alist' due to non-expanded default values. 4179 ;; `tramp-default-proxies-alist' due to non-expanded default values.
4179 (let ((v (tramp-dissect-file-name file t)) 4180 (let ((v (tramp-dissect-file-name file t))
4180 tramp-default-proxies-alist) 4181 (tramp-default-proxies-alist tramp-cache-undefined))
4181 ;; Run the command on the localname portion only unless we are in 4182 ;; Run the command on the localname portion only unless we are in
4182 ;; completion mode. 4183 ;; completion mode.
4183 (tramp-make-tramp-file-name 4184 (tramp-make-tramp-file-name
@@ -4271,7 +4272,7 @@ Let-bind it when necessary.")
4271 ;; the remote file name parts. Suppress adding a hop to 4272 ;; the remote file name parts. Suppress adding a hop to
4272 ;; `tramp-default-proxies-alist' due to non-expanded default values. 4273 ;; `tramp-default-proxies-alist' due to non-expanded default values.
4273 (let ((v (tramp-dissect-file-name file t)) 4274 (let ((v (tramp-dissect-file-name file t))
4274 tramp-default-proxies-alist) 4275 (tramp-default-proxies-alist tramp-cache-undefined))
4275 ;; Run the command on the localname portion only. If this returns 4276 ;; Run the command on the localname portion only. If this returns
4276 ;; nil, mark also the localname part of `v' as nil. 4277 ;; nil, mark also the localname part of `v' as nil.
4277 (tramp-make-tramp-file-name 4278 (tramp-make-tramp-file-name
@@ -4912,21 +4913,37 @@ Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.")
4912 4913
4913(defun tramp-add-hops (vec) 4914(defun tramp-add-hops (vec)
4914 "Add ad-hoc proxy definitions to `tramp-default-proxies-alist'." 4915 "Add ad-hoc proxy definitions to `tramp-default-proxies-alist'."
4915 (when-let* ((hops (tramp-file-name-hop vec)) 4916 ;; `tramp-default-proxies-alist' is bound to `tramp-cache-undefined'
4917 ;; in `tramp-handle-file-name-as-directory' and
4918 ;; `tramp-handle-file-name-directory' suppressing to add a hop.
4919 (when-let* (((not (eq tramp-default-proxies-alist tramp-cache-undefined)))
4920 (hops (tramp-file-name-hop vec))
4916 (item vec)) 4921 (item vec))
4917 (let (signal-hook-function changed) 4922 (let (signal-hook-function changed)
4918 (dolist 4923 (dolist
4919 (proxy (reverse (split-string hops tramp-postfix-hop-regexp 'omit))) 4924 (proxy (reverse (split-string hops tramp-postfix-hop-regexp 'omit)))
4920 (let* ((host-port (tramp-file-name-host-port item)) 4925 (let* ((host-port (tramp-file-name-host-port item))
4926 (host-port (and (stringp host-port)
4927 (rx bol (literal host-port) eol)))
4921 (user-domain (tramp-file-name-user-domain item)) 4928 (user-domain (tramp-file-name-user-domain item))
4929 (user-domain (and (stringp user-domain)
4930 (rx bol (literal user-domain) eol)))
4922 (proxy (concat 4931 (proxy (concat
4923 tramp-prefix-format proxy tramp-postfix-host-format)) 4932 tramp-prefix-format proxy tramp-postfix-host-format))
4924 (entry 4933 (entry
4925 (list (and (stringp host-port) 4934 (list host-port user-domain (propertize proxy 'tramp-ad-hoc t))))
4926 (rx bol (literal host-port) eol)) 4935 ;; Remove superfluous entries.
4927 (and (stringp user-domain) 4936 (when tramp-show-ad-hoc-proxies
4928 (rx bol (literal user-domain) eol)) 4937 (dolist (entry1 tramp-default-proxies-alist)
4929 (propertize proxy 'tramp-ad-hoc t)))) 4938 (when (and (equal host-port (car entry1))
4939 (equal user-domain (cadr entry1))
4940 (not (equal proxy (caddr entry1))))
4941 (tramp-message
4942 vec 5 "Remove %S from `tramp-default-proxies-alist'" entry1)
4943 (tramp-cleanup-connection
4944 vec 'keep-debug 'keep-password 'keep-processes)
4945 (setq tramp-default-proxies-alist
4946 (delete entry1 tramp-default-proxies-alist)))))
4930 ;; Add the hop. 4947 ;; Add the hop.
4931 (unless (member entry tramp-default-proxies-alist) 4948 (unless (member entry tramp-default-proxies-alist)
4932 (tramp-message vec 5 "Add %S to `tramp-default-proxies-alist'" entry) 4949 (tramp-message vec 5 "Add %S to `tramp-default-proxies-alist'" entry)