emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit 71f7d1df1d: magit-diff-wash-hunk: Handle one li


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit 71f7d1df1d: magit-diff-wash-hunk: Handle one line edge case
Date: Thu, 12 May 2022 00:58:17 -0400 (EDT)

branch: elpa/git-commit
commit 71f7d1df1d715a866269f33ed5c3836ed0839571
Author: Kyle Meyer <kyle@kyleam.com>
Commit: Kyle Meyer <kyle@kyleam.com>

    magit-diff-wash-hunk: Handle one line edge case
    
    Calling magit-show-commit on a blame chunk for a diff that has one
    line in the post-image blob fails with a type error because
    magit-diff--locate-hunk expects the diff range's length (N in "+M,N")
    to be a number.  For a single line blob, this diff header codes this
    as "+1", leading to magit-diff-wash-hunk setting to-range to (1).
    
    Make magit-diff-wash-hunk catch this case and insert 1 for the length
    so that downstream consumers like magit-diff--locate-hunk don't need
    to worry about this edge case.
---
 lisp/magit-diff.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 4ce51cbebb..d59f9d6eb4 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -2428,10 +2428,16 @@ section or a child thereof."
 (defun magit-diff-wash-hunk ()
   (when (looking-at "^@\\{2,\\} \\(.+?\\) @\\{2,\\}\\(?: \\(.*\\)\\)?")
     (let* ((heading  (match-string 0))
-           (ranges   (mapcar (lambda (str)
+           (ranges   (mapcar
+                      (lambda (str)
+                        (let ((range
                                (mapcar #'string-to-number
-                                       (split-string (substring str 1) ",")))
-                             (split-string (match-string 1))))
+                                       (split-string (substring str 1) ","))))
+                          ;; A single line is +1 rather than +1,1.
+                          (if (length= range 1)
+                              (nconc range (list 1))
+                            range)))
+                      (split-string (match-string 1))))
            (about    (match-string 2))
            (combined (length= ranges 3))
            (value    (cons about ranges)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]