unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
@ 2007-09-08 13:49 Chris Moore
  2007-09-10  1:13 ` Richard Stallman
  0 siblings, 1 reply; 11+ messages in thread
From: Chris Moore @ 2007-09-08 13:49 UTC (permalink / raw)
  To: emacs-pretest-bug


[-- Attachment #1.1: Type: text/plain, Size: 3811 bytes --]

The diff-goto-source function doesn't work on context diff or unified diff
hunks when the context is set to 0 lines and when the hunk is only changing
a single line.

Example hunks which it fails on are this, generated using (let
((diff-switches "-c0")) (diff "/tmp/1" "/tmp/2")) :

diff -c0 /tmp/1 /tmp/2
*** /tmp/1      Sat Sep  8 15:44:04 2007
--- /tmp/2      Sat Sep  8 15:44:04 2007
***************
*** 4 ****
! one
--- 4 ----
! two

and this, generated using (let ((diff-switches "-u0")) (diff "/tmp/1"
"/tmp/2")) :

diff -u0 /tmp/1 /tmp/2
--- /tmp/1      2007-09-08 15:44:04.000000000 +0200
+++ /tmp/2      2007-09-08 15:44:04.000000000 +0200
@@ -4 +4 @@
-one
+two

I've fixed this bug.  The fix is to make parts of the regexps optional, and
to code what to do in the event that they're missing.

The patch is here: http://dooglus.rincevent.net/random/emacs-diff-patch.txt

I'll paste it here as well, in case you're reading this off-line.

I've signed papers with the FSF for my contributions to Emacs.

Chris.

-------

*** /home/chris/programs/emacs/lisp/diff-mode.el	Sat Sep  8 15:29:54 2007
--- /tmp/diff-mode.el	Sat Sep  8 15:40:53 2007
***************
*** 1217,1242 ****

         ;; A context diff.
         ((eq (char-after) ?*)
!         (if (not (looking-at "\\*\\{15\\}\\(?: .*\\)?\n\\*\\*\\*
\\([0-9]+\\),\\([0-9]+\\) \\*\\*\\*\\*"))
              (error "Unrecognized context diff first hunk header format")
            (forward-line 2)
            (diff-sanity-check-context-hunk-half
!            (1+ (- (string-to-number (match-string 2))
!                   (string-to-number (match-string 1)))))
!           (if (not (looking-at "--- \\([0-9]+\\),\\([0-9]+\\) ----$"))
                (error "Unrecognized context diff second hunk header format")
              (forward-line)
              (diff-sanity-check-context-hunk-half
!              (1+ (- (string-to-number (match-string 2))
!                     (string-to-number (match-string 1))))))))

         ;; A unified diff.
         ((eq (char-after) ?@)
          (if (not (looking-at
!                   "@@ -[0-9]+,\\([0-9]+\\) \\+[0-9]+,\\([0-9]+\\) @@"))
              (error "Unrecognized unified diff hunk header format")
!           (let ((before (string-to-number (match-string 1)))
!                 (after (string-to-number (match-string 2))))
              (forward-line)
              (while
                  (case (char-after)
--- 1217,1246 ----

         ;; A context diff.
         ((eq (char-after) ?*)
!         (if (not (looking-at "\\*\\{15\\}\\(?: .*\\)?\n\\*\\*\\*
\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? \\*\\*\\*\\*"))
              (error "Unrecognized context diff first hunk header format")
            (forward-line 2)
            (diff-sanity-check-context-hunk-half
! 	   (if (match-string 2)
! 	       (1+ (- (string-to-number (match-string 2))
! 		      (string-to-number (match-string 1))))
! 	     1))
!           (if (not (looking-at "---
\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? ----$"))
                (error "Unrecognized context diff second hunk header format")
              (forward-line)
              (diff-sanity-check-context-hunk-half
! 	     (if (match-string 2)
! 		 (1+ (- (string-to-number (match-string 2))
! 			(string-to-number (match-string 1))))
! 	       1)))))

         ;; A unified diff.
         ((eq (char-after) ?@)
          (if (not (looking-at
!                   "@@ -[0-9]+\\(?:,\\([0-9]+\\)\\)?
\\+[0-9]+\\(?:,\\([0-9]+\\)\\)? @@"))
              (error "Unrecognized unified diff hunk header format")
!           (let ((before (if (match-string 1) (string-to-number
(match-string 1)) 1))
!                 (after (if (match-string 2) (string-to-number
(match-string 2)) 1)))
              (forward-line)
              (while
                  (case (char-after)

-------

[-- Attachment #1.2: Type: text/html, Size: 4366 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-08 13:49 diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes Chris Moore
@ 2007-09-10  1:13 ` Richard Stallman
  2007-09-10 11:20   ` Chris Moore
  0 siblings, 1 reply; 11+ messages in thread
From: Richard Stallman @ 2007-09-10  1:13 UTC (permalink / raw)
  To: Chris Moore; +Cc: emacs-devel

Your patch was mangled by your mailer.  Can you please send it uuencoded?
And can you please provide a change log entry?

It should be installed in Emacs 22.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-10  1:13 ` Richard Stallman
@ 2007-09-10 11:20   ` Chris Moore
  2007-09-10 23:55     ` Richard Stallman
  2007-09-11  7:00     ` Thien-Thi Nguyen
  0 siblings, 2 replies; 11+ messages in thread
From: Chris Moore @ 2007-09-10 11:20 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

On 9/10/07, Richard Stallman <rms@gnu.org> wrote:
> Your patch was mangled by your mailer.  Can you please send it uuencoded?
> And can you please provide a change log entry?
>
> It should be installed in Emacs 22.
>

Sure.

Changelog:

2007-09-10  Chris Moore  <dooglus@gmail.com>

    * diff-mode.el: (diff-sanity-check-hunk): Fix to accept
    single-line hunks.

Patch:

begin 644 diff-mode-patch.txt.gz
M'XL("(`<Y48``V1I9F8M;6]D92UP871C:"YT>'0`U55-<YLP$#WC7[%A>I#`
M\B!2ZH0<3'Y#IZ>2`P%A-,:B%?*D']/_7H%Q;#X<0S/3-AI=M(_5KM[N/BS+
M@H2G*=D6"5NPW'!OX'ZW!M=QED"7OK?TKSVP'7TVZ()2=T8(:7LX-_"1?6D\
M/-]S_.O;QF-FM5=U!NK2Y9RZ[UVH30!Z-^ON#NXA+H1BWU0=9''$$&)?`<59
M)$F4*B8QK"P\NSKB/`4D"@4H+XH-%VL2*3##T`K#G]0+PU]AB%8^+/09KT)1
M`]4&;?_LD-L'6P/STP,\?Z.WB?$QEWU`)F4AP?PD)(N+M>`_6-)*'E(N2P79
M3FP@8U'")*2%W$;*;%^%M/4ID@G)N6#@=L":ZS(27'TG<<;B#6EBD.IBDD5Y
M>L)"Y4%M0`10J63%@BJ(V&T?=7"D0\<9V=MU'-SV.[A?\*.X6BW78>JK1CG/
MK4;)NSZI8V@MM5TDEWGM,-L#)S/[:F['LHMK7CISL1,\Y9J+RW,1G#YUJ#B#
MR9E!`&1?H.X8V$/F(!@Y$Z>)#U>MU4PYT[FB1Z91-HJO@=>@FHHQ=>H_X<6>
M><IXSGH]JX$X*EFK#+50'K3N0]WO_Y?6U=_,VQ:\>DNB9QRHZ!2U@>J;I@RL
MT7B-&M+G(/2/U/`,^V]&%HWC6P?8-Z82;TSC'`Z_H7^IDF<'R'X1_SNZV2L,
@Q6/ZNM?-S>6-G@Z4>TR)]S(]I0DGZ.QO@JG)$,,*````
`
end

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-10 11:20   ` Chris Moore
@ 2007-09-10 23:55     ` Richard Stallman
  2007-09-11  7:00     ` Thien-Thi Nguyen
  1 sibling, 0 replies; 11+ messages in thread
From: Richard Stallman @ 2007-09-10 23:55 UTC (permalink / raw)
  To: Chris Moore; +Cc: emacs-devel

Thanks.  If nobody installs it, please send a reminder every few days
until someone does.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-10 11:20   ` Chris Moore
  2007-09-10 23:55     ` Richard Stallman
@ 2007-09-11  7:00     ` Thien-Thi Nguyen
  2007-09-13 17:42       ` Stefan Monnier
  1 sibling, 1 reply; 11+ messages in thread
From: Thien-Thi Nguyen @ 2007-09-11  7:00 UTC (permalink / raw)
  To: Chris Moore; +Cc: emacs-devel

() "Chris Moore" <dooglus@gmail.com>
() Mon, 10 Sep 2007 13:20:23 +0200

   Changelog:
   Patch:

installed.

thi

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-11  7:00     ` Thien-Thi Nguyen
@ 2007-09-13 17:42       ` Stefan Monnier
  2007-09-13 18:38         ` Glenn Morris
                           ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Stefan Monnier @ 2007-09-13 17:42 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: Chris Moore, emacs-devel

> () "Chris Moore" <dooglus@gmail.com>
> () Mon, 10 Sep 2007 13:20:23 +0200

>    Changelog:
>    Patch:

> installed.

Thanks.  But I still wonder: why would anybody use "-c0" or "-u0"?

If you don't want context, then you're better off with the plain or `ed'
diff formats, no?


        Stefan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-13 17:42       ` Stefan Monnier
@ 2007-09-13 18:38         ` Glenn Morris
  2007-09-13 21:41           ` Stefan Monnier
  2007-09-13 20:06         ` Stephen J. Turnbull
  2007-09-14  1:40         ` Thien-Thi Nguyen
  2 siblings, 1 reply; 11+ messages in thread
From: Glenn Morris @ 2007-09-13 18:38 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Chris Moore, Thien-Thi Nguyen, emacs-devel

Stefan Monnier wrote:

> Thanks.  But I still wonder: why would anybody use "-c0" or "-u0"?
>
> If you don't want context, then you're better off with the plain or `ed'
> diff formats, no?

Previously, it also failed to work when either of the files being
diffed was a single line file (so there was no context to display with
plain -c or -u).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-13 17:42       ` Stefan Monnier
  2007-09-13 18:38         ` Glenn Morris
@ 2007-09-13 20:06         ` Stephen J. Turnbull
  2007-09-13 21:41           ` Stefan Monnier
  2007-09-14  1:40         ` Thien-Thi Nguyen
  2 siblings, 1 reply; 11+ messages in thread
From: Stephen J. Turnbull @ 2007-09-13 20:06 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Chris Moore, Thien-Thi Nguyen, emacs-devel

Stefan Monnier writes:

 > Thanks.  But I still wonder: why would anybody use "-c0" or "-u0"?

For ChangeLogs, which rarely apply if they have any context.  The
unidiff format is preferred by XEmacs because it provides the headers
which identify the ChangeLog exactly.  I don't think it hurts that all
patches are in the same format.

Not a big deal, but since it's trivial to do, why not?

 > If you don't want context, then you're better off with the plain or `ed'
 > diff formats, no?

If you remember how to read them. :-)  I only ever see those in patch
.rej files.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-13 18:38         ` Glenn Morris
@ 2007-09-13 21:41           ` Stefan Monnier
  0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2007-09-13 21:41 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Chris Moore, Thien-Thi Nguyen, emacs-devel

>> Thanks.  But I still wonder: why would anybody use "-c0" or "-u0"?
>> 
>> If you don't want context, then you're better off with the plain or `ed'
>> diff formats, no?

> Previously, it also failed to work when either of the files being
> diffed was a single line file (so there was no context to display with
> plain -c or -u).

Yes, the fix installed was right either way, I was just curious.


        Stefan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-13 20:06         ` Stephen J. Turnbull
@ 2007-09-13 21:41           ` Stefan Monnier
  0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2007-09-13 21:41 UTC (permalink / raw)
  To: Stephen J. Turnbull; +Cc: Chris Moore, Thien-Thi Nguyen, emacs-devel

>> Thanks.  But I still wonder: why would anybody use "-c0" or "-u0"?
> For ChangeLogs, which rarely apply if they have any context.

I guess that's an acceptable use for it.


        Stefan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes
  2007-09-13 17:42       ` Stefan Monnier
  2007-09-13 18:38         ` Glenn Morris
  2007-09-13 20:06         ` Stephen J. Turnbull
@ 2007-09-14  1:40         ` Thien-Thi Nguyen
  2 siblings, 0 replies; 11+ messages in thread
From: Thien-Thi Nguyen @ 2007-09-14  1:40 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Chris Moore, emacs-devel

() Stefan Monnier <monnier@iro.umontreal.ca>
() Thu, 13 Sep 2007 13:42:15 -0400

   Thanks.  But I still wonder: why would anybody use "-c0" or "-u0"?

   If you don't want context, then you're better off with the plain or `ed'
   diff formats, no?

i use -u0 sometimes to save screen space, especially if the set of changes
consists mostly of small one-line edits (e.g., to a config file).  ymmv.

thi

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-09-14  1:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-08 13:49 diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes Chris Moore
2007-09-10  1:13 ` Richard Stallman
2007-09-10 11:20   ` Chris Moore
2007-09-10 23:55     ` Richard Stallman
2007-09-11  7:00     ` Thien-Thi Nguyen
2007-09-13 17:42       ` Stefan Monnier
2007-09-13 18:38         ` Glenn Morris
2007-09-13 21:41           ` Stefan Monnier
2007-09-13 20:06         ` Stephen J. Turnbull
2007-09-13 21:41           ` Stefan Monnier
2007-09-14  1:40         ` Thien-Thi Nguyen

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).