Merge branch 'en/merge-recursive-cleanup'
Code cleanup. * en/merge-recursive-cleanup: merge-recursive: add pointer about unduly complex looking code merge-recursive: rename conflict_rename_*() family of functions merge-recursive: clarify the rename_dir/RENAME_DIR meaning merge-recursive: align labels with their respective code blocks merge-recursive: fix numerous argument alignment issues merge-recursive: fix miscellaneous grammar error in commentmaint
commit
473b8bb3aa
|
@ -182,7 +182,7 @@ static int oid_eq(const struct object_id *a, const struct object_id *b)
|
||||||
|
|
||||||
enum rename_type {
|
enum rename_type {
|
||||||
RENAME_NORMAL = 0,
|
RENAME_NORMAL = 0,
|
||||||
RENAME_DIR,
|
RENAME_VIA_DIR,
|
||||||
RENAME_DELETE,
|
RENAME_DELETE,
|
||||||
RENAME_ONE_FILE_TO_ONE,
|
RENAME_ONE_FILE_TO_ONE,
|
||||||
RENAME_ONE_FILE_TO_TWO,
|
RENAME_ONE_FILE_TO_TWO,
|
||||||
|
@ -542,7 +542,7 @@ static void record_df_conflict_files(struct merge_options *o,
|
||||||
struct string_list *entries)
|
struct string_list *entries)
|
||||||
{
|
{
|
||||||
/* If there is a D/F conflict and the file for such a conflict
|
/* If there is a D/F conflict and the file for such a conflict
|
||||||
* currently exist in the working tree, we want to allow it to be
|
* currently exists in the working tree, we want to allow it to be
|
||||||
* removed to make room for the corresponding directory if needed.
|
* removed to make room for the corresponding directory if needed.
|
||||||
* The files underneath the directories of such D/F conflicts will
|
* The files underneath the directories of such D/F conflicts will
|
||||||
* be processed before the corresponding file involved in the D/F
|
* be processed before the corresponding file involved in the D/F
|
||||||
|
@ -1413,11 +1413,17 @@ static int merge_file_one(struct merge_options *o,
|
||||||
return merge_file_1(o, &one, &a, &b, path, branch1, branch2, mfi);
|
return merge_file_1(o, &one, &a, &b, path, branch1, branch2, mfi);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int conflict_rename_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,
|
||||||
const char *other_branch)
|
const char *other_branch)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Handle file adds that need to be renamed due to directory rename
|
||||||
|
* detection. This differs from handle_rename_normal, because
|
||||||
|
* there is no content merge to do; just move the file into the
|
||||||
|
* desired final location.
|
||||||
|
*/
|
||||||
const struct diff_filespec *dest = pair->two;
|
const struct diff_filespec *dest = pair->two;
|
||||||
|
|
||||||
if (!o->call_depth && would_lose_untracked(dest->path)) {
|
if (!o->call_depth && would_lose_untracked(dest->path)) {
|
||||||
|
@ -1473,6 +1479,21 @@ static int handle_change_delete(struct merge_options *o,
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = update_file(o, 0, o_oid, o_mode, update_path);
|
ret = update_file(o, 0, o_oid, o_mode, update_path);
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
|
* Despite the four nearly duplicate messages and argument
|
||||||
|
* lists below and the ugliness of the nested if-statements,
|
||||||
|
* having complete messages makes the job easier for
|
||||||
|
* translators.
|
||||||
|
*
|
||||||
|
* The slight variance among the cases is due to the fact
|
||||||
|
* that:
|
||||||
|
* 1) directory/file conflicts (in effect if
|
||||||
|
* !alt_path) could cause us to need to write the
|
||||||
|
* file to a different path.
|
||||||
|
* 2) renames (in effect if !old_path) could mean that
|
||||||
|
* there are two names for the path that the user
|
||||||
|
* may know the file by.
|
||||||
|
*/
|
||||||
if (!alt_path) {
|
if (!alt_path) {
|
||||||
if (!old_path) {
|
if (!old_path) {
|
||||||
output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
|
output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
|
||||||
|
@ -1512,7 +1533,7 @@ static int handle_change_delete(struct merge_options *o,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int conflict_rename_delete(struct merge_options *o,
|
static int handle_rename_delete(struct merge_options *o,
|
||||||
struct diff_filepair *pair,
|
struct diff_filepair *pair,
|
||||||
const char *rename_branch,
|
const char *rename_branch,
|
||||||
const char *delete_branch)
|
const char *delete_branch)
|
||||||
|
@ -1617,7 +1638,7 @@ static int handle_file(struct merge_options *o,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int conflict_rename_rename_1to2(struct merge_options *o,
|
static int handle_rename_rename_1to2(struct merge_options *o,
|
||||||
struct rename_conflict_info *ci)
|
struct rename_conflict_info *ci)
|
||||||
{
|
{
|
||||||
/* One file was renamed in both branches, but to different names. */
|
/* One file was renamed in both branches, but to different names. */
|
||||||
|
@ -1679,7 +1700,7 @@ static int conflict_rename_rename_1to2(struct merge_options *o,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int conflict_rename_rename_2to1(struct merge_options *o,
|
static int handle_rename_rename_2to1(struct merge_options *o,
|
||||||
struct rename_conflict_info *ci)
|
struct rename_conflict_info *ci)
|
||||||
{
|
{
|
||||||
/* Two files, a & b, were renamed to the same thing, c. */
|
/* Two files, a & b, were renamed to the same thing, c. */
|
||||||
|
@ -2422,7 +2443,7 @@ static void apply_directory_rename_modifications(struct merge_options *o,
|
||||||
* "NOTE" in update_stages(), doing so will modify the current
|
* "NOTE" in update_stages(), doing so will modify the current
|
||||||
* in-memory index which will break calls to would_lose_untracked()
|
* in-memory index which will break calls to would_lose_untracked()
|
||||||
* that we need to make. Instead, we need to just make sure that
|
* that we need to make. Instead, we need to just make sure that
|
||||||
* the various conflict_rename_*() functions update the index
|
* the various handle_rename_*() functions update the index
|
||||||
* explicitly rather than relying on unpack_trees() to have done it.
|
* explicitly rather than relying on unpack_trees() to have done it.
|
||||||
*/
|
*/
|
||||||
get_tree_entry(&tree->object.oid,
|
get_tree_entry(&tree->object.oid,
|
||||||
|
@ -2695,7 +2716,7 @@ static int process_renames(struct merge_options *o,
|
||||||
|
|
||||||
if (oid_eq(&src_other.oid, &null_oid) &&
|
if (oid_eq(&src_other.oid, &null_oid) &&
|
||||||
ren1->add_turned_into_rename) {
|
ren1->add_turned_into_rename) {
|
||||||
setup_rename_conflict_info(RENAME_DIR,
|
setup_rename_conflict_info(RENAME_VIA_DIR,
|
||||||
ren1->pair,
|
ren1->pair,
|
||||||
NULL,
|
NULL,
|
||||||
branch1,
|
branch1,
|
||||||
|
@ -2826,7 +2847,7 @@ static void initial_cleanup_rename(struct diff_queue_struct *pairs,
|
||||||
free(pairs);
|
free(pairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_renames(struct merge_options *o,
|
static int detect_and_process_renames(struct merge_options *o,
|
||||||
struct tree *common,
|
struct tree *common,
|
||||||
struct tree *head,
|
struct tree *head,
|
||||||
struct tree *merge,
|
struct tree *merge,
|
||||||
|
@ -2907,7 +2928,8 @@ static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_oid_strbuf(struct merge_options *o,
|
static int read_oid_strbuf(struct merge_options *o,
|
||||||
const struct object_id *oid, struct strbuf *dst)
|
const struct object_id *oid,
|
||||||
|
struct strbuf *dst)
|
||||||
{
|
{
|
||||||
void *buf;
|
void *buf;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
|
@ -3101,7 +3123,7 @@ static int merge_content(struct merge_options *o,
|
||||||
return !is_dirty && mfi.clean;
|
return !is_dirty && mfi.clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int conflict_rename_normal(struct merge_options *o,
|
static int handle_rename_normal(struct merge_options *o,
|
||||||
const char *path,
|
const char *path,
|
||||||
struct object_id *o_oid, unsigned int o_mode,
|
struct object_id *o_oid, unsigned int o_mode,
|
||||||
struct object_id *a_oid, unsigned int a_mode,
|
struct object_id *a_oid, unsigned int a_mode,
|
||||||
|
@ -3133,16 +3155,16 @@ static int process_entry(struct merge_options *o,
|
||||||
switch (conflict_info->rename_type) {
|
switch (conflict_info->rename_type) {
|
||||||
case RENAME_NORMAL:
|
case RENAME_NORMAL:
|
||||||
case RENAME_ONE_FILE_TO_ONE:
|
case RENAME_ONE_FILE_TO_ONE:
|
||||||
clean_merge = conflict_rename_normal(o,
|
clean_merge = handle_rename_normal(o,
|
||||||
path,
|
path,
|
||||||
o_oid, o_mode,
|
o_oid, o_mode,
|
||||||
a_oid, a_mode,
|
a_oid, a_mode,
|
||||||
b_oid, b_mode,
|
b_oid, b_mode,
|
||||||
conflict_info);
|
conflict_info);
|
||||||
break;
|
break;
|
||||||
case RENAME_DIR:
|
case RENAME_VIA_DIR:
|
||||||
clean_merge = 1;
|
clean_merge = 1;
|
||||||
if (conflict_rename_dir(o,
|
if (handle_rename_via_dir(o,
|
||||||
conflict_info->pair1,
|
conflict_info->pair1,
|
||||||
conflict_info->branch1,
|
conflict_info->branch1,
|
||||||
conflict_info->branch2))
|
conflict_info->branch2))
|
||||||
|
@ -3150,7 +3172,7 @@ static int process_entry(struct merge_options *o,
|
||||||
break;
|
break;
|
||||||
case RENAME_DELETE:
|
case RENAME_DELETE:
|
||||||
clean_merge = 0;
|
clean_merge = 0;
|
||||||
if (conflict_rename_delete(o,
|
if (handle_rename_delete(o,
|
||||||
conflict_info->pair1,
|
conflict_info->pair1,
|
||||||
conflict_info->branch1,
|
conflict_info->branch1,
|
||||||
conflict_info->branch2))
|
conflict_info->branch2))
|
||||||
|
@ -3158,12 +3180,12 @@ static int process_entry(struct merge_options *o,
|
||||||
break;
|
break;
|
||||||
case RENAME_ONE_FILE_TO_TWO:
|
case RENAME_ONE_FILE_TO_TWO:
|
||||||
clean_merge = 0;
|
clean_merge = 0;
|
||||||
if (conflict_rename_rename_1to2(o, conflict_info))
|
if (handle_rename_rename_1to2(o, conflict_info))
|
||||||
clean_merge = -1;
|
clean_merge = -1;
|
||||||
break;
|
break;
|
||||||
case RENAME_TWO_FILES_TO_ONE:
|
case RENAME_TWO_FILES_TO_ONE:
|
||||||
clean_merge = 0;
|
clean_merge = 0;
|
||||||
if (conflict_rename_rename_2to1(o, conflict_info))
|
if (handle_rename_rename_2to1(o, conflict_info))
|
||||||
clean_merge = -1;
|
clean_merge = -1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -3303,8 +3325,8 @@ int merge_trees(struct merge_options *o,
|
||||||
get_files_dirs(o, merge);
|
get_files_dirs(o, merge);
|
||||||
|
|
||||||
entries = get_unmerged();
|
entries = get_unmerged();
|
||||||
clean = handle_renames(o, common, head, merge, entries,
|
clean = detect_and_process_renames(o, common, head, merge,
|
||||||
&re_info);
|
entries, &re_info);
|
||||||
record_df_conflict_files(o, entries);
|
record_df_conflict_files(o, entries);
|
||||||
if (clean < 0)
|
if (clean < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
Loading…
Reference in New Issue