patch_file: fill tmp with the patched file even in nop mode future work with diff3 merge will need the fully patched file even in the nop mode ok stsp@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/lib/patch.c b/lib/patch.c
index cb80bed..0a98afc 100644
--- a/lib/patch.c
+++ b/lib/patch.c
@@ -455,7 +455,7 @@ apply_hunk(FILE *tmp, struct got_patch_hunk *h, int *lineno)
}
static const struct got_error *
-patch_file(struct got_patch *p, FILE *orig, FILE *tmp, int nop, mode_t *mode)
+patch_file(struct got_patch *p, FILE *orig, FILE *tmp, mode_t *mode)
{
const struct got_error *err = NULL;
struct got_patch_hunk *h;
@@ -470,8 +470,6 @@ patch_file(struct got_patch *p, FILE *orig, FILE *tmp, int nop, mode_t *mode)
h = STAILQ_FIRST(&p->head);
if (h == NULL || STAILQ_NEXT(h, entries) != NULL)
return got_error(GOT_ERR_PATCH_MALFORMED);
- if (nop)
- return NULL;
return apply_hunk(tmp, h, &lineno);
}
@@ -487,8 +485,7 @@ patch_file(struct got_patch *p, FILE *orig, FILE *tmp, int nop, mode_t *mode)
h->err = err;
if (err != NULL)
return err;
- if (!nop)
- err = copy(tmp, orig, copypos, pos);
+ err = copy(tmp, orig, copypos, pos);
if (err != NULL)
return err;
copypos = pos;
@@ -513,8 +510,7 @@ patch_file(struct got_patch *p, FILE *orig, FILE *tmp, int nop, mode_t *mode)
if (lineno + 1 != h->old_from)
h->offset = lineno + 1 - h->old_from;
- if (!nop)
- err = apply_hunk(tmp, h, &lineno);
+ err = apply_hunk(tmp, h, &lineno);
if (err != NULL)
return err;
@@ -527,7 +523,7 @@ patch_file(struct got_patch *p, FILE *orig, FILE *tmp, int nop, mode_t *mode)
h = STAILQ_FIRST(&p->head);
h->err = got_error(GOT_ERR_HUNK_FAILED);
err = h->err;
- } else if (!nop && !feof(orig))
+ } else if (!feof(orig))
err = copy(tmp, orig, copypos, -1);
return err;
@@ -610,11 +606,10 @@ apply_patch(struct got_worktree *worktree, struct got_repository *repo,
goto done;
}
- if (!nop)
- err = got_opentemp_named(&tmppath, &tmp, template);
+ err = got_opentemp_named(&tmppath, &tmp, template);
if (err)
goto done;
- err = patch_file(p, oldfile, tmp, nop, &mode);
+ err = patch_file(p, oldfile, tmp, &mode);
if (err)
goto done;