Commit Diff


commit - bfc912128ca404176d8aebc46b2c89ee4926e1d2
commit + 122e16119c68804932abae9efbce7cad48a85a24
blob - 752292f3b5f9c267edf95a24e15610ec05c60613
blob + d89b541d0dedd769040cf62df12ad6582091b1d0
--- lib/patch.c
+++ lib/patch.c
@@ -275,7 +275,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;
@@ -313,6 +313,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");
@@ -418,11 +419,10 @@ patch_file(struct got_patch *p, const char *path, FILE
 			break;
 
 	tryagain:
-		err = locate_hunk(orig, h, &lineno);
+		err = locate_hunk(orig, h, &pos, &lineno);
 		if (err != NULL)
 			goto done;
-		if (!p->nop)
-			err = copy(tmp, orig, copypos, pos);
+		err = copy(tmp, orig, copypos, pos);
 		if (err != NULL)
 			goto done;
 		copypos = pos;