branch: elpa/magit
commit db5aa451ce1b5001ffa7887688e95f74ae576c84
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    magit-diff-visit--offset: Support comparing blobs directly
---
 lisp/magit-diff.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 5e8d32a8f3..a4cf9871ea 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1817,7 +1817,7 @@ the Magit-Status buffer for DIRECTORY."
     (with-current-buffer buffer
       (when (and goto-file (not (equal rev "{worktree}")))
         (setq line (apply #'magit-diff-visit--offset line file
-                          (and (equal rev "{index}") (list rev)))))
+                          (and (not (equal rev "{index}")) (list rev)))))
       (save-restriction
         (widen)
         (goto-char (point-min))
@@ -1860,7 +1860,10 @@ the Magit-Status buffer for DIRECTORY."
     (with-temp-buffer
       (save-excursion
         (magit-with-toplevel
-          (magit-git-insert "diff" rev "--" file)))
+          (cond ((stringp file)
+                 (magit-git-insert "diff" args "--" file))
+                ((magit-git-version< "2.50"))
+                ((apply #'magit--diff-pair (current-buffer) file)))))
       (catch 'found
         (while (re-search-forward
                 "^@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([0-9]+\\),\\([0-9]+\\) 
@@.*\n"
@@ -1881,6 +1884,13 @@ the Magit-Status buffer for DIRECTORY."
               (throw 'found nil))))))
     (+ line offset)))
 
+(defun magit--diff-pair (buffer a b &optional file)
+  (with-temp-buffer
+    (insert (format ":100644 100644 %s %s M\0%s\0" a b (or file "blob")))
+    (call-process-region (point-min) (point-max)
+                         (magit-git-executable) nil buffer nil
+                         "diff-pairs" "-z")))
+
 ;;;; Scroll Commands
 
 (defun magit-diff-show-or-scroll-up ()

Reply via email to