From: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Robert Fitzsimons <robfitz@273k.net>,
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Subject: [PATCH 2/2] git apply: preserve original whitespace with --ignore-whitespace
Date: Thu, 2 Jul 2009 14:52:17 +0200 [thread overview]
Message-ID: <1246539137-24754-3-git-send-email-giuseppe.bilotta@gmail.com> (raw)
In-Reply-To: <1246539137-24754-2-git-send-email-giuseppe.bilotta@gmail.com>
---
builtin-apply.c | 32 +++++++++++++++++++++++++++++---
1 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 86860d6..d213cce 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1640,6 +1640,10 @@ static void update_pre_post_images(struct image *preimage,
int i, ctx;
char *new, *old, *fixed;
struct image fixed_preimage;
+ /* Do we need more space for the postimage? */
+ size_t newlen = postimage->len;
+ if (len > preimage->len)
+ newlen += len - preimage->len;
/*
* Update the preimage with whitespace fixes. Note that we
@@ -1654,11 +1658,16 @@ static void update_pre_post_images(struct image *preimage,
*preimage = fixed_preimage;
/*
- * Adjust the common context lines in postimage, in place.
+ * Adjust the common context lines in postimage, in place
+ * if we are not ignoring whitespace differences.
* This is possible because whitespace fixing does not make
* the string grow.
*/
- new = old = postimage->buf;
+ old = postimage->buf;
+ if (ignore_whitespace)
+ new = postimage->buf = xmalloc(newlen);
+ else
+ new = old;
fixed = preimage->buf;
for (i = ctx = 0; i < postimage->nr; i++) {
size_t len = postimage->line[i].len;
@@ -1730,8 +1739,25 @@ static int match_fragment(struct image *img,
if ((match_end
? (try + preimage->len == img->len)
: (try + preimage->len <= img->len)) &&
- !memcmp_switch(img->buf + try, preimage->buf, preimage->len))
+ !memcmp_switch(img->buf + try, preimage->buf, preimage->len)) {
+ if (ignore_whitespace) {
+ /*
+ * Replace the preimage whitespace with the original one
+ */
+ size_t newlen = 0;
+ for (i = 0; i < preimage->nr; i++) {
+ newlen += preimage->line[i].len =
+ img->line[try_lno + i].len;
+ }
+ fixed_buf = xmalloc(newlen);
+ memcpy(fixed_buf, img->buf + try, newlen);
+
+ update_pre_post_images(
+ preimage, postimage,
+ fixed_buf, newlen);
+ }
return 1;
+ }
if (!ignore_whitespace && (ws_error_action != correct_ws_error))
return 0;
--
1.6.3.3.512.g1f6a.dirty
next prev parent reply other threads:[~2009-07-02 12:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-02 12:52 [PATCH 0/2] git apply: cope with whitespace differences Giuseppe Bilotta
2009-07-02 12:52 ` [PATCH 1/2] git apply: option to ignore " Giuseppe Bilotta
2009-07-02 12:52 ` Giuseppe Bilotta [this message]
2009-07-02 16:46 ` Junio C Hamano
2009-07-02 17:46 ` Giuseppe Bilotta
2009-07-02 18:29 ` 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=1246539137-24754-3-git-send-email-giuseppe.bilotta@gmail.com \
--to=giuseppe.bilotta@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=robfitz@273k.net \
/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).