commit 497a59156be73918988396d3f7378fb8c7b6da8d from: Omar Polo date: Mon Jun 27 18:47:02 2022 UTC handle blob ids without corresponding blob ids ok stsp@ commit - 58e31a80da4f4a9e10eaea148672190f35107a47 commit + 497a59156be73918988396d3f7378fb8c7b6da8d blob - 965f8606f5dc0febfa47fceeba356519258f1021 blob + 9c2a6eea387f21e2d874e520ee11a682facc654b --- lib/patch.c +++ lib/patch.c @@ -192,10 +192,11 @@ recv_patch(struct imsgbuf *ibuf, int *done, struct got goto done; } - if (*patch.cid != '\0' && *patch.blob != '\0') { + if (*patch.cid != '\0') strlcpy(p->cid, patch.cid, sizeof(p->cid)); + + if (*patch.blob != '\0') strlcpy(p->blob, patch.blob, sizeof(p->blob)); - } /* automatically set strip=1 for git-style diffs */ if (strip == -1 && patch.git && @@ -689,6 +690,8 @@ apply_patch(int *overlapcnt, struct got_worktree *work goto done; if (do_merge) { + const char *type, *id; + if (fseeko(afile, 0, SEEK_SET) == -1 || fseeko(oldfile, 0, SEEK_SET) == -1 || fseeko(tmpfile, 0, SEEK_SET) == -1) { @@ -708,7 +711,15 @@ apply_patch(int *overlapcnt, struct got_worktree *work goto done; } - if (asprintf(&anclabel, "commit %s", p->cid) == -1) { + if (*p->cid != '\0') { + type = "commit"; + id = p->cid; + } else { + type = "blob"; + id = p->blob; + } + + if (asprintf(&anclabel, "%s %s", type, id) == -1) { err = got_error_from_errno("asprintf"); anclabel = NULL; goto done; blob - 05415ddde579ebfde446284ba961406bc37a4255 blob + 14191697a10b4dbbc2cd5609d898d7830564529a --- libexec/got-read-patch/got-read-patch.c +++ libexec/got-read-patch/got-read-patch.c @@ -74,10 +74,11 @@ send_patch(const char *oldname, const char *newname, c if (newname != NULL) strlcpy(p.new, newname, sizeof(p.new)); - if (commitid != NULL && blob != NULL) { + if (commitid != NULL) strlcpy(p.cid, commitid, sizeof(p.cid)); + + if (blob != NULL) strlcpy(p.blob, blob, sizeof(p.blob)); - } p.git = git; if (imsg_compose(&ibuf, GOT_IMSG_PATCH, 0, 0, -1, &p, sizeof(p)) == -1)