[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: diff-sanity-check-hunk fails on "unterminated" hunks
From: |
Stefan Monnier |
Subject: |
Re: diff-sanity-check-hunk fails on "unterminated" hunks |
Date: |
Wed, 12 Sep 2007 01:09:38 -0400 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (gnu/linux) |
> to get all differing files at once (as any reasonable person would), I
> produced the diffs separately and concatenated them:
Yes, these diffs are problematic because you need to count the lines in
order to do the right thing and most of diff-mode.el doesn't count the lines
but just presumes that the hunk-end will be self-evident.
> 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.)
This might be right, but I think I prefer to also complain when the hunk is
formally correct but is followed by things that look like a continuation.
Especially since diff-mode will typically not handle them correctly.
Does the patch below address your particular problem (which I agree is
a case that should be handled, I've encountered it several times already,
tho that was before implementing diff-sanity-check-hunk, obviously).
Stefan
--- diff-mode.el 27 aoĆ» 2007 23:25:15 -0400 1.99.2.4
+++ diff-mode.el 12 sep 2007 01:03:59 -0400
@@ -1181,7 +1181,16 @@
(while
(case (char-after)
(?\s (decf before) (decf after) t)
- (?- (decf before) t)
+ (?-
+ (if (and (looking-at diff-file-header-re)
+ (zerop before) (zerop after))
+ ;; No need to query: this is a case where two patches
+ ;; are concatenated and only counting the lines will
+ ;; give the right result. Let's just add an empty
+ ;; line so that our code which doesn't count lines
+ ;; will not get confused.
+ (progn (save-excursion (insert "\n")) nil)
+ (decf before) t))
(?+ (decf after) t)
(t
(cond