handle blob ids without corresponding blob ids 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
diff --git a/lib/patch.c b/lib/patch.c
index 965f860..9c2a6ee 100644
--- a/lib/patch.c
+++ b/lib/patch.c
@@ -192,10 +192,11 @@ recv_patch(struct imsgbuf *ibuf, int *done, struct got_patch *p, int strip)
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 *worktree,
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 *worktree,
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;
diff --git a/libexec/got-read-patch/got-read-patch.c b/libexec/got-read-patch/got-read-patch.c
index 05415dd..1419169 100644
--- a/libexec/got-read-patch/got-read-patch.c
+++ b/libexec/got-read-patch/got-read-patch.c
@@ -74,10 +74,11 @@ send_patch(const char *oldname, const char *newname, const char *commitid,
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)