Subject: Re: bug#70901: 30.0.50; Tramp doesn't use ControlMaster even with (setq tramp-use-connection-share nil)

From: Michael Albinus <[email-masked]>
Date: Thu, 23 May 2024 18:25:00 +0200

Dmitry Gutov <[email-masked]> writes:

Hi Dmitry,

> 1. Somehow have a message that only spans the time the connection is
> established, and don't print the rest by default (the user will note
> when the action finished anyway, and there likely will be other
> messages corresponding to different operations - copying a file,
> opening it, etc). I'm not sure how to fit that into the described
> framework, but what if the new message was level 3 and the current was
> moved to level 4?

I've changed it such a way that the message "Opening connection ..."
appears only until the prompt from remote is seen. For the rest, there
will be another message "Setup connection ...".

As bonus, the "Opening connection ..." message appears now for every hop
in the multi-hop case. This is new.

Could you pls check the appended patch?

Best regards, Michael.

diff --git a/lisp/tramp-sh.el b/lisp/tramp-sh.el
index 569922a9..1233c635 100644
--- a/lisp/tramp-sh.el
+++ b/lisp/tramp-sh.el
@@ -5263,18 +5263,7 @@ connection if a previous connection has died for some reason."
       ;; New connection must be opened.
       (condition-case err
 	  (unless (process-live-p p)
-	    (with-tramp-progress-reporter
-		vec 3
-		(if (tramp-string-empty-or-nil-p (tramp-file-name-user vec))
-		    (format "Opening connection %s for %s using %s"
-			    process-name
-			    (tramp-file-name-host vec)
-			    (tramp-file-name-method vec))
-		  (format "Opening connection %s for %s@%s using %s"
-			  process-name
-			  (tramp-file-name-user vec)
-			  (tramp-file-name-host vec)
-			  (tramp-file-name-method vec)))
+	    (progn

 	      (catch 'uname-changed
 		;; Start new process.
@@ -5424,15 +5413,23 @@ connection if a previous connection has died for some reason."
 			" "))

 		      ;; Send the command.
-		      (tramp-message vec 3 "Sending command `%s'" command)
-		      (tramp-send-command vec command t t)
-		      (tramp-process-actions
-		       p vec
-		       (min
-			pos (with-current-buffer (process-buffer p) (point-max)))
-		       tramp-actions-before-shell connection-timeout)
-		      (tramp-message
-		       vec 3 "Found remote shell prompt on `%s'" l-host)
+		      (with-tramp-progress-reporter
+			  vec 3
+			  (if (tramp-string-empty-or-nil-p l-user)
+			      (format "Opening connection %s for %s using %s"
+				      process-name l-host l-method)
+			    (format "Opening connection %s for %s@%s using %s"
+				    process-name l-user l-host l-method))
+
+			(tramp-message vec 3 "Sending command `%s'" command)
+			(tramp-send-command vec command t t)
+			(tramp-process-actions
+			 p vec
+			 (min
+			  pos (with-current-buffer (process-buffer p) (point-max)))
+			 tramp-actions-before-shell connection-timeout)
+			(tramp-message
+			 vec 3 "Found remote shell prompt on `%s'" l-host))

 		      ;; Next hop.
 		      (setq options ""
@@ -5446,7 +5443,18 @@ connection if a previous connection has died for some reason."
 		     #'tramp-timeout-session vec))

 		  ;; Make initial shell settings.
-		  (tramp-open-connection-setup-interactive-shell p vec)
+		  (with-tramp-progress-reporter
+		      vec 3
+		      (if (tramp-string-empty-or-nil-p
+			   (tramp-file-name-user vec))
+			  (format "Setup connection %s for %s using %s"
+				  process-name (tramp-file-name-host vec)
+				  (tramp-file-name-method vec))
+			(format "Setup connection %s for %s@%s using %s"
+				process-name (tramp-file-name-user vec)
+				(tramp-file-name-host vec)
+				(tramp-file-name-method vec)))
+		    (tramp-open-connection-setup-interactive-shell p vec))

 		  ;; Mark it as connected.
 		  (tramp-set-connection-property p "connected" t)))))