Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [PATCHv4] git apply: option to ignore whitespace differences

From: Giuseppe Bilotta <hidden>
Date: 2016-06-15 22:47:20

Possibly related (same subject, not in this thread)

On Tue, Sep 1, 2009 at 11:17 AM, Junio C Hamano[off-list ref] wrote:
quoted hunk ↗ jump to hunk
Why do you need imglen[] vla here?  IOW, can't the above be simply like
this?
diff --git a/builtin-apply.c b/builtin-apply.c
index ae11b41..c8372a0 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1874,20 +1874,18 @@ static int match_fragment(struct image *img,
       if (ws_ignore_action == ignore_ws_change) {
               size_t imgoff = 0;
               size_t preoff = 0;
               size_t postlen = postimage->len;
-               size_t imglen[preimage->nr];
               for (i = 0; i < preimage->nr; i++) {
                       size_t prelen = preimage->line[i].len;
+                       size_t imglen = img->line[try_lno+i].len;

-                       imglen[i] = img->line[try_lno+i].len;
-                       if (!fuzzy_matchlines(
-                               img->buf + try + imgoff, imglen[i],
-                               preimage->buf + preoff, prelen))
+                       if (!fuzzy_matchlines(img->buf + try + imgoff, imglen,
+                                             preimage->buf + preoff, prelen))
                               return 0;
                       if (preimage->line[i].flag & LINE_COMMON)
-                               postlen += imglen[i] - prelen;
-                       imgoff += imglen[i];
+                               postlen += imglen - prelen;
+                       imgoff += imglen;
                       preoff += prelen;
               }

               /*
@@ -1899,9 +1897,9 @@ static int match_fragment(struct image *img,
                */
               fixed_buf = xmalloc(imgoff);
               memcpy(fixed_buf, img->buf + try, imgoff);
               for (i = 0; i < preimage->nr; i++)
-                       preimage->line[i].len = imglen[i];
+                       preimage->line[i].len = img->line[try_lno+i].len;
Yep, I think that would do it. I'm not sure why I was doing it that
other way. Maybe a leftover from when I was still getting confident
with the code and I hadn't yet found the var that held the initial
match line, or something like that.

-- 
Giuseppe "Oblomov" Bilotta
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help