branch: externals/diff-hl
commit b2a57ac4fe7ab43d277d852a4f02122c81995eed
Merge: f25d715d47 2170ec1fc9
Author: Dmitry Gutov <[email protected]>
Commit: GitHub <[email protected]>

    Merge pull request #253 from dgutov/jj-with-resolve-revision
    
    Improve interaction with Jj and change fn to diff-hl-resolved-revision
---
 diff-hl.el           | 64 ++++++++++++++++++++++++----------------------------
 test/diff-hl-test.el | 26 ++++++++++-----------
 2 files changed, 42 insertions(+), 48 deletions(-)

diff --git a/diff-hl.el b/diff-hl.el
index 69ee63437a..097f0db835 100644
--- a/diff-hl.el
+++ b/diff-hl.el
@@ -499,7 +499,8 @@ It can be a relative expression as well, such as \"HEAD^\" 
with Git, or
          ((eq state 'removed)
           `((:working . ,`((1 0 ,(line-number-at-pos (point-max)) 
delete))))))))))
 
-(defvar diff-hl-head-revision-alist '((Git . "HEAD") (Bzr . "last:1") (Hg . 
".")))
+(defvar diff-hl-head-revision-alist '((Git . "HEAD") (Bzr . "last:1") (Hg . 
".")
+                                      (JJ . "@-")))
 
 (defun diff-hl-head-revision (backend)
   (or (assoc-default backend diff-hl-head-revision-alist)
@@ -1467,8 +1468,11 @@ CONTEXT-LINES is the size of the unified diff context, 
defaults to 0."
                  (diff-hl-git-index-object-name file))
               (diff-hl-create-revision
                file
-               (or (diff-hl-resolved-reference-revision backend)
-                   (diff-hl-working-revision file backend)))))
+               (or (diff-hl-resolved-revision
+                    backend
+                    (or diff-hl-reference-revision
+                        (assoc-default backend diff-hl-head-revision-alist)))
+                   (diff-hl-working-revision buffer-file-name backend)))))
            (switches (format "-U %d --strip-trailing-cr" (or context-lines 
0))))
       (diff-no-select rev (current-buffer) switches (not 
(diff-hl--use-async-p))
                       (get-buffer-create dest-buffer))
@@ -1476,42 +1480,32 @@ CONTEXT-LINES is the size of the unified diff context, 
defaults to 0."
       ;; In all commands which use exact text we call it synchronously.
       (get-buffer-create dest-buffer))))
 
-(defun diff-hl-resolved-reference-revision (backend)
+(declare-function vc-jj--process-lines "vc-jj")
+
+(defun diff-hl-resolved-revision (backend revision)
   (cond
-   ((null diff-hl-reference-revision)
-    nil)
    ((eq backend 'Git)
-    (vc-git--rev-parse diff-hl-reference-revision))
+    (vc-git--rev-parse revision))
    ((eq backend 'Hg)
-    ;;  Preserve the potentially buffer-local variables (e.g.,
-    ;;  `diff-hl-reference-revision`, `vc-hg-program`) by not switching buffer
-    ;;  until the vc-hg-command is done.
-    (let ((temp-buffer (generate-new-buffer " *temp*")))
-      (unwind-protect
-          (progn
-            (vc-hg-command temp-buffer 0 nil
-                           "identify" "-r" diff-hl-reference-revision "-i")
-            (with-current-buffer temp-buffer
-              (goto-char (point-min))
-              (buffer-substring-no-properties (point) (line-end-position))))
-        (kill-buffer temp-buffer))))
+    (with-temp-buffer
+      (vc-hg-command (current-buffer) 0 nil
+                     "identify" "-r" revision "-i")
+      (goto-char (point-min))
+      (buffer-substring-no-properties (point) (line-end-position))))
    ((eq backend 'Bzr)
-    ;;  Preserve the potentially buffer-local variables (e.g.,
-    ;;  `diff-hl-reference-revision`, `vc-bzr-program`) by not switching buffer
-    ;;  until the vc-bzr-command is done.
-    (let ((temp-buffer (generate-new-buffer " *temp*")))
-      (unwind-protect
-          (progn
-            (vc-bzr-command temp-buffer 0 nil
-                            "log" "--log-format=template"
-                            "--template-str='{revno}'"
-                            "-r" diff-hl-reference-revision)
-            (with-current-buffer temp-buffer
-              (goto-char (point-min))
-              (buffer-substring-no-properties (point) (line-end-position))))
-        (kill-buffer temp-buffer))))
-    (t
-     diff-hl-reference-revision)))
+    (with-temp-buffer
+      (vc-bzr-command (current-buffer) 0 nil
+                      "log" "--log-format=template"
+                      "--template-str='{revno}'"
+                      "-r" revision)
+      (goto-char (point-min))
+      (buffer-substring-no-properties (point) (line-end-position))))
+   ((eq backend 'JJ)
+    (car (last (vc-jj--process-lines "log" "--no-graph"
+                                     "-r" revision
+                                     "-T" "change_id" "-n" "1"))))
+   (t
+    revision)))
 
 ;; TODO: Cache based on .git/index's mtime, maybe.
 (defun diff-hl-git-index-object-name (file)
diff --git a/test/diff-hl-test.el b/test/diff-hl-test.el
index dbda7ee450..a143fbe16f 100644
--- a/test/diff-hl-test.el
+++ b/test/diff-hl-test.el
@@ -221,20 +221,20 @@
 Diff finished."
                  (buffer-substring (point) (point-max))))))))
 
-(diff-hl-deftest diff-hl-resolved-reference-revision-buffer-local-hg ()
+(diff-hl-deftest diff-hl-resolved-revision-with-hg ()
   (diff-hl-test-in-source
-   (setq-local diff-hl-reference-revision "test-rev")
-   (setq-local vc-hg-program "chg")
-   (condition-case err
-       (progn
-         (diff-hl-resolved-reference-revision 'Hg)
-         (ert-fail "Expected an error to be signaled but none was."))
-     ;; We don't have a hg repo, but we can use the error message to verify the
-     ;; underlying command.
-     (error
-      (should (string-match-p
-               "chg .*identify -r test-rev -i"
-               (error-message-string err)))))))
+    (setq-local diff-hl-reference-revision "test-rev")
+    (let ((vc-hg-program "chg"))
+      (condition-case err
+          (progn
+            (diff-hl-resolved-revision 'Hg "test-rev")
+            (ert-fail "Expected an error to be signaled but none was."))
+        ;; We don't have a hg repo, but we can use the error message to verify 
the
+        ;; underlying command.
+        (error
+         (should (string-match-p
+                  "chg .*identify -r test-rev -i"
+                  (error-message-string err))))))))
 
 (provide 'diff-hl-test)
 

Reply via email to