[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 189df82 2/3: Handle patch terminators produced by g
From: |
Dima Kogan |
Subject: |
[Emacs-diffs] master 189df82 2/3: Handle patch terminators produced by git and bzr patch export |
Date: |
Tue, 31 Jan 2017 15:53:28 +0000 (UTC) |
branch: master
commit 189df8262e54c486658784801da3e90b29a548df
Author: Dima Kogan <address@hidden>
Commit: Dima Kogan <address@hidden>
Handle patch terminators produced by git and bzr patch export
Patch by Juri Linkov posted in the #9597 bug report
* lisp/vc/diff-mode.el (diff-sanity-check-hunk): Find and ignore
terminator (Bug #9597, #5302)
---
lisp/vc/diff-mode.el | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index e609ca9..7ffa115 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -437,6 +437,9 @@ See
http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01990.html")
(defconst diff-hunk-header-re
(concat "^\\(?:" diff-hunk-header-re-unified ".*\\|\\*\\{15\\}.*\n\\*\\*\\*
.+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$"))
(defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+ \\|\\*\\*\\*
.+\n--- \\|[^-+!<>address@hidden \n]\\).+\n" (substring diff-hunk-header-re 1)))
+
+(defconst diff-separator-re "^--+ ?$")
+
(defvar diff-narrowed-to nil)
(defun diff-hunk-style (&optional style)
@@ -1537,15 +1540,20 @@ Only works for unified diffs."
(pcase (char-after)
(?\s (cl-decf before) (cl-decf after) t)
(?-
- (if (and (looking-at diff-file-header-re)
- (zerop before) (zerop after))
- ;; No need to query: this is a case where two patches
- ;; are concatenated and only counting the lines will
- ;; give the right result. Let's just add an empty
- ;; line so that our code which doesn't count lines
- ;; will not get confused.
- (progn (save-excursion (insert "\n")) nil)
- (cl-decf before) t))
+ (cond
+ ((and (looking-at diff-separator-re)
+ (zerop before) (zerop after))
+ nil)
+ ((and (looking-at diff-file-header-re)
+ (zerop before) (zerop after))
+ ;; No need to query: this is a case where two patches
+ ;; are concatenated and only counting the lines will
+ ;; give the right result. Let's just add an empty
+ ;; line so that our code which doesn't count lines
+ ;; will not get confused.
+ (save-excursion (insert "\n")) nil)
+ (t
+ (cl-decf before) t)))
(?+ (cl-decf after) t)
(_
(cond