From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Chris Moore" Newsgroups: gmane.emacs.devel,gmane.emacs.pretest.bugs Subject: diff-mode doesn't like "-c0" or "-u0" diff output for single-line changes Date: Sat, 8 Sep 2007 15:49:19 +0200 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0466892547==" X-Trace: sea.gmane.org 1189259374 28184 80.91.229.12 (8 Sep 2007 13:49:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 8 Sep 2007 13:49:34 +0000 (UTC) To: emacs-pretest-bug@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 08 15:49:33 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IU0gk-0006h1-Tg for ged-emacs-devel@m.gmane.org; Sat, 08 Sep 2007 15:49:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IU0gi-0001dZ-OO for ged-emacs-devel@m.gmane.org; Sat, 08 Sep 2007 09:49:28 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IU0gf-0001bq-Kj for emacs-devel@gnu.org; Sat, 08 Sep 2007 09:49:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IU0gf-0001bK-A1 for emacs-devel@gnu.org; Sat, 08 Sep 2007 09:49:25 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IU0ge-0001bC-UP for emacs-devel@gnu.org; Sat, 08 Sep 2007 09:49:24 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IU0ge-0007sr-Hf for emacs-devel@gnu.org; Sat, 08 Sep 2007 09:49:24 -0400 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by fencepost.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IU0gK-0003Qa-1p for emacs-pretest-bug@gnu.org; Sat, 08 Sep 2007 09:49:04 -0400 Original-Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1IU0gb-0007s2-Sk for emacs-pretest-bug@gnu.org; Sat, 08 Sep 2007 09:49:24 -0400 Original-Received: from rv-out-0910.google.com ([209.85.198.188]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IU0gb-0007rk-9U for emacs-pretest-bug@gnu.org; Sat, 08 Sep 2007 09:49:21 -0400 Original-Received: by rv-out-0910.google.com with SMTP id c27so600405rvf for ; Sat, 08 Sep 2007 06:49:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:mime-version:content-type:x-google-sender-auth; bh=PM4V/hByUfyPyYF0WqueoocC0YITQGiUNcB4pltPrw8=; b=QfKSVE0apyFl8XYeapMRcfDFbMSg6GHl4iAHgUgiG3lHBilTnVsCE145D8xmfaQRZBMTRzlNxJ0crvApGqo+OODGykh1fr5T949gIxzYIz2H+2Cw5KX1F5TOhX4n2SjRHjLwlwjMX+71Q3ajMRtXXUYLx6z/k5dt4hC51ZECEUk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:x-google-sender-auth; b=ORcBc5KRGR13xiJoKdus7FzoUrtRSh11Ci1Swfc0LRLQg7CuMAciHaC3Lg0ykJgZZW6FSo9sQsLboQZi4tq7bY4mXbxUZ32Cha/BMnLmu3P1Gz7qsRLMVIWqHyMHHhY1c1PcnjKnNirBDf6F24l1Yq5oyViqC4mOyH9CmC4qSV8= Original-Received: by 10.142.174.8 with SMTP id w8mr141544wfe.1189259359230; Sat, 08 Sep 2007 06:49:19 -0700 (PDT) Original-Received: by 10.143.4.2 with HTTP; Sat, 8 Sep 2007 06:49:19 -0700 (PDT) X-Google-Sender-Auth: c42a2ae7da2d48c2 X-Detected-Kernel: Linux 2.6 (newer, 2) X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:78264 gmane.emacs.pretest.bugs:19778 Archived-At: --===============0466892547== Content-Type: multipart/alternative; boundary="----=_Part_5105_2046619.1189259359227" ------=_Part_5105_2046619.1189259359227 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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) ------- ------=_Part_5105_2046619.1189259359227 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
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)

-------

------=_Part_5105_2046619.1189259359227-- --===============0466892547== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --===============0466892547==--