Björn Gustavsson <bgustavsson@xxxxxxxxx> writes: > "git apply --whitespace=fix" will not always succeed when used > on a series of patches in the following circumstances: Very nicely done. I wanted to explain to myself what "limit" and "preimage_limit" variables mean. preimage-limit has a very clear definition: this many lines from the beginning of preimage must match img, and the remainder of the preimage must be all blank (the remainder can exist only when we are trying to match at the end). On the other hand "limit" does not have such a good definition, other than as a work around to bypass line-number check when we are trying to match at the end. It might be cleaner to read if we move the problematic "line numbers must match" logic and eliminate this variable, like the attached patch does on top of this one. I couldn't figure out how this would interact with the ignore_ws_change codepath, though. That one shows a clear sign of being bolted on as an afterthought (once you fall into that "if()" statement you will not come back). builtin-apply.c | 15 +++++---------- 1 files changed, 5 insertions(+), 10 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index 4374d33..ae4452c 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1854,26 +1854,24 @@ static int match_fragment(struct image *img, { int i; char *fixed_buf, *buf, *orig, *target; - int limit; int preimage_limit; if (preimage->nr + try_lno <= img->nr) { /* * The hunk falls within the boundaries of img. */ - limit = img->nr; preimage_limit = preimage->nr; + if (match_end && (preimage->nr + try_lno != img->nr)) + return 0; } else if (ws_error_action == correct_ws_error && (ws_rule & WS_BLANK_AT_EOF) && match_end) { /* * This hunk that matches at the end extends beyond * the end of img, and we are removing blank lines - * at the end of the file. Set up the limits so that - * tests below will pass and the quick hash test - * will only test the lines up to the last line - * in img. + * at the end of the file. This many lines from the + * beginning of the preimage must match with img, and + * the remainder of the preimage must be blank. */ - limit = try_lno + preimage->nr; preimage_limit = img->nr - try_lno; } else { /* @@ -1887,9 +1885,6 @@ static int match_fragment(struct image *img, if (match_beginning && try_lno) return 0; - if (match_end && preimage->nr + try_lno != limit) - return 0; - /* Quick hash check */ for (i = 0; i < preimage_limit; i++) if (preimage->line[i].hash != img->line[try_lno + i].hash) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html