From: Junio C Hamano <junkio@cox.net>
To: "Marco Costalba" <mcostalba@gmail.com>
Cc: "Git Mailing List" <git@vger.kernel.org>
Subject: Re: [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at end of file
Date: Sat, 19 May 2007 16:03:38 -0700 [thread overview]
Message-ID: <7vsl9stnzp.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <e5bfff550705191458o3fa1d1a0ndd916d1efafdd2a7@mail.gmail.com> (Marco Costalba's message of "Sat, 19 May 2007 23:58:54 +0200")
"Marco Costalba" <mcostalba@gmail.com> writes:
> What about this?
>
> builtin-apply.c | 13 +++++++++----
> 1 files changed, 9 insertions(+), 4 deletions(-)
You count the trailing blank lines in new and old, and if new
one has more you strip them out, which _sounds_ sane.
But it is unclear to me how you are limiting the processing to
the very end of the file. The "new" and "old" essentially is a
patch fragment that is separated into two, and the part you
modified with your patch does not know if the hunk applies at
the end of the patch yet.
That is, given this patch:
diff --git a/builtin-apply.c b/builtin-apply.c
index 9e82757..113c71f 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1746,10 +1746,15 @@ static int apply_one_fragment(struct buffer_desc *des..
newsize--;
}
- if (new_whitespace == strip_whitespace)
- while (newsize > 1 && !strncmp(new + newsize - 2, "\n\n", 2))
- newsize--;
-
+ if (new_whitespace == strip_whitespace) {
+ int cnt1 = 1, cnt2 = 1;
+ while (newsize - cnt1 > 1 && new[newsize - cnt1] == '\n')
+ cnt1++;
+ while (oldsize - cnt2 > 1 && new[newsize - cnt2] == '\n')
+ cnt2++;
+ if (cnt1 > cnt2 && cnt1 > 2)
+ newsize -= cnt1 - cnt2;
+ }
oldlines = old;
newlines = new;
leading = frag->leading;
"new" has these lines
newsize--;
}
if (new_whitespace == strip_whitespace) {
int cnt1 = 1, cnt2 = 1;
while (newsize - cnt1 > 1 && new[newsize - cnt1] == '\n')
cnt1++;
while (oldsize - cnt2 > 1 && new[newsize - cnt2] == '\n')
cnt2++;
if (cnt1 > cnt2 && cnt1 > 2)
newsize -= cnt1 - cnt2;
}
oldlines = old;
newlines = new;
leading = frag->leading;
while "old" has this:
newsize--;
}
if (new_whitespace == strip_whitespace)
while (newsize > 1 && !strncmp(new + newsize - 2, "\n\n", 2))
newsize--;
oldlines = old;
newlines = new;
leading = frag->leading;
and these may or may not be at the end of the file, so
inspecting what blank lines they have at the end is not
sufficient. If "new" does not introduce new blank lines at its
end, then you can be sure that you are not adding trailing blank
lines, but even if "new" does introduce a new blank line at the
end, you do not know if that is adding it to the end of the
file, or in the middle.
You do not know where the hunk is applied until you do the loop
that follows the part your patch we are discussing.
next prev parent reply other threads:[~2007-05-19 23:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-19 13:12 [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at end of file Marco Costalba
2007-05-19 20:39 ` Junio C Hamano
2007-05-19 21:58 ` Marco Costalba
2007-05-19 23:03 ` Junio C Hamano [this message]
2007-05-19 23:18 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vsl9stnzp.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=mcostalba@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).