{"thread":{"id":"46892","subject":"[PATCH] emacs: work with remote filesystems","startedAt":"2017-10-03T16:33:44Z","lastAt":"2017-10-03T16:33:44Z","messageCount":1,"participants":["Enrico Scholz"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"329580","messageId":"20171003162348.25376-1-enrico.scholz@sigma-chemnitz.de","threadId":"46892","inReplyTo":null,"subject":"[PATCH] emacs: work with remote filesystems","fromName":"Enrico Scholz","fromEmail":"enrico.scholz@sigma-chemnitz.de","sentAt":"2017-10-03T16:23:48Z","receivedAt":"2017-10-03T16:33:44Z","isPatch":true,"sender":{"key":"enrico.scholz@sigma-chemnitz.de","avatar":null},"body":"With this patch, it is possible to work on remote filesystems which\nwere made accessible by tramp.\n\nFor example, 'M-x git-status /remote-host:/repository' will show the\nstatus of /repository on 'remote-host' and usual operations like add\nor commit are supported there.\n\nFirst part of the is patch is trivial and replaces 'call-process' with\nthe network transparent 'process-file'.\n\nThe second one is more extensive and implements a tramp wrapper for\n'call-process-region'.\n\nSigned-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>\n---\n contrib/emacs/git.el | 32 ++++++++++++++++++++++++++------\n 1 file changed, 26 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex 5ffc506..3d9d691 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -190,8 +190,8 @@ if there is already one that displays the same directory.\"\n   (mapcar (lambda (entry) (concat (car entry) \"=\" (cdr entry))) env))\n \n (defun git-call-process (buffer &rest args)\n-  \"Wrapper for call-process that sets environment strings.\"\n-  (apply #'call-process \"git\" nil buffer nil args))\n+  \"Wrapper for process-file that sets environment strings.\"\n+  (apply #'process-file \"git\" nil buffer nil args))\n \n (defun git-call-process-display-error (&rest args)\n   \"Wrapper for call-process that displays error messages.\"\n@@ -221,14 +221,34 @@ the process output as a string, or nil if the git command failed.\"\n       (display-message-or-buffer (current-buffer))\n       nil)))\n \n+(defun git-tramp-call-process-region (start end program\n+                                            &optional delete buffer display\n+                                            &rest args)\n+  \"call-process-region variant for tramp\"\n+  (let ((tmpfile (tramp-compat-make-temp-file \"\")))\n+    (unwind-protect\n+        (progn\n+          (write-region start end tmpfile)\n+          (when delete (delete-region start end))\n+          (apply #'process-file program tmpfile buffer display args))\n+      (delete-file tmpfile))))\n+\n (defun git-run-process-region (buffer start end program args)\n   \"Run a git process with a buffer region as input.\"\n-  (let ((output-buffer (current-buffer))\n-        (dir default-directory))\n+  (let ((dir default-directory)\n+        (fh (find-file-name-handler default-directory 'call-process-region))\n+        (fnargs (apply 'list start end program\n+                       nil (list (current-buffer) t) nil args)))\n     (with-current-buffer buffer\n       (cd dir)\n-      (apply #'call-process-region start end program\n-             nil (list output-buffer t) nil args))))\n+      (case fh\n+        ;; special handling for tramp\n+        (tramp-file-name-handler\n+         (apply #'git-tramp-call-process-region fnargs))\n+        ;; the default (local-file) handler\n+        ((nil) (apply #'call-process-region fnargs))\n+        ;; else, when there is a handler, call it\n+        (t (apply fh #'call-process-region fnargs))))))\n \n (defun git-run-command-buffer (buffer-name &rest args)\n   \"Run a git command, sending the output to a buffer named BUFFER-NAME.\"\n-- \n2.9.5\n\n"}]}