Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2019-08-16 00:40:32 +0300
committerJunio C Hamano <gitster@pobox.com>2019-08-16 22:47:20 +0300
commit139ef37a2f4daf2071debeca8b2115b4e4b0a33f (patch)
treebe14e0863d5af8089936f191fa8da46c23ca1c56 /merge-recursive.c
parent65c01c644250fb0a92f929c2fc61f33771bf480f (diff)
merge-recursive: enforce opt->ancestor != NULL when calling merge_trees()
We always want our conflict hunks to be labelled so that users can know where each came from. The previous commit fixed the one caller in the codebase which was not setting opt->ancestor (and thus not providing a label for the "merge base" conflict hunk in diff3-style conflict markers); add an assertion to prevent future codepaths from also overlooking this requirement. Enforcing this requirement also allows us to simplify the code for labelling the conflict hunks by no longer checking if the ancestor label is NULL. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-recursive.c')
-rw-r--r--merge-recursive.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/merge-recursive.c b/merge-recursive.c
index 1d960fa64b..a67ea4957a 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1019,7 +1019,7 @@ static int merge_3way(struct merge_options *opt,
{
mmfile_t orig, src1, src2;
struct ll_merge_options ll_opts = {0};
- char *base_name, *name1, *name2;
+ char *base, *name1, *name2;
int merge_status;
ll_opts.renormalize = opt->renormalize;
@@ -1043,16 +1043,13 @@ static int merge_3way(struct merge_options *opt,
}
}
- assert(a->path && b->path && o->path);
- if (strcmp(a->path, b->path) ||
- (opt->ancestor != NULL && strcmp(a->path, o->path) != 0)) {
- base_name = opt->ancestor == NULL ? NULL :
- mkpathdup("%s:%s", opt->ancestor, o->path);
+ assert(a->path && b->path && o->path && opt->ancestor);
+ if (strcmp(a->path, b->path) || strcmp(a->path, o->path) != 0) {
+ base = mkpathdup("%s:%s", opt->ancestor, o->path);
name1 = mkpathdup("%s:%s", branch1, a->path);
name2 = mkpathdup("%s:%s", branch2, b->path);
} else {
- base_name = opt->ancestor == NULL ? NULL :
- mkpathdup("%s", opt->ancestor);
+ base = mkpathdup("%s", opt->ancestor);
name1 = mkpathdup("%s", branch1);
name2 = mkpathdup("%s", branch2);
}
@@ -1061,11 +1058,11 @@ static int merge_3way(struct merge_options *opt,
read_mmblob(&src1, &a->oid);
read_mmblob(&src2, &b->oid);
- merge_status = ll_merge(result_buf, a->path, &orig, base_name,
+ merge_status = ll_merge(result_buf, a->path, &orig, base,
&src1, name1, &src2, name2,
opt->repo->index, &ll_opts);
- free(base_name);
+ free(base);
free(name1);
free(name2);
free(orig.ptr);
@@ -3390,6 +3387,8 @@ int merge_trees(struct merge_options *opt,
int code, clean;
struct strbuf sb = STRBUF_INIT;
+ assert(opt->ancestor != NULL);
+
if (!opt->call_depth && repo_index_has_changes(opt->repo, head, &sb)) {
err(opt, _("Your local changes to the following files would be overwritten by merge:\n %s"),
sb.buf);