From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#9597: 23.3; [diff-mode] Can't quite cope with git patches Date: Sun, 25 Sep 2011 16:29:02 +0300 Organization: JURTA Message-ID: <87mxdsde9l.fsf@mail.jurta.org> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1316957793 20133 80.91.229.12 (25 Sep 2011 13:36:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 25 Sep 2011 13:36:33 +0000 (UTC) Cc: 9597@debbugs.gnu.org To: Dave Abrahams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 25 15:36:29 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R7ose-00080N-GK for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Sep 2011 15:36:28 +0200 Original-Received: from localhost ([::1]:55745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R7ose-0003ke-1h for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Sep 2011 09:36:28 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:53319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R7osc-0003k9-4G for bug-gnu-emacs@gnu.org; Sun, 25 Sep 2011 09:36:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R7osa-0005iE-PN for bug-gnu-emacs@gnu.org; Sun, 25 Sep 2011 09:36:26 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56158) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R7osa-0005iA-MQ for bug-gnu-emacs@gnu.org; Sun, 25 Sep 2011 09:36:24 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1R7otC-0002SI-0R for bug-gnu-emacs@gnu.org; Sun, 25 Sep 2011 09:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 Sep 2011 13:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9597 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 9597-submit@debbugs.gnu.org id=B9597.13169577869393 (code B ref 9597); Sun, 25 Sep 2011 13:37:01 +0000 Original-Received: (at 9597) by debbugs.gnu.org; 25 Sep 2011 13:36:26 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1R7osb-0002RS-HI for submit@debbugs.gnu.org; Sun, 25 Sep 2011 09:36:25 -0400 Original-Received: from smarty.dreamhost.com ([208.113.175.8]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1R7osY-0002RJ-Vs for 9597@debbugs.gnu.org; Sun, 25 Sep 2011 09:36:24 -0400 Original-Received: from ps18281.dreamhostps.com (ps18281.dreamhost.com [69.163.218.105]) by smarty.dreamhost.com (Postfix) with ESMTP id B90E86E805F; Sun, 25 Sep 2011 06:35:43 -0700 (PDT) Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 63A74451C330; Sun, 25 Sep 2011 06:35:41 -0700 (PDT) In-Reply-To: (Dave Abrahams's message of "Sat, 24 Sep 2011 15:41:51 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sun, 25 Sep 2011 09:37:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:51817 Archived-At: > 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