commit 4f34ed97e0f428b8e9695ed8c18c681c339f7f02 from: Omar Polo via: Thomas Adam date: Sat Aug 06 20:57:41 2022 UTC allow for ignore whitespaces when matching the hunk commit - 0335d24d8aee21c0754bcee3471af5d81b515221 commit + 4f34ed97e0f428b8e9695ed8c18c681c339f7f02 blob - 121278b253ae2dfd4d7089d23651bac456257f0d blob + 6e31c8d2cf7df53c75d28271fdeb51d2590fd306 --- lib/patch.c +++ lib/patch.c @@ -373,6 +373,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) @@ -383,7 +385,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); @@ -398,8 +400,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) { @@ -414,6 +416,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;