tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

suggested optimization for file-in-directory-p


From: Harvey Chapman
Subject: suggested optimization for file-in-directory-p
Date: Tue, 10 Nov 2015 23:04:13 -0500

I was having a problem with Magit and Tramp: http://emacs.stackexchange.com/questions/17929/can-magit-be-configured-to-not-touch-read-every-buffer-in-emacs

The problem was that telling the magit-status buffer to refresh would cause all of my tramp buffers to attempt to connect to their remotes.

This answer was provided and recommended to be passed along to this list in the hope that Tramp might make this optimization, too.


Answer:

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]