commit 4027dbc25c21bad271f5406e382054c6095523bc from: Omar Polo date: Tue Mar 22 11:20:46 2022 UTC reuse apply_hunk in patch_file when creating a file commit - 3b01d641c14e67930d70d9cc5fb8b06d0f782033 commit + 4027dbc25c21bad271f5406e382054c6095523bc blob - 20b4e1e2357e5e26d85170030eb53e9f387807e0 blob + 59e2c3f9430e3ca55e7c81bba6faf5e7222d2d4f --- lib/patch.c +++ lib/patch.c @@ -398,7 +398,6 @@ patch_file(struct got_patch *p, const char *path, FILE const struct got_error *err = NULL; struct got_patch_hunk *h; struct stat sb; - size_t i; long lineno = 0; FILE *orig; off_t copypos, pos; @@ -412,11 +411,7 @@ patch_file(struct got_patch *p, const char *path, FILE return got_error(GOT_ERR_PATCH_MALFORMED); if (nop) return NULL; - for (i = 0; i < h->len; ++i) { - if (fprintf(tmp, "%s", h->lines[i] + 1) < 0) - return got_error_from_errno("fprintf"); - } - return err; + return apply_hunk(tmp, h, &lineno); } if ((orig = fopen(path, "r")) == NULL) {