From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#17522: diff-mode frustrates attempt to correct corrupted diff file. Date: Sun, 25 May 2014 16:07:55 +0000 Message-ID: <20140525160755.GA2777@acm.acm> References: <20140518105055.GA3727@acm.acm> <20140521215636.GA3908@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1401034452 21640 80.91.229.3 (25 May 2014 16:14:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 25 May 2014 16:14:12 +0000 (UTC) Cc: 17522@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun May 25 18:14:04 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Wob3j-000537-O9 for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 May 2014 18:14:03 +0200 Original-Received: from localhost ([::1]:52021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wob3j-0003Rk-24 for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 May 2014 12:14:03 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wob2s-0002Vl-Ui for bug-gnu-emacs@gnu.org; Sun, 25 May 2014 12:13:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wob2k-0002SU-MB for bug-gnu-emacs@gnu.org; Sun, 25 May 2014 12:13:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:60945) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wob2k-0002SJ-IZ for bug-gnu-emacs@gnu.org; Sun, 25 May 2014 12:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Wob2j-0004wX-V3 for bug-gnu-emacs@gnu.org; Sun, 25 May 2014 12:13:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 May 2014 16:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17522 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 17522-submit@debbugs.gnu.org id=B17522.140103433618920 (code B ref 17522); Sun, 25 May 2014 16:13:01 +0000 Original-Received: (at 17522) by debbugs.gnu.org; 25 May 2014 16:12:16 +0000 Original-Received: from localhost ([127.0.0.1]:59822 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wob1z-0004v5-Ux for submit@debbugs.gnu.org; Sun, 25 May 2014 12:12:16 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:27571 helo=mail.muc.de) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wob1w-0004uv-Dr for 17522@debbugs.gnu.org; Sun, 25 May 2014 12:12:13 -0400 Original-Received: (qmail 90452 invoked by uid 3782); 25 May 2014 16:12:10 -0000 Original-Received: from acm.muc.de (pD95189FA.dip0.t-ipconnect.de [217.81.137.250]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 25 May 2014 18:12:09 +0200 Original-Received: (qmail 3216 invoked by uid 1000); 25 May 2014 16:07:55 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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:89481 Archived-At: Hello, Stefan. On Wed, May 21, 2014 at 09:32:11PM -0400, Stefan Monnier wrote: > >> Maybe not a bug, but a misfeature: the ",0" is probably because the first > >> line after the @...@ is empty, which normally "can't" be part of a hunk, > >> so this empty line is taken as an "end of hunk". > > OK. But patch appears to accept a blank line (in a unified diff) > > without complaint. > Indeed, "patch" at some point was changed so as to accept empty lines. > diff-mode.el was partly changed to accommodate that looser format, but > not 100% (and in the case of updating line counts while editing the > patch, it's a bit more delicate since, contrary to "patch" we can't > rely on the line counts to decide whether an empty line marks the end of > a hunk or not). Why not? If you're going to carry on making surreptitious changes to hunk headers, you'll need to determine the start and end of hunks reliably, especially corrupted hunks. This can't be done with 100% certainty, and is going to involve heuristics. A good way might be to scan a hunk _forwards_ counting lines before the first change to that hunk. We know that, in broken unified patches, empty lines are liable to have their single space removed, and long lines are liable to be split. > >> If you add a space on that line, the count should be updated again and > >> start looking more sane. > > This is all besides the point. I did not edit the hunk header, > > therefore I don't expect it to be changed behind my back. If I need > > the header to be recalculated, surely there should be a command > > for that. > diff-mode tries to be fancier and do that transparently. You're just > bumping into a bug of that code (regardless of how the empty-line is > handled, a line count of 0 for both sides of the hunk is clearly not > right). [ .... ] > BTW, I remember writing some kind of "fix corrupted hunk" code. > Oh, yes, it's in diff-sanity-check-hunk. Can you try to see if it can > auto-fix your corrupted patch? The code for diff-sanity-check-hunk is unfinished. It asks "Try to auto-fix word wrap damage?", but does nothing when you say yes. It also doesn't check the line counts, at least, not for unified diffs. > M-x diff-goto-source RET is probably the easiest way to trigger it > (sadly, it's not provided as a separate command). > Stefan -- Alan Mackenzie (Nuremberg, Germany).