unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Dave Abrahams <dave@boostpro.com>
Cc: 9597@debbugs.gnu.org
Subject: bug#9597: 23.3; [diff-mode] Can't quite cope with git patches
Date: Sun, 25 Sep 2011 16:29:02 +0300	[thread overview]
Message-ID: <87mxdsde9l.fsf@mail.jurta.org> (raw)
In-Reply-To: <m21uv5pekj.fsf@pluto.luannocracy.com> (Dave Abrahams's message of "Sat, 24 Sep 2011 15:41:51 -0400")

> 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







  reply	other threads:[~2011-09-25 13:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-24 19:41 bug#9597: 23.3; [diff-mode] Can't quite cope with git patches Dave Abrahams
2011-09-25 13:29 ` Juri Linkov [this message]
2011-09-26  2:08   ` Stefan Monnier
2011-09-27  0:03     ` Juri Linkov
2016-12-25 23:40 ` bug#9597: update Dima Kogan
2016-12-27 21:16   ` Juri Linkov
2016-12-27 23:56     ` Dima Kogan
2017-01-25 22:16       ` Dima Kogan
2017-01-27  9:53         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mxdsde9l.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=9597@debbugs.gnu.org \
    --cc=dave@boostpro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).