GNU bug report logs - #20276
24.4; diff-mode doesn't handle unified diff file headers without tabs

Previous Next

Package: emacs;

Reported by: Gustav Hållberg <gustav <at> gmail.com>

Date: Tue, 7 Apr 2015 22:35:01 UTC

Severity: normal

Found in version 24.4

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 20276 in the body.
You can then email your comments to 20276 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#20276; Package emacs. (Tue, 07 Apr 2015 22:35:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Gustav Hållberg <gustav <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 07 Apr 2015 22:35:02 GMT) Full text and rfc822 format available.

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

From: Gustav Hållberg <gustav <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4; diff-mode doesn't handle unified diff file headers without tabs
Date: Wed, 8 Apr 2015 00:34:23 +0200
[Message part 1 (text/plain, inline)]
In diff-mode, "o" doesn't recognize unified diff file headers if they do
not contain tabs. Some diff programs will not emit tab + timestamp (as
GNU diff does), but just the file name.

Example working file header (where ".txt" is followed by tabs):

--- a.txt 2015-04-08 00:09:46.000000000 +0200
+++ b.txt 2015-04-08 00:09:51.000000000 +0200

Example failing file header:

--- a.txt
+++ b.txt

The fallback is for "o" to open the file on the leading "diff" line
which may or may not be present.

This used to work in Emacs 24.3.1 but does not as of the patch mentioned
here:
http://stackoverflow.com/questions/14720205/how-do-i-use-emacs-diff-with-spaces

My proposal is to fix this in (diff-hunk-file-names) by removing the
requirement for the trailing tab on the leading diff file header and
replace it with a no-newline check (sorry for not providing proper
patch):

-          (if (looking-at "[-*][-*][-*] \\([^\t]+\\)\t.*\n[-+][-+][-+]
\\([^\t]+\\)")
+          (if (looking-at "[-*][-*][-*] \\([^\t\n]+\\).*\n[-+][-+][-+]
\\([^\t\n]+\\)")

The return values should probably use (match-string-no-properties)
rather than (match-string) as well.

Thanks,
 Gustav
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20276; Package emacs. (Wed, 08 Apr 2015 20:51:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Gustav Hållberg <gustav <at> gmail.com>
Cc: 20276 <at> debbugs.gnu.org
Subject: Re: bug#20276: 24.4;
 diff-mode doesn't handle unified diff file headers without tabs
Date: Wed, 08 Apr 2015 16:50:06 -0400
> Some diff programs will not emit tab + timestamp (as GNU diff does),
> but just the file name.

Which diff programs do that?

> -          (if (looking-at "[-*][-*][-*] \\([^\t]+\\)\t.*\n[-+][-+][-+]
> \\([^\t]+\\)")
> +          (if (looking-at "[-*][-*][-*] \\([^\t\n]+\\).*\n[-+][-+][-+]
> \\([^\t\n]+\\)")

Adding \n in the char-ranges is fine (it's a good change in itself), but
removing the \t increases the risk of false positives, so I'm a bit
worried about that.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20276; Package emacs. (Wed, 08 Apr 2015 22:40:02 GMT) Full text and rfc822 format available.

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

From: Gustav Hållberg <gustav <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 20276 <at> debbugs.gnu.org
Subject: Re: bug#20276: 24.4; diff-mode doesn't handle unified diff file
 headers without tabs
Date: Thu, 9 Apr 2015 00:38:55 +0200
[Message part 1 (text/plain, inline)]
On Wed, Apr 8, 2015 at 10:50 PM, Stefan Monnier <monnier <at> iro.umontreal.ca>
wrote:

> > Some diff programs will not emit tab + timestamp (as GNU diff does),
> > but just the file name.
>
> Which diff programs do that?
>

diff -u with -L does for example:

  $ diff -u -Lfoo a.txt -Lbar b.txt
  --- foo
  +++ bar
    :

git diff also does for what it's worth.


>
> > -          (if (looking-at "[-*][-*][-*] \\([^\t]+\\)\t.*\n[-+][-+][-+]
> > \\([^\t]+\\)")
> > +          (if (looking-at "[-*][-*][-*] \\([^\t\n]+\\).*\n[-+][-+][-+]
> > \\([^\t\n]+\\)")
>
> Adding \n in the char-ranges is fine (it's a good change in itself), but
> removing the \t increases the risk of false positives, so I'm a bit
> worried about that.
>

True, but note that diff-font-lock-keywords is more permissive; it does not
require the tab to be present.

- Gustav



>
>
>         Stefan
>
[Message part 2 (text/html, inline)]

Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Thu, 09 Apr 2015 01:49:02 GMT) Full text and rfc822 format available.

Notification sent to Gustav Hållberg <gustav <at> gmail.com>:
bug acknowledged by developer. (Thu, 09 Apr 2015 01:49:02 GMT) Full text and rfc822 format available.

Message #16 received at 20276-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Gustav Hållberg <gustav <at> gmail.com>
Cc: 20276-done <at> debbugs.gnu.org
Subject: Re: bug#20276: 24.4;
 diff-mode doesn't handle unified diff file headers without tabs
Date: Wed, 08 Apr 2015 21:48:49 -0400
> git diff also does for what it's worth.

Ah, indeed.  This doesn't bite us too hard because git also happens to
provide the "diff ..." line.

> True, but note that diff-font-lock-keywords is more permissive; it does not
> require the tab to be present.

Of course a false positive in diff-font-lock-keywords will only look
funny but won't affect actual behavior, which is why I thought it was OK
to be more permissive.

Anyway, I guess we have to bite this bullet, so I installed your patch
into "master".  Thanks,


        Stefan




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 07 May 2015 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 98 days ago.

Previous Next


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