GNU bug report logs - #9597
23.3; [diff-mode] Can't quite cope with git patches

Previous Next

Package: emacs;

Reported by: Dave Abrahams <dave <at> boostpro.com>

Date: Sun, 25 Sep 2011 02:01:01 UTC

Severity: normal

Found in version 23.3

Done: Dima Kogan <dima <at> secretsauce.net>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 9597 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Dave Abrahams <dave <at> boostpro.com>
Cc: 9597 <at> debbugs.gnu.org
Subject: Re: bug#9597: 23.3; [diff-mode] Can't quite cope with git patches
Date: Sun, 25 Sep 2011 16:29:02 +0300
> When I try to apply the last diff in the enclosed file, I get the
> following backtrace:
>
> Debugger entered--Lisp error: (error "End of hunk ambiguously marked")
>   signal(error ("End of hunk ambiguously marked"))
>   error("End of hunk ambiguously marked")
>   diff-sanity-check-hunk()
>   diff-find-source-location(nil nil)
>   diff-apply-hunk(nil)
>   call-interactively(diff-apply-hunk nil nil)
>
> Seems to me that diff-mode should be able to handle the output of
> git-format-patch; after all, the patch command can.

bug#5302 reports the same problem with Bzr diffs.

In both cases diff separators (a line of dashes)
are ignored by `diff-sanity-check-hunk'.

Both bugs can be fixed with the patch below.

I suppose that modifying the buffer with inserting a newline
is a temporary workaround for some earlier bug, so I added
a check for the diff separator in another condition branch.
The comment says that adding an empty line is for code which
doesn't count lines.  I don't know where this code is located,
but perhaps this code should also check for diff separators?

=== modified file 'lisp/vc/diff-mode.el'
--- lisp/vc/diff-mode.el	2011-05-22 19:22:37 +0000
+++ lisp/vc/diff-mode.el	2011-09-25 13:28:50 +0000
@@ -429,6 +429,9 @@ (defvar diff-valid-unified-empty-line t
 (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--- \\|[^-+!<>0-9@* \n]\\).+\n" (substring diff-hunk-header-re 1)))
+
+(defconst diff-separator-re "^--+ ?$")
+
 (defvar diff-narrowed-to nil)
 
 (defun diff-hunk-style (&optional style)
@@ -1414,15 +1417,20 @@ (defun diff-sanity-check-hunk ()
                 (case (char-after)
                   (?\s (decf before) (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)
-                     (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
+                     (decf before) t)))
                   (?+ (decf after) t)
                   (t
                    (cond






This bug report was last modified 8 years and 113 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.