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

    fix: `vc-jj-diff' edge case when REV1 is REV2
    
    When calling `log-view-modify-change-comment', the diff associated
    with that edit appears empty.
    
    This is because Log View passes to `vc-jj-diff' the same revision for
    its REV1 and REV2 arguments. As a result, "jj diff -f REV1 -t REV2" is
    called.  There is a special case when REV1 is REV2: "jj diff" will
    always return an empty commit.
    
    Avoid this by calling "jj diff -r REV1" when REV1 equals REV2.
---
 NEWS.org |  3 ++-
 vc-jj.el | 12 ++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 3f1da8ea3e..6782346486 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -19,8 +19,9 @@
 
 - Fixed =vc-jj-diff= not transforming filenames into jj fileset syntax. This 
means commands like =vc-diff= and =log-view-diff= do not fail.
 - Fixed a bug related to vc-jj's integration with project.el in cases where a 
.git repo is within a subdirectory of a .jj repo.  Previously, when inside the 
.git repo, project.el would erroneously detect the .jj repo to be current one 
(instead of the .git repo, which is closer).  Now, project.el correctly detects 
the closer .git repo.
-+ ~vc-jj-bookmark-delete~ properly recognize the names of local bookmarks that 
are pushable to a remote.
++ =vc-jj-bookmark-delete= now properly recognizes the names of local bookmarks 
that are pushable to a remote.
 - Prevent the possibility of operating on the wrong revisions when in stale JJ 
Log View buffers (Log View buffers that are not up-to-date with the repository).
+- Show the correct diff in log-edit buffers created by 
=log-view-modify-change-comment=.
 
 ** [[https://codeberg.org/emacs-jj-vc/vc-jj.el/compare/v0.3...v0.4][0.4]] - 
2025-09-03
 
diff --git a/vc-jj.el b/vc-jj.el
index 19844dc949..41469da744 100644
--- a/vc-jj.el
+++ b/vc-jj.el
@@ -896,10 +896,18 @@ delete."
     (setq rev1 "root()")))
   (setq rev2 (or rev2 "@"))
   (let ((inhibit-read-only t)
-        (args (append (vc-switches 'jj 'diff) (list "--") files)))
+        ;; When REV1 and REV2 are the same revision, "-f REV1 -t REV2"
+        ;; (erroneously) returns an empty diff.  So we check for that
+        ;; case and use "-r REV1" instead, which returns the correct
+        ;; diff
+        (args (append (if (string= rev1 rev2)
+                          (list "-r" rev1)
+                        (list "-f" rev1 "-t" rev2))
+                      (vc-switches 'jj 'diff)
+                      (list "--") files)))
     (with-current-buffer buffer
       (erase-buffer))
-    (apply #'call-process vc-jj-program nil buffer nil "diff" "--from" rev1 
"--to" rev2 args)
+    (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

Reply via email to