1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 02:31:03 -08:00

Make diff--iterate-hunks more resilient

* lisp/vc/diff-mode.el (diff--iterate-hunks): Ignore malformed
hunks instead of signalling errors (bug#53343).
This commit is contained in:
Lars Ingebrigtsen 2022-01-21 12:07:04 +01:00
parent 3ffa13d0aa
commit 502dbd1f7c

View file

@ -2270,23 +2270,27 @@ Return new point, if it was moved."
(defun diff--iterate-hunks (max fun)
"Iterate over all hunks between point and MAX.
Call FUN with two args (BEG and END) for each hunk."
Call FUN with two args (BEG and END) for each hunk.
If INHIBIT-ERROR, ignore malformed hunks."
(save-excursion
(let* ((beg (or (ignore-errors (diff-beginning-of-hunk))
(ignore-errors (diff-hunk-next) (point))
max)))
(while (< beg max)
(goto-char beg)
(cl-assert (looking-at diff-hunk-header-re))
(let ((end
(save-excursion (diff-end-of-hunk) (point))))
(cl-assert (< beg end))
(funcall fun beg end)
(goto-char end)
(setq beg (if (looking-at diff-hunk-header-re)
end
(or (ignore-errors (diff-hunk-next) (point))
max))))))))
(catch 'malformed
(let* ((beg (or (ignore-errors (diff-beginning-of-hunk))
(ignore-errors (diff-hunk-next) (point))
max)))
(while (< beg max)
(goto-char beg)
(unless (looking-at diff-hunk-header-re)
(throw 'malformed nil))
(let ((end
(save-excursion (diff-end-of-hunk) (point))))
(unless (< beg end)
(throw 'malformed nil))
(funcall fun beg end)
(goto-char end)
(setq beg (if (looking-at diff-hunk-header-re)
end
(or (ignore-errors (diff-hunk-next) (point))
max)))))))))
(defun diff--font-lock-refined (max)
"Apply hunk refinement from font-lock."