Web lists-archives.com

[PATCH] emacs: work with remote filesystems

With this patch, it is possible to work on remote filesystems which
were made accessible by tramp.

For example, 'M-x git-status /remote-host:/repository' will show the
status of /repository on 'remote-host' and usual operations like add
or commit are supported there.

First part of the is patch is trivial and replaces 'call-process' with
the network transparent 'process-file'.

The second one is more extensive and implements a tramp wrapper for

Signed-off-by: Enrico Scholz <enrico.scholz@xxxxxxxxxxxxxxxxx>
 contrib/emacs/git.el | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 5ffc506..3d9d691 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -190,8 +190,8 @@ if there is already one that displays the same directory."
   (mapcar (lambda (entry) (concat (car entry) "=" (cdr entry))) env))
 (defun git-call-process (buffer &rest args)
-  "Wrapper for call-process that sets environment strings."
-  (apply #'call-process "git" nil buffer nil args))
+  "Wrapper for process-file that sets environment strings."
+  (apply #'process-file "git" nil buffer nil args))
 (defun git-call-process-display-error (&rest args)
   "Wrapper for call-process that displays error messages."
@@ -221,14 +221,34 @@ the process output as a string, or nil if the git command failed."
       (display-message-or-buffer (current-buffer))
+(defun git-tramp-call-process-region (start end program
+                                            &optional delete buffer display
+                                            &rest args)
+  "call-process-region variant for tramp"
+  (let ((tmpfile (tramp-compat-make-temp-file "")))
+    (unwind-protect
+        (progn
+          (write-region start end tmpfile)
+          (when delete (delete-region start end))
+          (apply #'process-file program tmpfile buffer display args))
+      (delete-file tmpfile))))
 (defun git-run-process-region (buffer start end program args)
   "Run a git process with a buffer region as input."
-  (let ((output-buffer (current-buffer))
-        (dir default-directory))
+  (let ((dir default-directory)
+        (fh (find-file-name-handler default-directory 'call-process-region))
+        (fnargs (apply 'list start end program
+                       nil (list (current-buffer) t) nil args)))
     (with-current-buffer buffer
       (cd dir)
-      (apply #'call-process-region start end program
-             nil (list output-buffer t) nil args))))
+      (case fh
+        ;; special handling for tramp
+        (tramp-file-name-handler
+         (apply #'git-tramp-call-process-region fnargs))
+        ;; the default (local-file) handler
+        ((nil) (apply #'call-process-region fnargs))
+        ;; else, when there is a handler, call it
+        (t (apply fh #'call-process-region fnargs))))))
 (defun git-run-command-buffer (buffer-name &rest args)
   "Run a git command, sending the output to a buffer named BUFFER-NAME."