]> git.eshelyaron.com Git - emacs.git/commitdiff
Adapt some changes of last Tramp commit
authorMichael Albinus <michael.albinus@gmx.de>
Tue, 29 Aug 2023 09:30:20 +0000 (11:30 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Tue, 29 Aug 2023 09:30:20 +0000 (11:30 +0200)
* lisp/net/tramp-container.el (tramp-container--completion-function):
Use METHOD as argument, instead of PROGRAM.  Determine program
from METHOD entry in `tramp-methods'.  Bind `non-essential' to
nil.  Use a file property as cache.
(tramp-container--completion-function): Use adapted arguments when
setting for "docker" and "podman".

* lisp/net/tramp.el (tramp--last-hop-directory): Adapt docstring.
Move down.
(tramp-set-completion-function): Revert default case to
`file-exists-p', the workaround isn't needed anymore.
(tramp-get-completion-methods): Rename argument to MULTI-HOP.
(tramp-completion-remote-containers): Add :version.
(tramp-multi-hop-p): Bind `tramp-verbose' to nil.

lisp/net/tramp-container.el
lisp/net/tramp.el

index e5ad3a55e27058d2c84e00e03ff19730c44ce0f9..687092e7e959111d9d12bb79a43b958e96ae8d90 100644 (file)
@@ -158,31 +158,39 @@ If it is nil, the default context will be used."
   "Tramp method name to use to connect to Flatpak sandboxes.")
 
 ;;;###tramp-autoload
-(defun tramp-container--completion-function (program)
+(defun tramp-container--completion-function (method)
   "List running containers available for connection.
-PROGRAM is the program to be run for \"ps\", either
-`tramp-docker-program' or `tramp-podman-program'.
+METHOD is the Tramp method to be used for \"ps\", either
+`tramp-docker-method' or `tramp-podman-method'.
 
 This function is used by `tramp-set-completion-function', please
 see its function help for a description of the format."
-  ;; Set the default-directory to the directory of the last hop
-  ;; of a multi-hop path so that we can run the container program
-  ;; from there. If this is not a multi-hop path, run from the local
-  ;; temp file directory.
-  (when-let ((default-directory (or (and tramp-completion-remote-containers tramp--last-hop-directory)
-                                    tramp-compat-temporary-file-directory))
-            (raw-list (shell-command-to-string
-                       (concat program " ps --format '{{.ID}}\t{{.Names}}'")))
-             (lines (split-string raw-list "\n" 'omit))
-             (names (mapcar
-                    (lambda (line)
-                       (when (string-match
-                             (rx bol (group (1+ nonl))
-                                 "\t" (? (group (1+ nonl))) eol)
-                             line)
-                        (or (match-string 2 line) (match-string 1 line))))
-                     lines)))
-    (mapcar (lambda (name) (list nil name)) (delq nil names))))
+  (let ((default-directory
+        (or (and tramp-completion-remote-containers tramp--last-hop-directory)
+            tramp-compat-temporary-file-directory))
+       (program (tramp-get-method-parameter
+                 (make-tramp-file-name :method method) 'tramp-login-program))
+       non-essential)
+    ;; We don't use connection properties, because this information
+    ;; shouldn't be kept persistently.
+    (with-tramp-file-property
+       (when (tramp-tramp-file-p default-directory)
+         (tramp-dissect-file-name default-directory))
+       (concat "/" method ":") "user-host-completions"
+      (when-let ((raw-list
+                 (shell-command-to-string
+                  (concat program " ps --format '{{.ID}}\t{{.Names}}'")))
+                (lines (split-string raw-list "\n" 'omit))
+                (names
+                 (mapcar
+                  (lambda (line)
+                    (when (string-match
+                           (rx bol (group (1+ nonl))
+                               "\t" (? (group (1+ nonl))) eol)
+                           line)
+                      (or (match-string 2 line) (match-string 1 line))))
+                  lines)))
+       (mapcar (lambda (name) (list nil name)) (delq nil names))))))
 
 ;;;###tramp-autoload
 (defun tramp-kubernetes--completion-function (&rest _args)
@@ -387,13 +395,11 @@ see its function help for a description of the format."
 
  (tramp-set-completion-function
   tramp-docker-method
-  `((tramp-container--completion-function
-     ,tramp-docker-program)))
+  `((tramp-container--completion-function ,tramp-docker-method)))
 
  (tramp-set-completion-function
   tramp-podman-method
-  `((tramp-container--completion-function
-     ,tramp-podman-program)))
+  `((tramp-container--completion-function ,tramp-podman-method)))
 
  (tramp-set-completion-function
   tramp-kubernetes-method
index 01a8356697509bb5281ace851d1b188b093964a8..9d555c5621b9225726ad1ec6a517fe041e36ad77 100644 (file)
@@ -81,8 +81,6 @@
 (defvar tramp-file-name-regexp)
 (defvar tramp-completion-method-regexp)
 (defvar tramp-completion-file-name-regexp)
-(defvar tramp--last-hop-directory nil
-  "Tracks the directory from which to run container executable programs.")
 
 ;; Reload `tramp-compat' when we reload `tramp-autoloads' of the GNU
 ;; ELPA package.
@@ -2143,10 +2141,8 @@ Example:
                      tramp-dns-sd-service-regexp (nth 1 (car v))))
                    ;; Method.
                    ((string-equal method (nth 1 (car v))))
-                    ;; FIXME: for now do not check local existence of file
-                    ;; to allow allow arbitrary container program executable
-                    ;; name for container completion on remote systems.
-                    (t t)))
+                   ;; Configuration file or empty string.
+                   (t (file-exists-p (nth 1 (car v))))))
        (setq r (delete (car v) r)))
       (setq v (cdr v)))
 
@@ -2724,6 +2720,9 @@ not in completion mode."
 
       (tramp-run-real-handler #'file-exists-p (list filename))))
 
+(defvar tramp--last-hop-directory nil
+  "Tracks the directory from which to run login programs.")
+
 ;; Method, host name and user name completion.
 ;; `tramp-completion-dissect-file-name' returns a list of
 ;; `tramp-file-name' structures.  For all of them we return possible
@@ -2759,7 +2758,7 @@ not in completion mode."
 
       ;; Possible completion structures.
       (dolist (elt (tramp-completion-dissect-file-name fullname))
-        (let* ((method (tramp-file-name-method elt))
+       (let* ((method (tramp-file-name-method elt))
               (user (tramp-file-name-user elt))
               (host (tramp-file-name-host elt))
               (localname (tramp-file-name-localname elt))
@@ -2770,8 +2769,8 @@ not in completion mode."
 
            (if (or user host)
 
-               ;; Method dependent user / host combinations.
-               (progn
+               ;; Method dependent user / host combinations.
+               (progn
                  (mapc
                   (lambda (x)
                     (setq all-user-hosts
@@ -2780,12 +2779,12 @@ not in completion mode."
                   (tramp-get-completion-function m))
 
                  (setq result
-                       (append result
-                               (mapcar
-                                (lambda (x)
+                       (append result
+                               (mapcar
+                                (lambda (x)
                                   (tramp-get-completion-user-host
                                    method user host (nth 0 x) (nth 1 x)))
-                                (delq nil all-user-hosts)))))
+                                (delq nil all-user-hosts)))))
 
              ;; Possible methods.
              (setq result
@@ -2924,13 +2923,13 @@ remote host and localname (filename on remote host)."
 
 ;; This function returns all possible method completions, adding the
 ;; trailing method delimiter.
-(defun tramp-get-completion-methods (partial-method hop)
+(defun tramp-get-completion-methods (partial-method multi-hop)
   "Return all method completions for PARTIAL-METHOD.
-If HOP is non-nil, return only multi-hop capable methods."
+If MULTI-HOP is non-nil, return only multi-hop capable methods."
   (mapcar
    (lambda (method)
      (and method (string-prefix-p (or partial-method "") method)
-         (or (not hop)
+         (or (not multi-hop)
              (tramp-multi-hop-p (make-tramp-file-name :method method)))
          (tramp-completion-make-tramp-file-name method nil nil nil)))
    (mapcar #'car tramp-methods)))
@@ -3012,6 +3011,7 @@ for all methods.  Resulting data are derived from default settings."
 
 (defcustom tramp-completion-remote-containers nil
   "Whether container hosts in multi-hop paths should be queried for completions."
+  :version "30.1"
   :type 'boolean)
 
 (defcustom tramp-completion-use-auth-sources auth-source-do-cache
@@ -4585,8 +4585,9 @@ Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.")
 
 (defun tramp-multi-hop-p (vec)
   "Whether the method of VEC is capable of multi-hops."
-  (and (tramp-sh-file-name-handler-p vec)
-       (not (tramp-get-method-parameter vec 'tramp-copy-program))))
+  (let ((tramp-verbose 0))
+    (and (tramp-sh-file-name-handler-p vec)
+        (not (tramp-get-method-parameter vec 'tramp-copy-program)))))
 
 (defun tramp-add-hops (vec)
   "Add ad-hoc proxy definitions to `tramp-default-proxies-alist'."