commit 016bfe4bc2e2f43aea446f3c89e1539235c66fd2 from: Omar Polo via: Thomas Adam date: Thu Jun 23 14:09:35 2022 UTC use the commitid in the patch diff3 conflict header suggested by and ok stsp@ commit - 0f76ab831bc589bb34a4953cf60c8a05a4ed708c commit + 016bfe4bc2e2f43aea446f3c89e1539235c66fd2 blob - 7418f687e34fddd7bc47a309d75e671e26709308 blob + 490ff32c2bbf394e69fe8a5808f91bec4b3e9a41 --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -613,6 +613,7 @@ struct got_imsg_patch { int git; char old[PATH_MAX]; char new[PATH_MAX]; + char cid[41]; char blob[41]; }; blob - d713307ee278f076b3b46464b40dd6050c58a459 blob + ecf6989cbca1d92de8eb26b076cf13a213f9cd4c --- lib/patch.c +++ lib/patch.c @@ -70,6 +70,7 @@ STAILQ_HEAD(got_patch_hunk_head, got_patch_hunk); struct got_patch { char *old; char *new; + char cid[41]; char blob[41]; struct got_patch_hunk_head head; }; @@ -182,12 +183,16 @@ recv_patch(struct imsgbuf *ibuf, int *done, struct got if (patch.old[sizeof(patch.old)-1] != '\0' || patch.new[sizeof(patch.new)-1] != '\0' || + patch.cid[sizeof(patch.cid)-1] != '\0' || patch.blob[sizeof(patch.blob)-1] != '\0') { err = got_error(GOT_ERR_PRIVSEP_LEN); goto done; } - strlcpy(p->blob, patch.blob, sizeof(p->blob)); + if (*patch.cid != '\0' && *patch.blob != '\0') { + strlcpy(p->cid, patch.cid, sizeof(p->cid)); + strlcpy(p->blob, patch.blob, sizeof(p->blob)); + } /* automatically set strip=1 for git-style diffs */ if (strip == -1 && patch.git && @@ -621,7 +626,7 @@ apply_patch(int *overlapcnt, struct got_worktree *work { const struct got_error *err = NULL; int do_merge = 0, file_renamed = 0; - char *oldlabel = NULL, *newlabel = NULL; + char *oldlabel = NULL, *newlabel = NULL, *anclabel = NULL; char *oldpath = NULL, *newpath = NULL; char *tmppath = NULL, *template = NULL, *parent = NULL; char *apath = NULL, *mergepath = NULL; @@ -696,6 +701,12 @@ apply_patch(int *overlapcnt, struct got_worktree *work goto done; } + if (asprintf(&anclabel, "commit %s", p->cid) == -1) { + err = got_error_from_errno("asprintf"); + anclabel = NULL; + goto done; + } + err = got_opentemp_named(&mergepath, &mergefile, template); if (err) goto done; @@ -703,7 +714,7 @@ apply_patch(int *overlapcnt, struct got_worktree *work outfd = fileno(mergefile); err = got_merge_diff3(overlapcnt, outfd, tmpfile, afile, - oldfile, oldlabel, p->blob, newlabel, + oldfile, oldlabel, anclabel, newlabel, GOT_DIFF_ALGORITHM_PATIENCE); if (err) goto done; @@ -791,6 +802,7 @@ done: free(newpath); free(oldlabel); free(newlabel); + free(anclabel); return err; } blob - 841db30ae083c7116c5d261ae998294883ff2b52 blob + 57b57caa1ba90f49fd985a8aa10b7961a4c1ce7f --- libexec/got-read-patch/got-read-patch.c +++ libexec/got-read-patch/got-read-patch.c @@ -60,7 +60,8 @@ struct imsgbuf ibuf; static const struct got_error * -send_patch(const char *oldname, const char *newname, const char *blob, int git) +send_patch(const char *oldname, const char *newname, const char *commitid, + const char *blob, int git) { struct got_imsg_patch p; @@ -72,8 +73,10 @@ send_patch(const char *oldname, const char *newname, c if (newname != NULL) strlcpy(p.new, newname, sizeof(p.new)); - if (blob != NULL) + if (commitid != NULL && blob != NULL) { + strlcpy(p.cid, commitid, sizeof(p.cid)); strlcpy(p.blob, blob, sizeof(p.blob)); + } p.git = git; if (imsg_compose(&ibuf, GOT_IMSG_PATCH, 0, 0, -1, &p, sizeof(p)) == -1) @@ -149,7 +152,7 @@ find_patch(int *done, FILE *fp) { const struct got_error *err = NULL; char *old = NULL, *new = NULL; - char *blob = NULL; + char *commitid = NULL, *blob = NULL; char *line = NULL; size_t linesize = 0; ssize_t linelen; @@ -180,8 +183,13 @@ find_patch(int *done, FILE *fp) rename = 1; else if (!strncmp(line, "diff --git a/", 13)) { git = 1; + free(commitid); + commitid = NULL; free(blob); blob = NULL; + } else if (!git && !strncmp(line, "diff ", 5)) { + free(commitid); + err = blobid(line + 5, &commitid); } if (err) @@ -194,7 +202,8 @@ find_patch(int *done, FILE *fp) */ if (rename && old != NULL && new != NULL) { *done = 1; - err = send_patch(old, new, blob, git); + err = send_patch(old, new, commitid, + blob, git); break; } @@ -204,7 +213,8 @@ find_patch(int *done, FILE *fp) (!create && old == NULL)) err = got_error(GOT_ERR_PATCH_MALFORMED); else - err = send_patch(old, new, blob, git); + err = send_patch(old, new, commitid, + blob, git); if (err) break; @@ -218,6 +228,7 @@ find_patch(int *done, FILE *fp) free(old); free(new); + free(commitid); free(blob); free(line); if (ferror(fp) && err == NULL) blob - 6c9ee03971f22c84e0e5a023a0b18209a73bbdd8 blob + 20e899eab3a352dc9e8636b15e894c186595d20a --- regress/cmdline/patch.sh +++ regress/cmdline/patch.sh @@ -1516,6 +1516,8 @@ test_patch_merge_conflict() { test_done $testroot $ret return 1 fi + + local commit_id=`git_show_head $testroot/repo` jot 10 | sed 's/6/six/g' > $testroot/wt/numbers @@ -1555,7 +1557,7 @@ test_patch_merge_conflict() { 5 <<<<<<< --- numbers six - ||||||| f00c965d8307308469e537302baa73048488f162 + ||||||| commit $commit_id 6 ======= 3+3