all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* diff-sanity-check-hunk fails on "unterminated" hunks
@ 2007-09-12  1:57 Bob Rogers
  2007-09-12  5:09 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Bob Rogers @ 2007-09-12  1:57 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: message body text --]
[-- Type: text/plain, Size: 2564 bytes --]

   To reproduce the problem (in Emacs 22 or trunk):

   1.  Put the first attachment (unterminated-hunk-test.patch) in the
top directory of your Emacs working copy.

   2.  Do "emacs -Q unterminated-hunk-test.patch" to bring it up in
diff-mode.

   3.  Move point into the first hunk and type C-c C-c; it should move
to that hunk in the source, but instead it gives the error "Hunk
seriously messed up".  Doing the same thing in the second hunk should
find the source (with the message "Hunk already applied").

   Note that this patch was produced in a slightly unusual way.  Instead
of doing 

	rogers@rgrjr> diff -ur lisp/url.old lisp/url

to get all differing files at once (as any reasonable person would), I
produced the diffs separately and concatenated them:

	rogers@rgrjr> diff -u lisp/url.old/url-dav.el lisp/url/url-dav.el > unterminated-hunk-test.patch
	rogers@rgrjr> diff -u lisp/url.old/url-ftp.el lisp/url/url-ftp.el >> unterminated-hunk-test.patch

For this reason, the usual "diff -ur file1 file2" line that precedes
each file in a normal multifile diff is missing.  The start of the
second file therefore comes right after the last hunk of the first file,
and because it's a unidiff, it looks like this:

	--- lisp/url.old/url-ftp.el	2007-09-11 20:42:21.000000000 -0400
	+++ lisp/url/url-ftp.el	2007-08-13 19:47:02.000000000 -0400
	@@ -24,12 +24,12 @@

So diff-sanity-check-hunk sees one more "-" line and one more "+" line
than it should, and barfs when it comes to the "@@" for the first hunk
of the second file.

   The second attachment
(fix-diff-sanity-check-hunk-for-unterminated-hunk.patch) fixes the
problem by doing the normal exit test (exit when both line counters get
to zero) before checking the BOL character.  (It's actually just a small
change but with a lot of whitespace adjustment.)

   One could argue that this is an artificial problem caused by an
eccentric application of "diff".  However, I would argue that unidiff
hunks *are* unterminated, except by counting lines as the original code
does, so the revision strikes me as cleaner and more robust.  Also, the
concatenation of two syntactically valid patch files should also be
considered a syntactically valid patch file (modulo issues with relative
file names), so Emacs ought to deal with such files gracefully.
Finally, the issue came up naturally enough for me, so it may not be all
that rare; I ran vc-diff repeatedly on a list of changed file names,
concatenating the output into a diff-mode buffer.

   WDOT?

					-- Bob Rogers
					   http://rgrjr.dyndns.org/


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

--- lisp/url.old/url-dav.el	2007-09-11 20:42:46.000000000 -0400
+++ lisp/url/url-dav.el	2007-08-13 19:47:02.000000000 -0400
@@ -23,7 +23,7 @@
 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 ;; Boston, MA 02110-1301, USA.
 
-    ;; DAV is in RFC 2518.
+;; DAV is in RFC 2518.
 
 ;;; Commentary:
 
--- lisp/url.old/url-ftp.el	2007-09-11 20:42:21.000000000 -0400
+++ lisp/url/url-ftp.el	2007-08-13 19:47:02.000000000 -0400
@@ -24,12 +24,12 @@
 
 ;;; Commentary:
 
-    ;; We knew not what we did when we overloaded 'file' to mean 'file'
-    ;; and 'ftp' back in the dark ages of the web.
-    ;;
-    ;; This stub file is just here to please the auto-scheme-loading code
-    ;; in url-methods.el and just maps everything onto the code in
-    ;; url-file.
+;; We knew not what we did when we overloaded 'file' to mean 'file'
+;; and 'ftp' back in the dark ages of the web.
+;;
+;; This stub file is just here to please the auto-scheme-loading code
+;; in url-methods.el and just maps everything onto the code in
+;; url-file.
 
 ;;; Code:
 

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

Index: lisp/diff-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/diff-mode.el,v
retrieving revision 1.113
diff -c -r1.113 diff-mode.el
*** lisp/diff-mode.el	11 Sep 2007 06:59:13 -0000	1.113
--- lisp/diff-mode.el	12 Sep 2007 01:32:24 -0000
***************
*** 1243,1264 ****
                  (after (if (match-string 2) (string-to-number (match-string 2)) 1)))
              (forward-line)
              (while
!                 (case (char-after)
!                   (?\s (decf before) (decf after) t)
!                   (?- (decf before) t)
!                   (?+ (decf after) t)
!                   (t
!                    (cond
!                     ((and (zerop before) (zerop after)) nil)
!                     ((or (< before 0) (< after 0))
!                      (error (if (or (zerop before) (zerop after))
!                                 "End of hunk ambiguously marked"
!                               "Hunk seriously messed up")))
!                     ((not (y-or-n-p "Try to auto-fix whitespace loss and word-wrap damage? "))
!                      (error "Abort!"))
!                     ((eolp) (insert " ") (forward-line -1) t)
!                     (t (insert " ")
!                        (delete-region (- (point) 2) (- (point) 1)) t))))
                (forward-line)))))
  
         ;; A plain diff.
--- 1243,1262 ----
                  (after (if (match-string 2) (string-to-number (match-string 2)) 1)))
              (forward-line)
              (while
! 		(cond ((and (zerop before) (zerop after)) nil)
! 		      ((case (char-after)
! 			 (?\s (decf before) (decf after) t)
! 			 (?- (decf before) t)
! 			 (?+ (decf after) t)))
! 		      ((or (< before 0) (< after 0))
! 		       (error (if (or (zerop before) (zerop after))
! 				  "End of hunk ambiguously marked"
! 				  "Hunk seriously messed up")))
! 		      ((not (y-or-n-p "Try to auto-fix whitespace loss and word-wrap damage? "))
! 		       (error "Abort!"))
! 		      ((eolp) (insert " ") (forward-line -1) t)
! 		      (t (insert " ")
! 			 (delete-region (- (point) 2) (- (point) 1)) t))
                (forward-line)))))
  
         ;; A plain diff.

[-- Attachment #4: 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] 4+ messages in thread

end of thread, other threads:[~2007-09-13  2:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-12  1:57 diff-sanity-check-hunk fails on "unterminated" hunks Bob Rogers
2007-09-12  5:09 ` Stefan Monnier
2007-09-12 12:09   ` Bob Rogers
2007-09-13  2:04     ` Bob Rogers

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.