summaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-10-12 13:51:44 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-10-12 13:51:45 -0700
commit62a7648a5e0968c25bd7a0b9ff9103f920c19a8d (patch)
tree2ab652f222af5ef08624d43dc034705ce160e63d /apply.c
parentMerge branch 'ab/send-email-config-fix' into maint (diff)
parentapply: resolve trivial merge without hitting ll-merge with "--3way" (diff)
downloadtgif-62a7648a5e0968c25bd7a0b9ff9103f920c19a8d.tar.xz
Merge branch 'jc/trivial-threeway-binary-merge' into maint
The "git apply -3" code path learned not to bother the lower level merge machinery when the three-way merge can be trivially resolved without the content level merge. * jc/trivial-threeway-binary-merge: apply: resolve trivial merge without hitting ll-merge with "--3way"
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/apply.c b/apply.c
index 4ed4b27169..43a0aebf4e 100644
--- a/apply.c
+++ b/apply.c
@@ -3468,6 +3468,21 @@ static int load_preimage(struct apply_state *state,
return 0;
}
+static int resolve_to(struct image *image, const struct object_id *result_id)
+{
+ unsigned long size;
+ enum object_type type;
+
+ clear_image(image);
+
+ image->buf = read_object_file(result_id, &type, &size);
+ if (!image->buf || type != OBJ_BLOB)
+ die("unable to read blob object %s", oid_to_hex(result_id));
+ image->len = size;
+
+ return 0;
+}
+
static int three_way_merge(struct apply_state *state,
struct image *image,
char *path,
@@ -3479,6 +3494,12 @@ static int three_way_merge(struct apply_state *state,
mmbuffer_t result = { NULL };
int status;
+ /* resolve trivial cases first */
+ if (oideq(base, ours))
+ return resolve_to(image, theirs);
+ else if (oideq(base, theirs) || oideq(ours, theirs))
+ return resolve_to(image, ours);
+
read_mmblob(&base_file, base);
read_mmblob(&our_file, ours);
read_mmblob(&their_file, theirs);