Download raw body.
two small fixes for got patch
Omar Polo <op@omarpolo.com> wrote:
> thanks thomas and stsp for reviewing!
>
> I had another small tweak i'd like to commit before moving into more
> interesting diffs (dry run, error recovering, no final newline etc) that
> I forgot to include in previous mail, apologies.
>
> The following moves some checks done in apply_patch early in recv_patch
> so that we bail out early in case of malformed patches and changes the
> error for mismatching paths from
>
> % got patch < diff
> got: the paths mentioned in the patch are different.
> to
> % got patch < diff
> got: old file is "foo" and new "bar": paths are different
>
> OK?
apologies for the non-applying diff. it was meant to be applied on top
of the "check file status before applying a patch" diff I sent a few
days ago (and that's still pending ;-). Anyway, here's another version
of the diff that applies on top of the current main branch.
diff ca6444c5b3830627626458222ef3f16852e3505f /home/op/w/got
blob - 64f2cb93558b933d2ffdcc0da7dedecf78d8ee52
file + include/got_error.h
--- include/got_error.h
+++ include/got_error.h
@@ -346,8 +346,7 @@ static const struct got_error {
{ GOT_ERR_PATCH_MALFORMED, "malformed patch" },
{ GOT_ERR_PATCH_TRUNCATED, "patch truncated" },
{ GOT_ERR_PATCH_DONT_APPLY, "patch doesn't apply" },
- { GOT_ERR_PATCH_PATHS_DIFFER, "the paths mentioned in the patch "
- "are different." },
+ { GOT_ERR_PATCH_PATHS_DIFFER, "paths are different" },
{ GOT_ERR_NO_PATCH, "no patch found" },
};
blob - 6cc85331d4129d6f7dfec267d04e16173c9608a6
file + lib/patch.c
--- lib/patch.c
+++ lib/patch.c
@@ -173,6 +173,17 @@ recv_patch(struct imsgbuf *ibuf, int *done, struct got
goto done;
}
+ if (p->old == NULL && p->new == NULL) {
+ err = got_error(GOT_ERR_PATCH_MALFORMED);
+ goto done;
+ }
+ if (p->old != NULL && p->new != NULL && strcmp(p->old, p->new)) {
+ err = got_error_fmt(GOT_ERR_PATCH_PATHS_DIFFER,
+ "old file is \"%s\" and new \"%s\"",
+ p->old, p->new);
+ goto done;
+ }
+
imsg_free(&imsg);
for (;;) {
@@ -396,9 +407,6 @@ apply_patch(struct got_worktree *worktree, struct got_
TAILQ_INIT(&paths);
- if (p->old == NULL && p->new == NULL)
- return got_error(GOT_ERR_PATCH_MALFORMED);
-
err = got_worktree_resolve_path(&path, worktree,
p->new != NULL ? p->new : p->old);
if (err)
@@ -415,9 +423,6 @@ apply_patch(struct got_worktree *worktree, struct got_
err = got_worktree_schedule_delete(worktree, &paths,
0, NULL, delete_cb, delete_arg, repo, 0, 0);
goto done;
- } else if (p->old != NULL && strcmp(p->old, p->new)) {
- err = got_error(GOT_ERR_PATCH_PATHS_DIFFER);
- goto done;
}
if (asprintf(&template, "%s/got-patch",
two small fixes for got patch