use the commitid in the patch diff3 conflict header suggested by and 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index 8b9f4c0..8e99bbe 100644
--- a/lib/got_lib_privsep.h
+++ b/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];
};
diff --git a/lib/patch.c b/lib/patch.c
index 9fbe217..9209e54 100644
--- a/lib/patch.c
+++ b/lib/patch.c
@@ -73,6 +73,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;
};
@@ -185,12 +186,16 @@ recv_patch(struct imsgbuf *ibuf, int *done, struct got_patch *p, int strip)
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 &&
@@ -624,7 +629,7 @@ apply_patch(int *overlapcnt, struct got_worktree *worktree,
{
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;
@@ -699,6 +704,12 @@ apply_patch(int *overlapcnt, struct got_worktree *worktree,
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;
@@ -706,7 +717,7 @@ apply_patch(int *overlapcnt, struct got_worktree *worktree,
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;
@@ -794,6 +805,7 @@ done:
free(newpath);
free(oldlabel);
free(newlabel);
+ free(anclabel);
return err;
}
diff --git a/libexec/got-read-patch/got-read-patch.c b/libexec/got-read-patch/got-read-patch.c
index ba9f841..5f1a284 100644
--- a/libexec/got-read-patch/got-read-patch.c
+++ b/libexec/got-read-patch/got-read-patch.c
@@ -61,7 +61,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;
@@ -73,8 +74,10 @@ send_patch(const char *oldname, const char *newname, const char *blob, int git)
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)
@@ -150,7 +153,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;
@@ -181,8 +184,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)
@@ -195,7 +203,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;
}
@@ -205,7 +214,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;
@@ -219,6 +229,7 @@ find_patch(int *done, FILE *fp)
free(old);
free(new);
+ free(commitid);
free(blob);
free(line);
if (ferror(fp) && err == NULL)
diff --git a/regress/cmdline/patch.sh b/regress/cmdline/patch.sh
index 6c9ee03..20e899e 100755
--- a/regress/cmdline/patch.sh
+++ b/regress/cmdline/patch.sh
@@ -1517,6 +1517,8 @@ test_patch_merge_conflict() {
return 1
fi
+ local commit_id=`git_show_head $testroot/repo`
+
jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
(cd $testroot/wt && got diff > $testroot/old.diff \
@@ -1555,7 +1557,7 @@ test_patch_merge_conflict() {
5
<<<<<<< --- numbers
six
- ||||||| f00c965d8307308469e537302baa73048488f162
+ ||||||| commit $commit_id
6
=======
3+3