@matheusbsbs / matheus-bagliano / commits / 4c5868f43d
Fork 0

merge_trees(): add ancestor label parameter for diff3-style output

Commands using the merge_trees() machinery will present conflict hunks in output something like what ‘diff3 -m’ produces if the merge.conflictstyle configuration option is set to diff3. The output lacks the name of the merge base on the ||||||| line of the output, and tools can misparse the conflict hunks without it. Add a new o->ancestor parameter to merge_trees() for use as a label for the ancestor in conflict hunks. If o->ancestor is NULL, the output format is as before. All callers pass NULL for now. If o->ancestor is non-NULL and both branches renamed the base file to the same name, that name is included in the conflict hunk labels. Even if o->ancestor is NULL I think this would be a good change, but this patch only does it in the non-NULL case to ensure the output format does not change where it might matter. Requested-by: Stefan Monnier <monnier@iro.umontreal.ca> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Mar 20, 2010 at 19:41 UTC 4c5868f43d1ec2573f4f511d732bc00d56accc70
2 files changed +9 -3
merge-recursive.c
+8 -3
@@ -608,7 +608,7 @@ static int merge_3way(struct merge_options *o,
608 const char *branch2)
609 {
610 mmfile_t orig, src1, src2;
611 - char *name1, *name2;
611 + char *base_name, *name1, *name2;
612 int merge_status;
613 int favor;
614
@@ -628,10 +628,15 @@ static int merge_3way(struct merge_options *o,
628 }
629 }
630
631 - if (strcmp(a->path, b->path)) {
631 + if (strcmp(a->path, b->path) ||
632 + (o->ancestor != NULL && strcmp(a->path, one->path) != 0)) {
633 + base_name = o->ancestor == NULL ? NULL :
634 + xstrdup(mkpath("%s:%s", o->ancestor, one->path));
635 name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
636 name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
637 } else {
638 + base_name = o->ancestor == NULL ? NULL :
639 + xstrdup(mkpath("%s", o->ancestor));
640 name1 = xstrdup(mkpath("%s", branch1));
641 name2 = xstrdup(mkpath("%s", branch2));
642 }
@@ -640,7 +645,7 @@ static int merge_3way(struct merge_options *o,
645 read_mmblob(&src1, a->sha1);
646 read_mmblob(&src2, b->sha1);
647
643 - merge_status = ll_merge(result_buf, a->path, &orig, NULL,
648 + merge_status = ll_merge(result_buf, a->path, &orig, base_name,
649 &src1, name1, &src2, name2,
650 (!!o->call_depth) | (favor << 1));
651
merge-recursive.h
+1
@@ -4,6 +4,7 @@
4 #include "string-list.h"
5
6 struct merge_options {
7 + const char *ancestor;
8 const char *branch1;
9 const char *branch2;
10 enum {