Commit Diff


commit - 39479daec29a845f84812b85418dc85dc3a433a9
commit + 33df9995672a4f24ded6f8cd1575637e47d27921
blob - 9bfe37463cbe64005617a3395ea55e551360f8d1
blob + 6cc85331d4129d6f7dfec267d04e16173c9608a6
--- lib/patch.c
+++ lib/patch.c
@@ -269,7 +269,7 @@ copy(FILE *tmp, FILE *orig, off_t copypos, off_t pos)
 }
 
 static const struct got_error *
-locate_hunk(FILE *orig, struct got_patch_hunk *h, long *lineno)
+locate_hunk(FILE *orig, struct got_patch_hunk *h, off_t *pos, long *lineno)
 {
 	const struct got_error *err = NULL;
 	char *line = NULL;
@@ -307,6 +307,7 @@ locate_hunk(FILE *orig, struct got_patch_hunk *h, long
 	}
 
 	if (err == NULL) {
+		*pos = match;
 		*lineno = match_lineno;
 		if (fseek(orig, match, SEEK_SET) == -1)
 			err = got_error_from_errno("fseek");
@@ -452,13 +453,9 @@ apply_patch(struct got_worktree *worktree, struct got_
 	copypos = 0;
 	STAILQ_FOREACH(h, &p->head, entries) {
 	tryagain:
-		err = locate_hunk(orig, h, &lineno);
+		err = locate_hunk(orig, h, &pos, &lineno);
 		if (err != NULL)
 			goto done;
-		if ((pos = ftello(orig)) == -1) {
-			err = got_error_from_errno("ftello");
-			goto done;
-		}
 		err = copy(tmp, orig, copypos, pos);
 		if (err != NULL)
 			goto done;