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

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