all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* diff-goto-source fails if "-p" is in diff-switches
@ 2007-02-07 14:12 Per Cederqvist
  2007-02-08  9:49 ` Per Cederqvist
  0 siblings, 1 reply; 2+ messages in thread
From: Per Cederqvist @ 2007-02-07 14:12 UTC (permalink / raw)
  To: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

Revision 1.94 of diff-mode.el (committed 2007-01-11) introduced a
regression.  Now, the diff-goto-source function fails with either of
the error messages below if "-p" is present in diff-switches:

    Unrecognized context diff first hunk header format
    Unrecognized unified diff hunk header format

The enclosed patch makes diff-sanity-check-hunk less picky on the
format, so that diff-goto-sources starts working again even if
diff-switches is set to "-p" or "-up".

One way to reproduce the problem is to check out the Emacs source code
from CVS, edit emacs/src/abbrev.c, inserting a character in the
syms_of_abbrev function, saving the buffer, do M-x set-variable RET
diff-switches RET "-up" RET, do M-x vc-diff, move the cursor down to
the character you inserted, and press C-c C-c.  Instead of jumping to
the same place in the source buffer, you will get the second error
message reported above.

    /ceder


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Teach diff-sanity-check-hunk to accept output from diff -u --]
[-- Type: text/x-patch, Size: 1805 bytes --]

Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.10655
diff -u -r1.10655 ChangeLog
--- lisp/ChangeLog	7 Feb 2007 13:40:09 -0000	1.10655
+++ lisp/ChangeLog	7 Feb 2007 13:52:04 -0000
@@ -1,3 +1,8 @@
+2007-02-07  Per Cederqvist  <ceder@lysator.liu.se>
+
+	* diff-mode.el (diff-sanity-check-hunk): Don't reject the hunk
+	just because the diff was produced using "-p" (--show-c-function).
+
 2007-02-07  Vinicius Jose Latorre  <viniciusjl@ig.com.br>
 
 	* ps-print.ps: The ps-print commands without face printing should not
Index: lisp/diff-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/diff-mode.el,v
retrieving revision 1.94
diff -u -r1.94 diff-mode.el
--- lisp/diff-mode.el	11 Jan 2007 16:52:59 -0000	1.94
+++ lisp/diff-mode.el	7 Feb 2007 13:52:04 -0000
@@ -1115,7 +1115,7 @@
 
        ;; A context diff.
        ((eq (char-after) ?*)
-        (if (not (looking-at "\\*\\{15\\}\n\\*\\*\\* \\([0-9]+\\),\\([0-9]+\\) \\*\\*\\*\\*$"))
+        (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
@@ -1131,7 +1131,7 @@
        ;; A unified diff.
        ((eq (char-after) ?@)
         (if (not (looking-at
-                  "@@ -[0-9]+,\\([0-9]+\\) \\+[0-9]+,\\([0-9]+\\) @@$"))
+                  "@@ -[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))))

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

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

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

* Re: diff-goto-source fails if "-p" is in diff-switches
  2007-02-07 14:12 diff-goto-source fails if "-p" is in diff-switches Per Cederqvist
@ 2007-02-08  9:49 ` Per Cederqvist
  0 siblings, 0 replies; 2+ messages in thread
From: Per Cederqvist @ 2007-02-08  9:49 UTC (permalink / raw)
  To: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2214 bytes --]

Per Cederqvist <ceder@lysator.liu.se> writes:

> Revision 1.94 of diff-mode.el (committed 2007-01-11) introduced a
> regression.  Now, the diff-goto-source function fails with either of
> the error messages below if "-p" is present in diff-switches:
> 
>     Unrecognized context diff first hunk header format
>     Unrecognized unified diff hunk header format
> 
> The enclosed patch makes diff-sanity-check-hunk less picky on the
> format, so that diff-goto-sources starts working again even if
> diff-switches is set to "-p" or "-up".
> 
> One way to reproduce the problem is to check out the Emacs source code
> from CVS, edit emacs/src/abbrev.c, inserting a character in the
> syms_of_abbrev function, saving the buffer, do M-x set-variable RET
> diff-switches RET "-up" RET, do M-x vc-diff, move the cursor down to
> the character you inserted, and press C-c C-c.  Instead of jumping to
> the same place in the source buffer, you will get the second error
> message reported above.
> 
>     /ceder

I see that the committer dediced to improve my patch before committing
it.  Unfortunately, the improvement casuses context diffs produced
with "-p" to fail.  Here is an example of a diff header for a context
diff with "-p":

*************** func_name(int x, int y)
*** 10,14 ****

Note how the extra text is placed: at the end of the all-star line,
not after the numbers.  This is documented in the diff manual:

> Then they add that line to the end of the line of asterisks in the
> context format, or to the `@@' line in unified format.

The enclosed patch (which was produced using "cvs diff -c -F
'^(defun'") just to show another way to produce that output format)
fixes this problem.  Please note that "." in a regexp does not match a
newline, so this regexp should be safe.

If there are versions of diff that actually place the function name
after the line numbers, the trailing dollar sign in the regexp should
be removed.  I'm not aware of any, though.  I have tested GNU diff
2.8.7 and GNU diff 2.8.1.

    /ceder, who doesn't like getting the blame for committing code I
            never wrote -- if you edit this before making the commit,
            please say so in the ChangeLog entry as well

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix parsing of \"diff -p\" for context diffs. --]
[-- Type: text/x-patch, Size: 1765 bytes --]

Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.10663
diff -c -F^(defun -r1.10663 ChangeLog
*** lisp/ChangeLog	8 Feb 2007 06:31:28 -0000	1.10663
--- lisp/ChangeLog	8 Feb 2007 09:39:42 -0000
***************
*** 1,3 ****
--- 1,9 ----
+ 2007-02-08  Per Cederqvist  <ceder@lysator.liu.se>  (tiny change)
+ 
+ 	* diff-mode.el (diff-sanity-check-hunk): My fix to this function
+ 	that was committed on 2007-02-07 was edited by the committer.  The
+ 	"improved" version fails for context diffs that use "-p".  Fix.
+ 
  2007-02-08  Karl Fogel  <kfogel@red-bean.com>
  
  	* emacs/lisp/simple.el (fundamental-mode-hook): Declare new hook.
Index: lisp/diff-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/diff-mode.el,v
retrieving revision 1.95
diff -c -F^(defun -r1.95 diff-mode.el
*** lisp/diff-mode.el	7 Feb 2007 17:08:36 -0000	1.95
--- lisp/diff-mode.el	8 Feb 2007 09:39:42 -0000
*************** (defun diff-sanity-check-hunk ()
*** 1115,1121 ****
  
         ;; 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
--- 1115,1121 ----
  
         ;; 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

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

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

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

end of thread, other threads:[~2007-02-08  9:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-07 14:12 diff-goto-source fails if "-p" is in diff-switches Per Cederqvist
2007-02-08  9:49 ` Per Cederqvist

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.