branch: externals/vc-jj
commit 0eb60c247632e23779bf81d961c3791890e34f53
Author: Kristoffer Balintona <[email protected]>
Commit: Kristoffer Balintona <[email protected]>

    Support editing on remote projects
    
    To support working on remote projects (via tramp), we do the
    following:
    - Replace all instances of `call-process` with `process-file`.  The
      latter leverages Emacs's file handlers (e.g. tramp), meaning jj
      commands are called in the appropriate remote environment as
      necessary.
    - Use `ansi-color-filter-region` to sanitize ANSI escape sequences
      from process output.
    - Ensure remote file paths are passed to our internal functions (e.g.,
      `vc-jj--command-parseable`) while the paths passed to jj invocations
      are local file names (remote part removed).
    
    Fixes #132
---
 NEWS.org      |  1 +
 project-jj.el | 10 ++++++----
 vc-jj.el      | 34 ++++++++++++++++++----------------
 3 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index c3bfb13935..f4bc93cc44 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -26,6 +26,7 @@
   - Fontify bookmark names (~vc-jj-log-view-bookmark~)
 - New user option: ~vc-jj-root-log-format~. ~vc-jj-root-log-format~ controls 
the format and fontification of the Log View buffer created from 
~vc-print-root-log~.
 - Added functionality for ~vc-print-log~ (the "long" revision log format).
+- Support editing project files on a remote host using Tramp.
 
 *** Changed
 
diff --git a/project-jj.el b/project-jj.el
index c113309389..d68f24f758 100644
--- a/project-jj.el
+++ b/project-jj.el
@@ -36,10 +36,12 @@
   ;; Therefore, we wrap the primary method with an :around method and
   ;; selectively override its behavior when the VC backend is JJ.
   (if (eq (cadr project) 'JJ)
-      (let* ((default-directory (expand-file-name (project-root project)))
-             (args (cons "--" (mapcar #'file-relative-name dirs)))
-             (files (apply #'process-lines "jj" "file" "list" args)))
-        (mapcar #'expand-file-name files))
+      (progn
+        (require 'vc-jj)
+        (let* ((default-directory (expand-file-name (project-root project)))
+               (files (vc-jj--process-lines (mapcar #'file-relative-name dirs)
+                                            "file" "list")))
+          (mapcar #'expand-file-name files)))
     (cl-call-next-method)))
 
 ;;;###autoload
diff --git a/vc-jj.el b/vc-jj.el
index 452a3f65bf..41e8888ac2 100644
--- a/vc-jj.el
+++ b/vc-jj.el
@@ -242,7 +242,8 @@ When FILENAME is not inside a JJ repository, throw an 
error."
       (setq-local compilation-arguments
                   (list compile-command nil
                         (lambda (_name-of-mode) buffer)
-                        nil))))
+                        nil))
+      (ansi-color-filter-region (point-min) (point-max))))
   (vc-set-async-update buffer))
 
 (defun vc-jj--process-lines (&rest args)
@@ -250,12 +251,13 @@ When FILENAME is not inside a JJ repository, throw an 
error."
 In contrast to `process-lines', discard output to stderr since jj prints
 warnings to stderr even when run with '--quiet'."
   (with-temp-buffer
-    (let ((status (apply #'call-process vc-jj-program nil
+    (let ((status (apply #'process-file vc-jj-program nil
                          ;; (current-buffer)
                          (list (current-buffer) nil)
                          nil args)))
       (unless (eq status 0)
-        (error "'jj' exited with status %s" status))
+       (error "'jj' exited with status %s" status))
+      (ansi-color-filter-region (point-min) (point-max))
       (goto-char (point-min))
       (let (lines)
         (while (not (eobp))
@@ -277,11 +279,12 @@ the output can be safely parsed.  Does not support many 
of the features
 of `vc-jj--command-dispatched', such as async execution and checking of
 process status."
   (with-temp-buffer
-    (let ((status (apply #'call-process vc-jj-program nil
+    (let ((status (apply #'process-file vc-jj-program nil
                          (list (current-buffer) nil)
                          nil args)))
       (unless (eq status 0)
-        (error "'jj' exited with status %s" status))
+       (error "'jj' exited with status %s" status))
+      (ansi-color-filter-region (point-min) (point-max))
       (buffer-substring-no-properties (point-min) (point-max)))))
 
 (defun vc-jj--command-dispatched (buffer okstatus file-or-list &rest flags)
@@ -410,11 +413,12 @@ For a description of the states relevant to jj, see 
`vc-jj-state'."
     (let* ((dir (expand-file-name dir))
            (default-directory dir)
            (project-root (vc-jj-root dir))
-           (registered-files (vc-jj--process-lines "file" "list" "--" dir))
+           (fileset (vc-jj--filename-to-fileset dir))
+           (registered-files (vc-jj--process-lines "file" "list" "--" fileset))
            (ignored-files (seq-difference (cl-delete-if #'file-directory-p
                                                         (directory-files dir 
nil nil t))
                                           registered-files))
-           (changed (vc-jj--process-lines "diff" "--summary" "--" dir))
+           (changed (vc-jj--process-lines "diff" "--summary" "--" fileset))
            (added-files (mapcan (lambda (entry)
                                   (and (string-prefix-p "A " entry)
                                        (list (substring entry 2))))
@@ -433,7 +437,8 @@ For a description of the states relevant to jj, see 
`vc-jj-state'."
            (conflicted-files (mapcar (lambda (entry)
                                        (file-relative-name (expand-file-name 
entry project-root) dir))
                                      (vc-jj--process-lines "file" "list"
-                                                           "-T" "if(conflict, 
path ++ \"\\n\")" "--" dir)))
+                                                           "-T" "if(conflict, 
path ++ \"\\n\")"
+                                                           "--" fileset)))
            (up-to-date-files (cl-remove-if (lambda (entry) (or (member entry 
conflicted-files)
                                                               (member entry 
edited-files)
                                                               (member entry 
added-files)
@@ -582,8 +587,8 @@ parents.map(|c| concat(
 (defun vc-jj-create-repo ()
   "Create an empty jj repository in the current directory."
   (if current-prefix-arg
-      (call-process vc-jj-program nil nil nil "git" "init" "--colocate")
-    (call-process vc-jj-program nil nil nil "git" "init")))
+      (process-file vc-jj-program nil nil nil "git" "init" "--colocate")
+    (process-file vc-jj-program nil nil nil "git" "init")))
 
 ;;;; register
 
@@ -1064,12 +1069,9 @@ unsupported."
                       (vc-switches 'jj 'diff)
                       (list "--") files)))
     (with-current-buffer buffer
-      (erase-buffer))
-    (apply #'call-process vc-jj-program nil buffer nil "diff" args)
-    (if (seq-some (lambda (line) (string-prefix-p "M " line))
-                  (apply #'vc-jj--process-lines "diff" "--summary" "--" files))
-        1
-      0)))
+      (prog1
+          (apply #'vc-jj--command-dispatched buffer 0 nil "diff" args)
+        (ansi-color-filter-region (point-min) (point-max))))))
 
 ;;;; revision-completion-table
 

Reply via email to