Commit Diff


commit - 0c6f49baf2b43adf1cd027050d27fc32ef8454da
commit + 8afec5d5388b965430c12e3405765ceb552faefa
blob - 9dccdc479c87919f89cf0a8b01fb1f3ab5b367ca
blob + c7465535acc5666625d7b591529f651371547808
--- lib/patch.c
+++ lib/patch.c
@@ -189,10 +189,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 &&
@@ -686,6 +687,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) {
@@ -705,7 +708,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 - be5fd59f7bd22bcddb4107bc9b7d0a9d415c93fa
blob + 6ef560b1f7733ae1a05b7a9de9c80f90453766a4
--- libexec/got-read-patch/got-read-patch.c
+++ libexec/got-read-patch/got-read-patch.c
@@ -73,10 +73,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)