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

    fix: Integration with project.el
    
    Fixes #117.
    
    Co-authored-by: @gessen (Codeberg)
---
 project-jj.el | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/project-jj.el b/project-jj.el
index d9514798e1..2b9f4212f1 100644
--- a/project-jj.el
+++ b/project-jj.el
@@ -25,24 +25,30 @@
 
 (require 'project)
 
-(cl-defmethod project-root ((project (head jj)))
-  "Return the root directory of PROJECT."
-  (cdr project))
-
-(cl-defmethod project-files ((project (head jj)) &optional dirs)
+;;;###autoload
+(cl-defmethod project-files :around ((project (head vc)) &optional dirs)
   "Return a list of files in directories DIRS in PROJECT."
-  ;; There is a bit of filename frobbing going on in this method.  The
-  ;; reason is that while jj reads and writes relative filenames, we
-  ;; get passed absolute filenames in DIRS and must return absolute
-  ;; (tilde-expanded) filenames.
-  (let* ((default-directory (expand-file-name (project-root project)))
-         (args (cons "--" (mapcar #'file-relative-name dirs)))
-         (absolutify (or (not project-files-relative-names)
-                         (> (length dirs) 1)))
-         (files (apply #'process-lines "jj" "file" "list" args)))
-    (if absolutify
-        (mapcar #'expand-file-name files)
-      files)))
+  ;; Intercept the primary/default `project-files' method.  Vc-jj does
+  ;; not register itself as a new project backend: it hooks into the
+  ;; existing VC integration into project.el (see `project-try-vc' in
+  ;; `project-find-functions').  Because of that, we cannot provide a
+  ;; standalone `project-files' method for a distinct backend class.
+  ;; 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)
+      ;; There is a bit of filename frobbing going on in this method.
+      ;; The reason is that while jj reads and writes relative
+      ;; filenames, we get passed absolute filenames in DIRS and must
+      ;; return absolute (tilde-expanded) filenames.
+      (let* ((default-directory (expand-file-name (project-root project)))
+             (args (cons "--" (mapcar #'file-relative-name dirs)))
+             (absolutify (or (not project-files-relative-names)
+                             (> (length dirs) 1)))
+             (files (apply #'process-lines "jj" "file" "list" args)))
+        (if absolutify
+            (mapcar #'expand-file-name files)
+          files))
+    (cl-call-next-method)))
 
 ;;;###autoload
 (with-eval-after-load 'project

Reply via email to