commit afbf14b354450516386d5af531a554eae463fd1f from: Omar Polo via: Thomas Adam date: Tue Mar 22 17:54:12 2022 UTC reuse apply_hunk in patch_file when creating a file commit - 3eb4f6293effeabefeb3842df6c2d10e06886737 commit + afbf14b354450516386d5af531a554eae463fd1f blob - 29295ac235d6bebb1b5aba1c2f3c35a681856ed6 blob + 93ee4e2f11acb992d6fb5092844613caeb4d2112 --- lib/patch.c +++ lib/patch.c @@ -397,7 +397,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; @@ -411,11 +410,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) {