[PATCH] emacs: work with remote filesystems

2017-10-03 Thread Enrico Scholz
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
'call-process-region'.

Signed-off-by: Enrico Scholz 
---
 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))
   nil)))
 
+(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."
-- 
2.9.5



[PATCH] emacs: make 'git-status' work with separate git dirs

2012-11-22 Thread Enrico Scholz
when trying 'M-x git-status' in a submodule created with recent (1.7.5+)
git, the command fails with

| ... is not a git working tree

This is caused by creating submodules with '--separate-git-dir' but
still checking for a working tree by testing for a '.git' directory.

The patch fixes this by relaxing the existing detection a little bit.

Signed-off-by: Enrico Scholz 
---
 contrib/emacs/git.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 65c95d9..5ffc506 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1671,7 +1671,7 @@ Commands:
   "Entry point into git-status mode."
   (interactive "DSelect directory: ")
   (setq dir (git-get-top-dir dir))
-  (if (file-directory-p (concat (file-name-as-directory dir) ".git"))
+  (if (file-exists-p (concat (file-name-as-directory dir) ".git"))
   (let ((buffer (or (and git-reuse-status-buffer (git-find-status-buffer 
dir))
 (create-file-buffer (expand-file-name "*git-status*" 
dir)
 (switch-to-buffer buffer)
-- 
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html