merge-recursive: introduce an enum for detect_directory_renames values

Improve code readability by introducing an enum to replace the not-quite-boolean values taken on by detect_directory_renames. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Aug 17, 2019 at 11:41 UTC 8e01251694fa277df53e5c52c137f0b4134d2cd5
3 files changed +21 -11
builtin/am.c
+1 -1
@@ -1538,7 +1538,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
1538 o.branch1 = "HEAD";
1539 their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
1540 o.branch2 = their_tree_name;
1541 - o.detect_directory_renames = 0;
1541 + o.detect_directory_renames = MERGE_DIRECTORY_RENAMES_NONE;
1542
1543 if (state->quiet)
1544 o.verbosity = 0;
merge-recursive.c
+15 -9
@@ -1375,7 +1375,8 @@ static int handle_rename_via_dir(struct merge_options *opt,
1375 const struct rename *ren = ci->ren1;
1376 const struct diff_filespec *dest = ren->pair->two;
1377 char *file_path = dest->path;
1378 - int mark_conflicted = (opt->detect_directory_renames == 1);
1378 + int mark_conflicted = (opt->detect_directory_renames ==
1379 + MERGE_DIRECTORY_RENAMES_CONFLICT);
1380 assert(ren->dir_rename_original_dest);
1381
1382 if (!opt->call_depth && would_lose_untracked(opt, dest->path)) {
@@ -2860,8 +2861,9 @@ static int detect_and_process_renames(struct merge_options *opt,
2861 head_pairs = get_diffpairs(opt, common, head);
2862 merge_pairs = get_diffpairs(opt, common, merge);
2863
2863 - if ((opt->detect_directory_renames == 2) ||
2864 - (opt->detect_directory_renames == 1 && !opt->call_depth)) {
2864 + if ((opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_TRUE) ||
2865 + (opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_CONFLICT &&
2866 + !opt->call_depth)) {
2867 dir_re_head = get_directory_renames(head_pairs);
2868 dir_re_merge = get_directory_renames(merge_pairs);
2869
@@ -3119,7 +3121,8 @@ static int handle_rename_normal(struct merge_options *opt,
3121 clean = handle_content_merge(&mfi, opt, path, was_dirty(opt, path),
3122 o, a, b, ci);
3123
3122 - if (clean && opt->detect_directory_renames == 1 &&
3124 + if (clean &&
3125 + opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_CONFLICT &&
3126 ren->dir_rename_original_dest) {
3127 if (update_stages(opt, path,
3128 NULL,
@@ -3164,12 +3167,12 @@ static int warn_about_dir_renamed_entries(struct merge_options *opt,
3167 return clean;
3168
3169 /* Sanity checks */
3167 - assert(opt->detect_directory_renames > 0);
3170 + assert(opt->detect_directory_renames > MERGE_DIRECTORY_RENAMES_NONE);
3171 assert(ren->dir_rename_original_type == 'A' ||
3172 ren->dir_rename_original_type == 'R');
3173
3174 /* Check whether to treat directory renames as a conflict */
3172 - clean = (opt->detect_directory_renames == 2);
3175 + clean = (opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_TRUE);
3176
3177 is_add = (ren->dir_rename_original_type == 'A');
3178 if (ren->dir_rename_original_type == 'A' && clean) {
@@ -3679,9 +3682,12 @@ static void merge_recursive_config(struct merge_options *opt)
3682 if (!git_config_get_string("merge.directoryrenames", &value)) {
3683 int boolval = git_parse_maybe_bool(value);
3684 if (0 <= boolval) {
3682 - opt->detect_directory_renames = boolval ? 2 : 0;
3685 + opt->detect_directory_renames = boolval ?
3686 + MERGE_DIRECTORY_RENAMES_TRUE :
3687 + MERGE_DIRECTORY_RENAMES_NONE;
3688 } else if (!strcasecmp(value, "conflict")) {
3684 - opt->detect_directory_renames = 1;
3689 + opt->detect_directory_renames =
3690 + MERGE_DIRECTORY_RENAMES_CONFLICT;
3691 } /* avoid erroring on values from future versions of git */
3692 free(value);
3693 }
@@ -3701,7 +3707,7 @@ void init_merge_options(struct merge_options *opt,
3707 opt->renormalize = 0;
3708 opt->diff_detect_rename = -1;
3709 opt->merge_detect_rename = -1;
3704 - opt->detect_directory_renames = 1;
3710 + opt->detect_directory_renames = MERGE_DIRECTORY_RENAMES_CONFLICT;
3711 merge_recursive_config(opt);
3712 merge_verbosity = getenv("GIT_MERGE_VERBOSITY");
3713 if (merge_verbosity)
merge-recursive.h
+5 -1
@@ -22,7 +22,11 @@ struct merge_options {
22 unsigned renormalize : 1;
23 long xdl_opts;
24 int verbosity;
25 - int detect_directory_renames;
25 + enum {
26 + MERGE_DIRECTORY_RENAMES_NONE = 0,
27 + MERGE_DIRECTORY_RENAMES_CONFLICT = 1,
28 + MERGE_DIRECTORY_RENAMES_TRUE = 2
29 + } detect_directory_renames;
30 int diff_detect_rename;
31 int merge_detect_rename;
32 int diff_rename_limit;