6

Summary:

Magit is constantly forcing my tramp/ssh buffers to connect remotely to their source machines. The buffers are all unrelated to the repo I'm working with. How do I stop this? The tramp/ssh buffers do contain git-versioned files.

Backstory:

I have a number of tramp/ssh buffers open in my Emacs to a virtual machine. Due to a years-old bug in VMware Fusion, I must close it before putting my laptop to sleep or Fusion crashes my entire laptop. I leave the Emacs buffers open because they'll reconnect to the VM after restarting it. I don't close the tramp/ssh files because my desktop setup doesn't seem to restore tramp buffers on a restart of Emacs, and I spent a lot of time finding each of those files among thousands of files.

Problem:

If I try to use Magit on a local repo unrelated to my VM work, it causes all of my tramp buffers to try to re-connect and tramp blocks Emacs until it succeeds or fails.

** Backtrace (toggle-debug-on-quit): **

Debugger entered--Lisp error: (quit)
  signal(quit nil)
  byte-code("\302\303\"\210\304 @   A\"\207" [vec err tramp-cleanup-connection t signal] 3)
  tramp-maybe-open-connection(["ssh" nil "and" "/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" nil])
  tramp-send-command(["ssh" nil "and" "/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" nil] "echo \\\"`getconf PATH 2>/dev/null`\\\" 2>/dev/null; echo tramp_exit_status $?")
  tramp-send-command-and-check(["ssh" nil "and" "/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" nil] "echo \\\"`getconf PATH 2>/dev/null`\\\"")
  tramp-send-command-and-read(["ssh" nil "and" "/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" nil] "echo \\\"`getconf PATH 2>/dev/null`\\\"" noerror)
  tramp-get-remote-path(["ssh" nil "and" "/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" nil])
  tramp-get-remote-readlink(["ssh" nil "and" "/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" nil])
  tramp-sh-handle-file-truename("/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c")
  apply(tramp-sh-handle-file-truename "/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c")
  tramp-sh-file-name-handler(file-truename "/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c")
  apply(tramp-sh-file-name-handler file-truename "/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c")
  byte-code("\300\301\215\207" [suppress (apply foreign operation args)] 2)
  byte-code("K\306\211<\203\237\n@\307=\203\237\306\310\311!\203\"\312\311\313N@!\206\221\314\315!\2039\316\315!\2044\317\315!\205\221\315 \202\221\320\321!\211\205D\322\f!)\203P\323\320\321!!\202\221\320\324!\211\205[\322\f!)\203g\323\320\324!!\202\221\320\325!\211\205r\322\f!)\203~\323\320\325!!\202\221\326\327!\203\212\323\327!\202\221\330\331!\210\323\332!)\333\n\211A@\262\334\335#\210)\336\337\215\211\336=\203\312*\340\341+,BC-./0\306\342\343\217,\210\344+,\"\202\374    \345=\203\373\3061*\346\347+,BC-./0\306\342\343\217,\210\350*\351\"\210\344+,\")\202\374    *\207" [foreign result sf file-name-handler-alist d default-directory nil autoload boundp temporary-file-directory eval standard-value fboundp temp-directory subrp functionp getenv "TEMP" file-directory-p file-name-as-directory "TMP" "TMPDIR" file-exists-p "c:/temp" message "Neither `temporary-file-directory' nor `temp-directory' is defined -- using /tmp." "/tmp" load noerror nomessage non-essential (byte-code "\300\301\215\207" [suppress (apply foreign operation args)] 2) 5 "Non-essential received in operation %s" (byte-code "   X\205g\306 \307\216\203;\310X\203;\311\312\313U\203!\314\2026\315U\203+\314\2026\316U\2035\317\2026\320\fP
#\210   \321Y\205f\322!\203S\313\323\324\325#)\326!\205f\311\327\330\331\"\fP
$*\207" [level tramp-verbose save-match-data-internal tramp-message-show-message fmt-string arguments match-data ((byte-code "\301\302\"\207" [save-match-data-internal set-match-data evaporate] 3)) 3 apply message 0 "" 1 2 "Warning: " "Tramp: " 4 processp tramp-get-connection-property "vector" nil vectorp tramp-debug-message format "(%d) # " vec-or-proc] 6) ((error)) tramp-run-real-handler suppress 1 "Suppress received in operation %s" tramp-cleanup-connection t v operation args arguments fmt-string level vec-or-proc tramp-message-show-message] 6)
  tramp-file-name-handler(file-truename "/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c")
  file-truename("/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c")
  file-in-directory-p("/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" "/Users/hchapman/work/RDM/")
  apply(file-in-directory-p ("/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" "/Users/hchapman/work/RDM/"))
  tramp-run-real-handler(file-in-directory-p ("/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" "/Users/hchapman/work/RDM/"))
  tramp-sh-file-name-handler(file-in-directory-p "/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" "/Users/hchapman/work/RDM/")
  apply(tramp-sh-file-name-handler file-in-directory-p ("/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" "/Users/hchapman/work/RDM/"))
  byte-code("\300\301\215\207" [suppress (apply foreign operation args)] 2)
  byte-code("K\306\211<\203\237\n@\307=\203\237\306\310\311!\203\"\312\311\313N@!\206\221\314\315!\2039\316\315!\2044\317\315!\205\221\315 \202\221\320\321!\211\205D\322\f!)\203P\323\320\321!!\202\221\320\324!\211\205[\322\f!)\203g\323\320\324!!\202\221\320\325!\211\205r\322\f!)\203~\323\320\325!!\202\221\326\327!\203\212\323\327!\202\221\330\331!\210\323\332!)\333\n\211A@\262\334\335#\210)\336\337\215\211\336=\203\312*\340\341+,BC-./0\306\342\343\217,\210\344+,\"\202\374    \345=\203\373\3061*\346\347+,BC-./0\306\342\343\217,\210\350*\351\"\210\344+,\")\202\374    *\207" [foreign result sf file-name-handler-alist d default-directory nil autoload boundp temporary-file-directory eval standard-value fboundp temp-directory subrp functionp getenv "TEMP" file-directory-p file-name-as-directory "TMP" "TMPDIR" file-exists-p "c:/temp" message "Neither `temporary-file-directory' nor `temp-directory' is defined -- using /tmp." "/tmp" load noerror nomessage non-essential (byte-code "\300\301\215\207" [suppress (apply foreign operation args)] 2) 5 "Non-essential received in operation %s" (byte-code "   X\205g\306 \307\216\203;\310X\203;\311\312\313U\203!\314\2026\315U\203+\314\2026\316U\2035\317\2026\320\fP
#\210   \321Y\205f\322!\203S\313\323\324\325#)\326!\205f\311\327\330\331\"\fP
$*\207" [level tramp-verbose save-match-data-internal tramp-message-show-message fmt-string arguments match-data ((byte-code "\301\302\"\207" [save-match-data-internal set-match-data evaporate] 3)) 3 apply message 0 "" 1 2 "Warning: " "Tramp: " 4 processp tramp-get-connection-property "vector" nil vectorp tramp-debug-message format "(%d) # " vec-or-proc] 6) ((error)) tramp-run-real-handler suppress 1 "Suppress received in operation %s" tramp-cleanup-connection t v operation args arguments fmt-string level vec-or-proc tramp-message-show-message] 6)
  tramp-file-name-handler(file-in-directory-p "/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" "/Users/hchapman/work/RDM/")
  file-in-directory-p("/ssh:and:/android/out/RDM/output/android_os_build/kernel_imx/drivers/video/mxc/mxc_hdmi.c" "/Users/hchapman/work/RDM/")
  magit-revert-buffers()
  magit-refresh()
  call-interactively(magit-refresh nil nil)
  command-execute(magit-refresh)
  • What's your magit-revert-buffers set to? – npostavs Nov 8 '15 at 4:15
  • How do you know it's Magit doing it? – tarsius Nov 8 '15 at 17:39
  • @npostavs: I haven't configured magit in any way. It is set to usage. Also, I'm using Magit 20151105.1932, Git 2.4.9 (Apple Git-60), Emacs 24.5.1 – Harvey Nov 8 '15 at 23:59
  • @tarsius: because if I hit g in the magit-status buffer, it does it. – Harvey Nov 9 '15 at 0:01
  • According to the docs, it should only be reverting buffers belonging to the current repo. None of my tramp buffers are files in the same repo. – Harvey Nov 9 '15 at 0:11
4

The problem is that ultimately tramp-sh-handle-file-truename is called which needs to make remote connections.

(Previously Tramp also tries to handle file-in-directory-p itself but since it eventually figures out that it does not implement a handler for that function and just falls back to the vanilla file-in-directory-p, that doesn't cause any remote connections. Except that file-in-directory-p does call file-truename and that, as stated earlier, does make remote connections.)

This patch was applied (will be part of v2.3.1) to fix this issue:

diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 271cc5f..d187cf5 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -833,6 +833,8 @@ (defun magit-revert-buffers (&optional force)
                   (--filter
                    (let ((file (buffer-file-name it)))
                      (and file
+                          (equal (file-remote-p file)
+                                 (file-remote-p topdir))
                           (file-in-directory-p file topdir)
                           (member (file-relative-name file topdir) tracked)))
                    (buffer-list))

This checks whether the file (each file which is being visited in some buffer in turn) and the directory/repository topdir are located on the same remote (nil for the local machine) before checking whether the file is located inside that directory. Obviously a file cannot possibly be located inside a directory which isn't even located on the same machine, so in that case we can bail before performing the more expensive check.

  • Arguably, Tramp should perform this optimization. I suggest you report this to Michael Albinus. – Stefan Nov 9 '15 at 14:33
  • Thank you! The patch worked. By "report," did you mean just report back here or also to report the behavior to tramp/emacs/other? – Harvey Nov 9 '15 at 15:23
  • @Stefan: Agreed, I was going to suggest the same. #Harvey: Well, what I originally meant was that you should test the patch and let me know whether it worked for you (don't see why it wouldn't, but making sure cannot hurt). But now I am with Stefan and think you should "report" (as in "suggest that he adds this optimization") this to Michael (on lists.gnu.org/mailman/listinfo/tramp-devel). I'll apply this patch anyway. – tarsius Nov 9 '15 at 15:45
  • @tarsius: will do. – Harvey Nov 11 '15 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.