]> git.eshelyaron.com Git - emacs.git/commitdiff
Morka handling of multi-hops in Tramp more consistent
authorMichael Albinus <michael.albinus@gmx.de>
Tue, 18 Jan 2022 10:27:15 +0000 (11:27 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Tue, 18 Jan 2022 10:27:15 +0000 (11:27 +0100)
* lisp/net/tramp.el (tramp-make-tramp-file-name): Adapt argument list.
Add hops to `tramp-default-proxies-alist'.
(tramp-find-foreign-file-name-handler): Adapt argument list.
(tramp-handle-abbreviate-file-name): Abbreviate multi-hops.
(tramp-handle-file-remote-p): Adapt handling of hops.
(tramp-add-hops): New defun.
(tramp-compute-multi-hops): Use it.

* lisp/net/tramp.el (tramp-make-tramp-hop-name, tramp-get-buffer)
(tramp-file-name-handler, tramp-handle-file-truename)
(tramp-handle-insert-file-contents, tramp-local-host-p)
(tramp-read-passwd, tramp-clear-passwd):
* lisp/net/tramp-archive.el (tramp-archive-dissect-file-name)
(tramp-archive-gvfs-file-name):
* lisp/net/tramp-cache.el (tramp-get-hash-table):
* lisp/net/tramp-sh.el (tramp-sh-handle-file-truename)
(tramp-sh-handle-make-process, tramp-sh-handle-process-file)
(tramp-sh-file-name-handler-p, tramp-get-remote-path):
* lisp/net/tramp-sshfs.el (tramp-sshfs-handle-process-file):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-file-truename):
Adapt callees.

* test/lisp/net/tramp-tests.el (tramp-test02-file-name-dissect)
(tramp-test02-file-name-dissect-simplified)
(tramp-test02-file-name-dissect-separate)
(tramp-test07-abbreviate-file-name): Adapt tests.

lisp/net/tramp-adb.el
lisp/net/tramp-archive.el
lisp/net/tramp-cache.el
lisp/net/tramp-sh.el
lisp/net/tramp-sshfs.el
lisp/net/tramp-sudoedit.el
lisp/net/tramp.el
test/lisp/net/tramp-tests.el

index 699dec4d58e2772870ee69f7d06dcdebad9080ed..75e6b7179b0b603a50c76fd28bc1c63245f4d5fa 100644 (file)
@@ -776,7 +776,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
 (defun tramp-adb-get-signal-strings (vec)
   "Strings to return by `process-file' in case of signals."
   (with-tramp-connection-property vec "signal-strings"
-    (let ((default-directory (tramp-make-tramp-file-name vec 'localname))
+    (let ((default-directory (tramp-make-tramp-file-name vec 'noloc))
          ;; `shell-file-name' and `shell-command-switch' are needed
          ;; for Emacs < 27.1, which doesn't support connection-local
          ;; variables in `shell-command'.
index 8a88057d38a7b000df602b867f683df9f8b08b90..d3f427932f383cd8b615ead0614c4f9d8e501322 100644 (file)
@@ -457,7 +457,7 @@ name is kept in slot `hop'"
        ((tramp-archive-file-name-p archive)
        (let ((archive
               (tramp-make-tramp-file-name
-               (tramp-archive-dissect-file-name archive) nil 'noarchive)))
+                (tramp-archive-dissect-file-name archive))))
          (setf (tramp-file-name-host vec) (tramp-archive-gvfs-host archive)))
        (puthash archive (list vec) tramp-archive-hash))
 
@@ -560,8 +560,7 @@ offered."
 
 (defun tramp-archive-gvfs-file-name (name)
   "Return NAME in GVFS syntax."
-  (tramp-make-tramp-file-name
-   (tramp-archive-dissect-file-name name) nil 'nohop))
+  (tramp-make-tramp-file-name (tramp-archive-dissect-file-name name)))
 
 \f
 ;; File name primitives.
index 715b537247fe1372dd1893b6608cc3be9f81442b..1ab8f4d335b00e7bf81ac7f09e24a3c5e8e38b67 100644 (file)
@@ -124,7 +124,7 @@ If KEY is `tramp-cache-undefined', don't create anything, and return nil."
            (dolist (elt tramp-connection-properties)
              (when (tramp-compat-string-search
                     (or (nth 0 elt) "")
-                    (tramp-make-tramp-file-name key 'noloc 'nohop))
+                    (tramp-make-tramp-file-name key 'noloc))
                (tramp-set-connection-property key (nth 1 elt) (nth 2 elt)))))
          hash))))
 
index ffa11b1fe3c0b331baf261d7550957789ca16820..f0ceabe568bd85335bb71515cd493ac87b16eca3 100644 (file)
@@ -1149,8 +1149,7 @@ component is used as the target of the symlink."
           (when (file-remote-p result)
             (setq result (tramp-compat-file-name-quote result 'top)))
           (tramp-message v 4 "True name of `%s' is `%s'" localname result)
-          result))
-       'nohop)))))
+          result)))))))
 
 ;; Basic functions.
 
@@ -2852,7 +2851,7 @@ implementation will be used."
                 ;; `shell'.  We discard hops, if existing, that's why
                 ;; we cannot use `file-remote-p'.
                 (prompt (format "PS1=%s %s"
-                                (tramp-make-tramp-file-name v nil 'nohop)
+                                (tramp-make-tramp-file-name v)
                                 tramp-initial-end-of-output))
                 ;; We use as environment the difference to toplevel
                 ;; `process-environment'.
@@ -3013,7 +3012,7 @@ implementation will be used."
       vec
       (concat
        "signal-strings-" (tramp-get-method-parameter vec 'tramp-remote-shell))
-    (let ((default-directory (tramp-make-tramp-file-name vec 'localname))
+    (let ((default-directory (tramp-make-tramp-file-name vec 'noloc))
          process-file-return-signal-string signals res result)
       (setq signals
            (append
@@ -3104,7 +3103,7 @@ implementation will be used."
            (setq input (tramp-file-local-name infile))
          ;; INFILE must be copied to remote host.
          (setq input (tramp-make-tramp-temp-file v)
-               tmpinput (tramp-make-tramp-file-name v input 'nohop))
+               tmpinput (tramp-make-tramp-file-name v input))
          (copy-file infile tmpinput t)))
       (when input (setq command (format "%s <%s" command input)))
 
@@ -3136,7 +3135,7 @@ implementation will be used."
            ;; stderr must be copied to remote host.  The temporary
            ;; file must be deleted after execution.
            (setq stderr (tramp-make-tramp-temp-file v)
-                 tmpstderr (tramp-make-tramp-file-name v stderr 'nohop))))
+                 tmpstderr (tramp-make-tramp-file-name v stderr))))
         ;; stderr to be discarded.
         ((null (cadr destination))
          (setq stderr (tramp-get-remote-null-device v)))))
@@ -3650,8 +3649,7 @@ Fall back to normal file name handler if no Tramp handler exists."
 (defun tramp-sh-file-name-handler-p (vec)
   "Whether VEC uses a method from `tramp-sh-file-name-handler'."
   (and (assoc (tramp-file-name-method vec) tramp-methods)
-       (eq (tramp-find-foreign-file-name-handler
-           (tramp-make-tramp-file-name vec nil 'nohop))
+       (eq (tramp-find-foreign-file-name-handler vec)
           'tramp-sh-file-name-handler)))
 
 ;; This must be the last entry, because `identity' always matches.
@@ -5441,7 +5439,7 @@ Nonexistent directories are removed from spec."
          (lambda (x)
            (and
             (stringp x)
-            (file-directory-p (tramp-make-tramp-file-name vec x 'nohop))
+            (file-directory-p (tramp-make-tramp-file-name vec x))
             x))
          remote-path))))))
 
index 8890d0ec5c3572e6a0fd01d2220cb89208f98d1e..72837793de4e5f48599f69ecd06203edc5257e3d 100644 (file)
@@ -255,7 +255,7 @@ arguments to pass to the OPERATION."
            (setq input (tramp-file-local-name infile))
          ;; INFILE must be copied to remote host.
          (setq input (tramp-make-tramp-temp-file v)
-               tmpinput (tramp-make-tramp-file-name v input 'nohop))
+               tmpinput (tramp-make-tramp-file-name v input))
          (copy-file infile tmpinput t)))
       (when input (setq command (format "%s <%s" command input)))
 
index a68d4b3e365883981ecc57cbd4c332214bd535b9..7fbe5412709a6926898dc6f0a41af201b87d02cb 100644 (file)
@@ -572,8 +572,7 @@ the result will be a local, non-Tramp, file name."
           (when (file-remote-p result)
             (setq result (tramp-compat-file-name-quote result 'top)))
           (tramp-message v 4 "True name of `%s' is `%s'" localname result)
-          result))
-       'nohop)))))
+          result)))))))
 
 (defun tramp-sudoedit-handle-file-writable-p (filename)
   "Like `file-writable-p' for Tramp files."
index 7d6157ed8c28b37a7b0fa2a128ac9f7fdd905ca1..3c6f4974d7d64659ba069ec2c8662fe5e786ed88 100644 (file)
@@ -1713,13 +1713,10 @@ See `tramp-dissect-file-name' for details."
   "Construct a Tramp file name from ARGS.
 
 ARGS could have two different signatures.  The first one is of
-type (VEC &optional LOCALNAME HOP).
+type (VEC &optional LOCALNAME).
 If LOCALNAME is nil, the value in VEC is used.  If it is a
 symbol, a null localname will be used.  Otherwise, LOCALNAME is
 expected to be a string, which will be used.
-If HOP is nil, the value in VEC is used.  If it is a symbol, a
-null hop will be used.  Otherwise, HOP is expected to be a
-string, which will be used.
 
 The other signature exists for backward compatibility.  It has
 the form (METHOD USER DOMAIN HOST PORT LOCALNAME &optional HOP)."
@@ -1735,8 +1732,10 @@ the form (METHOD USER DOMAIN HOST PORT LOCALNAME &optional HOP)."
            hop (tramp-file-name-hop (car args)))
       (when (cadr args)
        (setq localname (and (stringp (cadr args)) (cadr args))))
-      (when (cl-caddr args)
-       (setq hop (and (stringp (cl-caddr args)) (cl-caddr args)))))
+      (when hop
+       (setq hop nil)
+       ;; Assure that the hops are in `tramp-default-proxies-alist'.
+       (tramp-add-hops (car args))))
 
      (t (setq method (nth 0 args)
              user (nth 1 args)
@@ -1769,15 +1768,17 @@ the form (METHOD USER DOMAIN HOST PORT LOCALNAME &optional HOP)."
            localname)))
 
 (set-advertised-calling-convention
- #'tramp-make-tramp-file-name '(vec &optional localname hop) "27.1")
+ #'tramp-make-tramp-file-name '(vec &optional localname) "29.1")
 
 (defun tramp-make-tramp-hop-name (vec)
   "Construct a Tramp hop name from VEC."
-  (replace-regexp-in-string
-   tramp-prefix-regexp ""
+  (concat
+   (tramp-file-name-hop vec)
    (replace-regexp-in-string
-    (concat tramp-postfix-host-regexp "$") tramp-postfix-hop-format
-    (tramp-make-tramp-file-name vec 'noloc))))
+    tramp-prefix-regexp ""
+    (replace-regexp-in-string
+     (concat tramp-postfix-host-regexp "$") tramp-postfix-hop-format
+     (tramp-make-tramp-file-name vec 'noloc)))))
 
 (defun tramp-completion-make-tramp-file-name (method user host localname)
   "Construct a Tramp file name from METHOD, USER, HOST and LOCALNAME.
@@ -1811,7 +1812,7 @@ Unless DONT-CREATE, the buffer is created when it doesn't exist yet."
           (tramp-get-connection-property vec "process-buffer" nil))
          (setq buffer-undo-list t
                default-directory
-               (tramp-make-tramp-file-name vec 'noloc 'nohop))
+               (tramp-make-tramp-file-name vec 'noloc))
          (current-buffer)))))
 
 (defun tramp-get-connection-buffer (vec &optional dont-create)
@@ -2596,11 +2597,10 @@ Must be handled by the callers."
    ;; Unknown file primitive.
    (t (error "Unknown file I/O primitive: %s" operation))))
 
-(defun tramp-find-foreign-file-name-handler (filename &optional _operation)
+(defun tramp-find-foreign-file-name-handler (vec &optional _operation)
   "Return foreign file name handler if exists."
-  (when (tramp-tramp-file-p filename)
+  (when (tramp-file-name-p vec)
     (let ((handler tramp-foreign-file-name-handler-alist)
-          (vec (tramp-dissect-file-name filename))
          elt func res)
       (while handler
        (setq elt (car handler)
@@ -2633,7 +2633,7 @@ Fall back to normal file name handler if no Tramp file name handler exists."
           (with-parsed-tramp-file-name filename nil
             (let ((current-connection tramp-current-connection)
                  (foreign
-                  (tramp-find-foreign-file-name-handler filename operation))
+                  (tramp-find-foreign-file-name-handler v operation))
                  (signal-hook-function #'tramp-signal-hook-function)
                  result)
              ;; Set `tramp-current-connection'.
@@ -3351,7 +3351,7 @@ User is always nil."
         (tramp-compat-funcall 'directory-abbrev-make-regexp home-dir) filename)
         (tramp-make-tramp-file-name
         vec (concat "~" (substring filename (match-beginning 1))))
-      filename)))
+      (tramp-make-tramp-file-name (tramp-dissect-file-name filename)))))
 
 (defun tramp-handle-access-file (filename string)
   "Like `access-file' for Tramp files."
@@ -3678,8 +3678,8 @@ User is always nil."
   ;; We do not want traces in the debug buffer.
   (let ((tramp-verbose (min tramp-verbose 3)))
     (when (tramp-tramp-file-p filename)
-      (let* ((v (tramp-dissect-file-name filename))
-            (p (tramp-get-connection-process v))
+      (let* ((o (tramp-dissect-file-name filename))
+            (p (tramp-get-connection-process o))
             (c (and (process-live-p p)
                     (tramp-get-connection-property p "connected" nil))))
        ;; We expand the file name only, if there is already a connection.
@@ -3693,7 +3693,8 @@ User is always nil."
                ((eq identification 'user) (tramp-file-name-user-domain v))
                ((eq identification 'host) (tramp-file-name-host-port v))
                ((eq identification 'localname) localname)
-               ((eq identification 'hop) hop)
+               ;; Hop exists only in original dissected file name.
+               ((eq identification 'hop) (tramp-file-name-hop o))
                (t (tramp-make-tramp-file-name v 'noloc)))))))))
 
 (defun tramp-handle-file-selinux-context (_filename)
@@ -3744,8 +3745,7 @@ User is always nil."
                             (expand-file-name
                              symlink-target
                              (file-name-directory v2-localname))))
-                       v2-localname)
-                     'nohop)))
+                       v2-localname))))
             (when (>= numchase numchase-limit)
               (tramp-error
                v1 'file-error
@@ -3904,8 +3904,7 @@ User is always nil."
                            (cond
                             ((stringp remote-copy)
                              (file-local-copy
-                              (tramp-make-tramp-file-name
-                               v remote-copy 'nohop)))
+                              (tramp-make-tramp-file-name v remote-copy)))
                             ((stringp tramp-temp-buffer-file-name)
                              (copy-file
                               filename tramp-temp-buffer-file-name 'ok)
@@ -3948,7 +3947,7 @@ User is always nil."
                   (or remote-copy (null tramp-temp-buffer-file-name)))
          (delete-file local-copy))
        (when (stringp remote-copy)
-         (delete-file (tramp-make-tramp-file-name v remote-copy 'nohop))))
+         (delete-file (tramp-make-tramp-file-name v remote-copy))))
 
       ;; Result.
       (cons filename (cdr result)))))
@@ -4088,15 +4087,10 @@ Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.")
   (and (tramp-sh-file-name-handler-p vec)
        (not (tramp-get-method-parameter vec 'tramp-copy-program))))
 
-(defun tramp-compute-multi-hops (vec)
-  "Expands VEC according to `tramp-default-proxies-alist'."
-  (let ((saved-tdpa tramp-default-proxies-alist)
-       (target-alist `(,vec))
-       (hops (or (tramp-file-name-hop vec) ""))
-       (item vec)
-       choices proxy)
-
-    ;; Ad-hoc proxy definitions.
+(defun tramp-add-hops (vec)
+  "Add ad-hoc proxy definitions to `tramp-default-proxies-alist'."
+  (when-let ((hops (tramp-file-name-hop vec))
+            (item vec))
     (dolist (proxy (reverse (split-string hops tramp-postfix-hop-regexp 'omit)))
       (let* ((host-port (tramp-file-name-host-port item))
             (user-domain (tramp-file-name-user-domain item))
@@ -4113,9 +4107,19 @@ Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.")
        (add-to-list 'tramp-default-proxies-alist entry)
        (setq item (tramp-dissect-file-name proxy))))
     ;; Save the new value.
-    (when (and hops tramp-save-ad-hoc-proxies)
+    (when tramp-save-ad-hoc-proxies
       (customize-save-variable
-       'tramp-default-proxies-alist tramp-default-proxies-alist))
+       'tramp-default-proxies-alist tramp-default-proxies-alist))))
+
+(defun tramp-compute-multi-hops (vec)
+  "Expands VEC according to `tramp-default-proxies-alist'."
+  (let ((saved-tdpa tramp-default-proxies-alist)
+       (target-alist `(,vec))
+       (item vec)
+       choices proxy)
+
+    ;; Ad-hoc proxy definitions.
+    (tramp-add-hops vec)
 
     ;; Look for proxy hosts to be passed.
     (setq choices tramp-default-proxies-alist)
@@ -5462,8 +5466,7 @@ This handles also chrooted environments, which are not regarded as local."
      (null tramp-crypt-enabled)
      ;; The local temp directory must be writable for the other user.
      (file-writable-p
-      (tramp-make-tramp-file-name
-       vec tramp-compat-temporary-file-directory 'nohop))
+      (tramp-make-tramp-file-name vec tramp-compat-temporary-file-directory))
      ;; On some systems, chown runs only for root.
      (or (zerop (user-uid))
         (zerop (tramp-get-remote-uid vec 'integer))))))
@@ -5712,7 +5715,7 @@ Invokes `password-read' if available, `read-passwd' else."
               ;; multi-hop.
               (tramp-get-connection-property
                proc "password-vector" (process-get proc 'vector))
-              'noloc 'nohop))
+              'noloc))
         (pw-prompt
          (or prompt
              (with-current-buffer (process-buffer proc)
@@ -5789,7 +5792,7 @@ Invokes `password-read' if available, `read-passwd' else."
     (auth-source-forget
      `(:max 1 ,(and user-domain :user) ,user-domain
        :host ,host-port :port ,method))
-    (password-cache-remove (tramp-make-tramp-file-name vec 'noloc 'nohop))))
+    (password-cache-remove (tramp-make-tramp-file-name vec 'noloc))))
 
 (put #'tramp-clear-passwd 'tramp-suppress-trace t)
 
index a07d749916e01936d797369af82f7889c36cf408..1651ee4846e1b66ee8a1d4f5395ddd46e5437432 100644 (file)
@@ -796,8 +796,7 @@ Also see `ignore'."
           (string-equal
            (file-remote-p
             "/method1:user1@host1|method2:user2@host2:/path/to/file")
-           (format "/%s:%s@%s|%s:%s@%s:"
-                   "method1" "user1" "host1" "method2" "user2" "host2")))
+           "/method2:user2@host2:"))
          (should
           (string-equal
            (file-remote-p
@@ -833,10 +832,7 @@ Also see `ignore'."
              "/method1:user1@host1"
              "|method2:user2@host2"
              "|method3:user3@host3:/path/to/file"))
-           (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host2"
-                   "method3" "user3" "host3")))
+           "/method3:user3@host3:"))
          (should
           (string-equal
            (file-remote-p
@@ -895,10 +891,7 @@ Also see `ignore'."
              "/-:user1@host1"
              "|-:user2@host2"
              "|-:user3@host3:/path/to/file"))
-           (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host2"
-                   "method3" "user3" "host3")))
+           "/method3:user3@host3:"))
 
          ;; Expand `tramp-default-user-alist'.
          (add-to-list 'tramp-default-user-alist '("method1" "host1" "user1"))
@@ -911,10 +904,7 @@ Also see `ignore'."
              "/method1:host1"
              "|method2:host2"
              "|method3:host3:/path/to/file"))
-           (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host2"
-                   "method3" "user3" "host3")))
+           "/method3:user3@host3:"))
 
          ;; Expand `tramp-default-host-alist'.
          (add-to-list 'tramp-default-host-alist '("method1" "user1" "host1"))
@@ -927,10 +917,7 @@ Also see `ignore'."
              "/method1:user1@"
              "|method2:user2@"
              "|method3:user3@:/path/to/file"))
-           (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host2"
-                   "method3" "user3" "host3")))
+           "/method3:user3@host3:"))
 
          ;; Ad-hoc user name and host name expansion.
          (setq tramp-default-method-alist nil
@@ -943,10 +930,7 @@ Also see `ignore'."
              "/method1:user1@host1"
              "|method2:user2@"
              "|method3:user3@:/path/to/file"))
-           (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host1"
-                   "method3" "user3" "host1")))
+           "/method3:user3@host1:"))
          (should
           (string-equal
            (file-remote-p
@@ -955,11 +939,7 @@ Also see `ignore'."
              "|method2:user2@host2"
              "|method3:%u@%h"
              "|method4:user4%domain4@host4#1234:/path/to/file"))
-           (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s|%s:%s@%s:"
-                   "method1" "user2" "host2"
-                   "method2" "user2" "host2"
-                   "method3" "user4" "host4"
-                   "method4" "user4%domain4" "host4#1234"))))
+           "/method4:user4%domain4@host4#1234:")))
 
       ;; Exit.
       (tramp-change-syntax syntax))))
@@ -1147,7 +1127,7 @@ Also see `ignore'."
          (should
           (string-equal
            (file-remote-p "/user1@host1|user2@host2:/path/to/file")
-           (format "/%s@%s|%s@%s:" "user1" "host1" "user2" "host2")))
+           "/user2@host2:"))
          (should
           (string-equal
            (file-remote-p
@@ -1181,10 +1161,7 @@ Also see `ignore'."
              "/user1@host1"
              "|user2@host2"
              "|user3@host3:/path/to/file"))
-           (format "/%s@%s|%s@%s|%s@%s:"
-                   "user1" "host1"
-                   "user2" "host2"
-                   "user3" "host3")))
+           "/user3@host3:"))
          (should
           (string-equal
            (file-remote-p
@@ -1243,10 +1220,7 @@ Also see `ignore'."
              "/host1"
              "|host2"
              "|host3:/path/to/file"))
-           (format "/%s@%s|%s@%s|%s@%s:"
-                   "user1" "host1"
-                   "user2" "host2"
-                   "user3" "host3")))
+           "/user3@host3:"))
 
          ;; Expand `tramp-default-host-alist'.
          (add-to-list 'tramp-default-host-alist '(nil "user1" "host1"))
@@ -1259,10 +1233,7 @@ Also see `ignore'."
              "/user1@"
              "|user2@"
              "|user3@:/path/to/file"))
-           (format "/%s@%s|%s@%s|%s@%s:"
-                   "user1" "host1"
-                   "user2" "host2"
-                   "user3" "host3")))
+           "/user3@host3:"))
 
          ;; Ad-hoc user name and host name expansion.
          (setq tramp-default-user-alist nil
@@ -1274,10 +1245,7 @@ Also see `ignore'."
              "/user1@host1"
              "|user2@"
              "|user3@:/path/to/file"))
-           (format "/%s@%s|%s@%s|%s@%s:"
-                   "user1" "host1"
-                   "user2" "host1"
-                   "user3" "host1")))
+           "/user3@host1:"))
          (should
           (string-equal
            (file-remote-p
@@ -1286,11 +1254,7 @@ Also see `ignore'."
              "|user2@host2"
              "|%u@%h"
              "|user4%domain4@host4#1234:/path/to/file"))
-           (format "/%s@%s|%s@%s|%s@%s|%s@%s:"
-                   "user2" "host2"
-                   "user2" "host2"
-                   "user4" "host4"
-                   "user4%domain4" "host4#1234"))))
+           "/user4%domain4@host4#1234:")))
 
       ;; Exit.
       (tramp-change-syntax syntax))))
@@ -1786,8 +1750,7 @@ Also see `ignore'."
           (string-equal
            (file-remote-p
             "/[method1/user1@host1|method2/user2@host2]/path/to/file")
-           (format "/[%s/%s@%s|%s/%s@%s]"
-                   "method1" "user1" "host1" "method2" "user2" "host2")))
+           "/[method2/user2@host2]"))
          (should
           (string-equal
            (file-remote-p
@@ -1823,10 +1786,7 @@ Also see `ignore'."
              "/[method1/user1@host1"
              "|method2/user2@host2"
              "|method3/user3@host3]/path/to/file"))
-           (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host2"
-                   "method3" "user3" "host3")))
+           "/[method3/user3@host3]"))
          (should
           (string-equal
            (file-remote-p
@@ -1885,10 +1845,7 @@ Also see `ignore'."
              "/[/user1@host1"
              "|/user2@host2"
              "|/user3@host3]/path/to/file"))
-           (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host2"
-                   "method3" "user3" "host3")))
+           "/[method3/user3@host3]"))
 
          ;; Expand `tramp-default-user-alist'.
          (add-to-list 'tramp-default-user-alist '("method1" "host1" "user1"))
@@ -1901,10 +1858,7 @@ Also see `ignore'."
              "/[method1/host1"
              "|method2/host2"
              "|method3/host3]/path/to/file"))
-           (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host2"
-                   "method3" "user3" "host3")))
+           "/[method3/user3@host3]"))
 
          ;; Expand `tramp-default-host-alist'.
          (add-to-list 'tramp-default-host-alist '("method1" "user1" "host1"))
@@ -1917,10 +1871,7 @@ Also see `ignore'."
              "/[method1/user1@"
              "|method2/user2@"
              "|method3/user3@]/path/to/file"))
-           (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host2"
-                   "method3" "user3" "host3")))
+           "/[method3/user3@host3]"))
 
          ;; Ad-hoc user name and host name expansion.
          (setq tramp-default-method-alist nil
@@ -1933,10 +1884,7 @@ Also see `ignore'."
              "/[method1/user1@host1"
              "|method2/user2@"
              "|method3/user3@]/path/to/file"))
-           (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
-                   "method1" "user1" "host1"
-                   "method2" "user2" "host1"
-                   "method3" "user3" "host1")))
+           "/[method3/user3@host1]"))
          (should
           (string-equal
            (file-remote-p
@@ -1945,11 +1893,7 @@ Also see `ignore'."
              "|method2/user2@host2"
              "|method3/%u@%h"
              "|method4/user4%domain4@host4#1234]/path/to/file"))
-           (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s|%s/%s@%s]"
-                   "method1" "user2" "host2"
-                   "method2" "user2" "host2"
-                   "method3" "user4" "host4"
-                   "method4" "user4%domain4" "host4#1234"))))
+           "/[method4/user4%domain4@host4#1234]")))
 
       ;; Exit.
       (tramp-change-syntax syntax))))
@@ -2286,17 +2230,20 @@ This checks also `file-name-as-directory', `file-name-directory',
   (skip-unless (not (tramp--test-ange-ftp-p)))
 
   (let* ((remote-host (file-remote-p tramp-test-temporary-file-directory))
+        (remote-host-nohop
+         (tramp-make-tramp-file-name (tramp-dissect-file-name remote-host)))
         ;; Not all methods can expand "~".
-         (home-dir (ignore-errors (expand-file-name (concat remote-host "~")))))
+         (home-dir (ignore-errors (expand-file-name (concat remote-host "~"))))
+        home-dir-nohop)
     (skip-unless home-dir)
 
     ;; Check home-dir abbreviation.
     (unless (string-suffix-p "~" home-dir)
       (should (equal (abbreviate-file-name (concat home-dir "/foo/bar"))
-                     (concat remote-host "~/foo/bar")))
+                     (concat remote-host-nohop "~/foo/bar")))
       (should (equal (abbreviate-file-name
                      (concat remote-host "/nowhere/special"))
-                     (concat remote-host "/nowhere/special"))))
+                     (concat remote-host-nohop "/nowhere/special"))))
 
     ;; Check `directory-abbrev-alist' abbreviation.
     (let ((directory-abbrev-alist
@@ -2305,18 +2252,20 @@ This checks also `file-name-as-directory', `file-name-directory',
              (,(concat "\\`" (regexp-quote remote-host) "/nowhere")
               . ,(concat remote-host "/nw")))))
       (should (equal (abbreviate-file-name (concat home-dir "/foo/bar"))
-                     (concat remote-host "~/f/bar")))
+                     (concat remote-host-nohop "~/f/bar")))
       (should (equal (abbreviate-file-name
                      (concat remote-host "/nowhere/special"))
-                     (concat remote-host "/nw/special"))))
+                     (concat remote-host-nohop "/nw/special"))))
 
     ;; Check that home-dir abbreviation doesn't occur when home-dir is just "/".
-    (setq home-dir (concat remote-host "/"))
+    (setq home-dir (concat remote-host "/")
+         home-dir-nohop
+         (tramp-make-tramp-file-name (tramp-dissect-file-name home-dir)))
     ;; The remote home directory is kept in the connection property
     ;; "home-directory".  We fake this setting.
     (tramp-set-connection-property tramp-test-vec "home-directory" home-dir)
-    (should (equal (concat home-dir "foo/bar")
-                   (abbreviate-file-name (concat home-dir "foo/bar"))))
+    (should (equal (abbreviate-file-name (concat home-dir "foo/bar"))
+                  (concat home-dir-nohop "foo/bar")))
     (tramp-flush-connection-property tramp-test-vec "home-directory")))
 
 (ert-deftest tramp-test07-file-exists-p ()