summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-01-21 12:07:04 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2022-01-21 12:07:04 +0100
commit502dbd1f7c0295c1f01643778d2a6aea17a9808c (patch)
treecf24f3724020f3d02643b12ac7856faee4b0cef4
parent3ffa13d0aa00f463e134c568c2d52fb03637a108 (diff)
downloademacs-502dbd1f7c0295c1f01643778d2a6aea17a9808c.tar.gz
Make diff--iterate-hunks more resilient
* lisp/vc/diff-mode.el (diff--iterate-hunks): Ignore malformed hunks instead of signalling errors (bug#53343).
-rw-r--r--lisp/vc/diff-mode.el36
1 files changed, 20 insertions, 16 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 37eaf254fdb..ae2f545966e 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -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."