commit 445d38d7eafbd42b45d230374395225256a9994e from: Omar Polo date: Mon Aug 01 08:11:56 2022 UTC allow for ignore whitespaces when matching the hunk commit - 311b7e33449ba2b480b546b8e5b79221b1539b70 commit + 445d38d7eafbd42b45d230374395225256a9994e blob - b662fd9440dd44cb727518f3d66665658c6eea34 blob + e1e9258d4e6f76c6226e2040023e078361240dd1 --- lib/patch.c +++ lib/patch.c @@ -375,6 +375,8 @@ copy(FILE *tmp, FILE *orig, off_t copypos, off_t pos) } return NULL; } + +static int linecmp(const char *, const char *, int *); static const struct got_error * locate_hunk(FILE *orig, struct got_patch_hunk *h, off_t *pos, int *lineno) @@ -385,7 +387,7 @@ locate_hunk(FILE *orig, struct got_patch_hunk *h, off_ size_t linesize = 0; ssize_t linelen; off_t match = -1; - int match_lineno = -1; + int mangled = 0, match_lineno = -1; for (;;) { linelen = getline(&line, &linesize, orig); @@ -400,8 +402,8 @@ locate_hunk(FILE *orig, struct got_patch_hunk *h, off_ line[linelen - 1] = '\0'; (*lineno)++; - if ((mode == ' ' && !strcmp(h->lines[0] + 1, line)) || - (mode == '-' && !strcmp(h->lines[0] + 1, line)) || + if ((mode == ' ' && !linecmp(h->lines[0] + 1, line, &mangled)) || + (mode == '-' && !linecmp(h->lines[0] + 1, line, &mangled)) || (mode == '+' && *lineno == h->old_from)) { match = ftello(orig); if (match == -1) { @@ -416,6 +418,9 @@ locate_hunk(FILE *orig, struct got_patch_hunk *h, off_ break; } + if (mangled) + h->ws_mangled = 1; + if (err == NULL) { *pos = match; *lineno = match_lineno;