[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 502dbd1f7c 1/2: Make diff--iterate-hunks more resilient
From: |
Lars Ingebrigtsen |
Subject: |
master 502dbd1f7c 1/2: Make diff--iterate-hunks more resilient |
Date: |
Fri, 21 Jan 2022 06:08:15 -0500 (EST) |
branch: master
commit 502dbd1f7c0295c1f01643778d2a6aea17a9808c
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Make diff--iterate-hunks more resilient
* lisp/vc/diff-mode.el (diff--iterate-hunks): Ignore malformed
hunks instead of signalling errors (bug#53343).
---
lisp/vc/diff-mode.el | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 37eaf254fd..ae2f545966 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."