Merge branch 'en/merge-cleanup'
Code clean-up. * en/merge-cleanup: merge-recursive: rename merge_file_1() and merge_content() merge-recursive: remove final remaining caller of merge_file_one() merge-recursive: avoid wrapper function when unnecessary and wasteful merge-recursive: set paths correctly when three-way merging content
This commit is contained in:
commit
74bb46354f
@ -1274,14 +1274,14 @@ static int merge_submodule(struct merge_options *o,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int merge_file_1(struct merge_options *o,
|
static int merge_mode_and_contents(struct merge_options *o,
|
||||||
const struct diff_filespec *one,
|
const struct diff_filespec *one,
|
||||||
const struct diff_filespec *a,
|
const struct diff_filespec *a,
|
||||||
const struct diff_filespec *b,
|
const struct diff_filespec *b,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
const char *branch1,
|
const char *branch1,
|
||||||
const char *branch2,
|
const char *branch2,
|
||||||
struct merge_file_info *result)
|
struct merge_file_info *result)
|
||||||
{
|
{
|
||||||
result->merge = 0;
|
result->merge = 0;
|
||||||
result->clean = 1;
|
result->clean = 1;
|
||||||
@ -1366,56 +1366,6 @@ static int merge_file_1(struct merge_options *o,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int merge_file_special_markers(struct merge_options *o,
|
|
||||||
const struct diff_filespec *one,
|
|
||||||
const struct diff_filespec *a,
|
|
||||||
const struct diff_filespec *b,
|
|
||||||
const char *target_filename,
|
|
||||||
const char *branch1,
|
|
||||||
const char *filename1,
|
|
||||||
const char *branch2,
|
|
||||||
const char *filename2,
|
|
||||||
struct merge_file_info *mfi)
|
|
||||||
{
|
|
||||||
char *side1 = NULL;
|
|
||||||
char *side2 = NULL;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (filename1)
|
|
||||||
side1 = xstrfmt("%s:%s", branch1, filename1);
|
|
||||||
if (filename2)
|
|
||||||
side2 = xstrfmt("%s:%s", branch2, filename2);
|
|
||||||
|
|
||||||
ret = merge_file_1(o, one, a, b, target_filename,
|
|
||||||
side1 ? side1 : branch1,
|
|
||||||
side2 ? side2 : branch2, mfi);
|
|
||||||
|
|
||||||
free(side1);
|
|
||||||
free(side2);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int merge_file_one(struct merge_options *o,
|
|
||||||
const char *path,
|
|
||||||
const struct object_id *o_oid, int o_mode,
|
|
||||||
const struct object_id *a_oid, int a_mode,
|
|
||||||
const struct object_id *b_oid, int b_mode,
|
|
||||||
const char *branch1,
|
|
||||||
const char *branch2,
|
|
||||||
struct merge_file_info *mfi)
|
|
||||||
{
|
|
||||||
struct diff_filespec one, a, b;
|
|
||||||
|
|
||||||
one.path = a.path = b.path = (char *)path;
|
|
||||||
oidcpy(&one.oid, o_oid);
|
|
||||||
one.mode = o_mode;
|
|
||||||
oidcpy(&a.oid, a_oid);
|
|
||||||
a.mode = a_mode;
|
|
||||||
oidcpy(&b.oid, b_oid);
|
|
||||||
b.mode = b_mode;
|
|
||||||
return merge_file_1(o, &one, &a, &b, path, branch1, branch2, mfi);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int handle_rename_via_dir(struct merge_options *o,
|
static int handle_rename_via_dir(struct merge_options *o,
|
||||||
struct diff_filepair *pair,
|
struct diff_filepair *pair,
|
||||||
const char *rename_branch,
|
const char *rename_branch,
|
||||||
@ -1659,11 +1609,8 @@ static int handle_rename_rename_1to2(struct merge_options *o,
|
|||||||
struct merge_file_info mfi;
|
struct merge_file_info mfi;
|
||||||
struct diff_filespec other;
|
struct diff_filespec other;
|
||||||
struct diff_filespec *add;
|
struct diff_filespec *add;
|
||||||
if (merge_file_one(o, one->path,
|
if (merge_mode_and_contents(o, one, a, b, one->path,
|
||||||
&one->oid, one->mode,
|
ci->branch1, ci->branch2, &mfi))
|
||||||
&a->oid, a->mode,
|
|
||||||
&b->oid, b->mode,
|
|
||||||
ci->branch1, ci->branch2, &mfi))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1729,14 +1676,10 @@ static int handle_rename_rename_2to1(struct merge_options *o,
|
|||||||
|
|
||||||
path_side_1_desc = xstrfmt("%s (was %s)", path, a->path);
|
path_side_1_desc = xstrfmt("%s (was %s)", path, a->path);
|
||||||
path_side_2_desc = xstrfmt("%s (was %s)", path, b->path);
|
path_side_2_desc = xstrfmt("%s (was %s)", path, b->path);
|
||||||
if (merge_file_special_markers(o, a, c1, &ci->ren1_other,
|
if (merge_mode_and_contents(o, a, c1, &ci->ren1_other, path_side_1_desc,
|
||||||
path_side_1_desc,
|
o->branch1, o->branch2, &mfi_c1) ||
|
||||||
o->branch1, c1->path,
|
merge_mode_and_contents(o, b, &ci->ren2_other, c2, path_side_2_desc,
|
||||||
o->branch2, ci->ren1_other.path, &mfi_c1) ||
|
o->branch1, o->branch2, &mfi_c2))
|
||||||
merge_file_special_markers(o, b, &ci->ren2_other, c2,
|
|
||||||
path_side_2_desc,
|
|
||||||
o->branch1, ci->ren2_other.path,
|
|
||||||
o->branch2, c2->path, &mfi_c2))
|
|
||||||
return -1;
|
return -1;
|
||||||
free(path_side_1_desc);
|
free(path_side_1_desc);
|
||||||
free(path_side_2_desc);
|
free(path_side_2_desc);
|
||||||
@ -2766,12 +2709,23 @@ static int process_renames(struct merge_options *o,
|
|||||||
ren1_dst, branch2);
|
ren1_dst, branch2);
|
||||||
if (o->call_depth) {
|
if (o->call_depth) {
|
||||||
struct merge_file_info mfi;
|
struct merge_file_info mfi;
|
||||||
if (merge_file_one(o, ren1_dst, &null_oid, 0,
|
struct diff_filespec one, a, b;
|
||||||
&ren1->pair->two->oid,
|
|
||||||
ren1->pair->two->mode,
|
oidcpy(&one.oid, &null_oid);
|
||||||
&dst_other.oid,
|
one.mode = 0;
|
||||||
dst_other.mode,
|
one.path = ren1->pair->two->path;
|
||||||
branch1, branch2, &mfi)) {
|
|
||||||
|
oidcpy(&a.oid, &ren1->pair->two->oid);
|
||||||
|
a.mode = ren1->pair->two->mode;
|
||||||
|
a.path = one.path;
|
||||||
|
|
||||||
|
oidcpy(&b.oid, &dst_other.oid);
|
||||||
|
b.mode = dst_other.mode;
|
||||||
|
b.path = one.path;
|
||||||
|
|
||||||
|
if (merge_mode_and_contents(o, &one, &a, &b, ren1_dst,
|
||||||
|
branch1, branch2,
|
||||||
|
&mfi)) {
|
||||||
clean_merge = -1;
|
clean_merge = -1;
|
||||||
goto cleanup_and_return;
|
goto cleanup_and_return;
|
||||||
}
|
}
|
||||||
@ -3021,13 +2975,13 @@ static int handle_modify_delete(struct merge_options *o,
|
|||||||
_("modify"), _("modified"));
|
_("modify"), _("modified"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int merge_content(struct merge_options *o,
|
static int handle_content_merge(struct merge_options *o,
|
||||||
const char *path,
|
const char *path,
|
||||||
int is_dirty,
|
int is_dirty,
|
||||||
struct object_id *o_oid, int o_mode,
|
struct object_id *o_oid, int o_mode,
|
||||||
struct object_id *a_oid, int a_mode,
|
struct object_id *a_oid, int a_mode,
|
||||||
struct object_id *b_oid, int b_mode,
|
struct object_id *b_oid, int b_mode,
|
||||||
struct rename_conflict_info *rename_conflict_info)
|
struct rename_conflict_info *rename_conflict_info)
|
||||||
{
|
{
|
||||||
const char *reason = _("content");
|
const char *reason = _("content");
|
||||||
const char *path1 = NULL, *path2 = NULL;
|
const char *path1 = NULL, *path2 = NULL;
|
||||||
@ -3059,14 +3013,16 @@ static int merge_content(struct merge_options *o,
|
|||||||
path2 = (rename_conflict_info->pair2 ||
|
path2 = (rename_conflict_info->pair2 ||
|
||||||
o->branch2 == rename_conflict_info->branch1) ?
|
o->branch2 == rename_conflict_info->branch1) ?
|
||||||
pair1->two->path : pair1->one->path;
|
pair1->two->path : pair1->one->path;
|
||||||
|
one.path = pair1->one->path;
|
||||||
|
a.path = (char *)path1;
|
||||||
|
b.path = (char *)path2;
|
||||||
|
|
||||||
if (dir_in_way(path, !o->call_depth,
|
if (dir_in_way(path, !o->call_depth,
|
||||||
S_ISGITLINK(pair1->two->mode)))
|
S_ISGITLINK(pair1->two->mode)))
|
||||||
df_conflict_remains = 1;
|
df_conflict_remains = 1;
|
||||||
}
|
}
|
||||||
if (merge_file_special_markers(o, &one, &a, &b, path,
|
if (merge_mode_and_contents(o, &one, &a, &b, path,
|
||||||
o->branch1, path1,
|
o->branch1, o->branch2, &mfi))
|
||||||
o->branch2, path2, &mfi))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3157,9 +3113,9 @@ static int handle_rename_normal(struct merge_options *o,
|
|||||||
struct rename_conflict_info *ci)
|
struct rename_conflict_info *ci)
|
||||||
{
|
{
|
||||||
/* Merge the content and write it out */
|
/* Merge the content and write it out */
|
||||||
return merge_content(o, path, was_dirty(o, path),
|
return handle_content_merge(o, path, was_dirty(o, path),
|
||||||
o_oid, o_mode, a_oid, a_mode, b_oid, b_mode,
|
o_oid, o_mode, a_oid, a_mode, b_oid, b_mode,
|
||||||
ci);
|
ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Per entry merge function */
|
/* Per entry merge function */
|
||||||
@ -3283,9 +3239,11 @@ static int process_entry(struct merge_options *o,
|
|||||||
/* Case C: Added in both (check for same permissions) and */
|
/* Case C: Added in both (check for same permissions) and */
|
||||||
/* case D: Modified in both, but differently. */
|
/* case D: Modified in both, but differently. */
|
||||||
int is_dirty = 0; /* unpack_trees would have bailed if dirty */
|
int is_dirty = 0; /* unpack_trees would have bailed if dirty */
|
||||||
clean_merge = merge_content(o, path, is_dirty,
|
clean_merge = handle_content_merge(o, path, is_dirty,
|
||||||
o_oid, o_mode, a_oid, a_mode, b_oid, b_mode,
|
o_oid, o_mode,
|
||||||
NULL);
|
a_oid, a_mode,
|
||||||
|
b_oid, b_mode,
|
||||||
|
NULL);
|
||||||
} else if (!o_oid && !a_oid && !b_oid) {
|
} else if (!o_oid && !a_oid && !b_oid) {
|
||||||
/*
|
/*
|
||||||
* this entry was deleted altogether. a_mode == 0 means
|
* this entry was deleted altogether. a_mode == 0 means
|
||||||
|
Loading…
Reference in New Issue
Block a user