]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-recursive: introduce an enum for detect_directory_renames values
authorDerrick Stolee <dstolee@microsoft.com>
Sat, 17 Aug 2019 18:41:25 +0000 (11:41 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Aug 2019 17:08:03 +0000 (10:08 -0700)
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>
builtin/am.c
merge-recursive.c
merge-recursive.h

index 1aea657a7f0b56345e1b2d5f8f32df439e278e80..037e828efe225e63e9650d3815f602f7a0aa613d 100644 (file)
@@ -1538,7 +1538,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
        o.branch1 = "HEAD";
        their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
        o.branch2 = their_tree_name;
-       o.detect_directory_renames = 0;
+       o.detect_directory_renames = MERGE_DIRECTORY_RENAMES_NONE;
 
        if (state->quiet)
                o.verbosity = 0;
index e6b84db2ef8eb5b9bdc1de66136c54b2848f23fa..962278161250733194a3033c330515f72ef88fd7 100644 (file)
@@ -1375,7 +1375,8 @@ static int handle_rename_via_dir(struct merge_options *opt,
        const struct rename *ren = ci->ren1;
        const struct diff_filespec *dest = ren->pair->two;
        char *file_path = dest->path;
-       int mark_conflicted = (opt->detect_directory_renames == 1);
+       int mark_conflicted = (opt->detect_directory_renames ==
+                              MERGE_DIRECTORY_RENAMES_CONFLICT);
        assert(ren->dir_rename_original_dest);
 
        if (!opt->call_depth && would_lose_untracked(opt, dest->path)) {
@@ -2860,8 +2861,9 @@ static int detect_and_process_renames(struct merge_options *opt,
        head_pairs = get_diffpairs(opt, common, head);
        merge_pairs = get_diffpairs(opt, common, merge);
 
-       if ((opt->detect_directory_renames == 2) ||
-           (opt->detect_directory_renames == 1 && !opt->call_depth)) {
+       if ((opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_TRUE) ||
+           (opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_CONFLICT &&
+            !opt->call_depth)) {
                dir_re_head = get_directory_renames(head_pairs);
                dir_re_merge = get_directory_renames(merge_pairs);
 
@@ -3119,7 +3121,8 @@ static int handle_rename_normal(struct merge_options *opt,
        clean = handle_content_merge(&mfi, opt, path, was_dirty(opt, path),
                                     o, a, b, ci);
 
-       if (clean && opt->detect_directory_renames == 1 &&
+       if (clean &&
+           opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_CONFLICT &&
            ren->dir_rename_original_dest) {
                if (update_stages(opt, path,
                                  NULL,
@@ -3164,12 +3167,12 @@ static int warn_about_dir_renamed_entries(struct merge_options *opt,
                return clean;
 
        /* Sanity checks */
-       assert(opt->detect_directory_renames > 0);
+       assert(opt->detect_directory_renames > MERGE_DIRECTORY_RENAMES_NONE);
        assert(ren->dir_rename_original_type == 'A' ||
               ren->dir_rename_original_type == 'R');
 
        /* Check whether to treat directory renames as a conflict */
-       clean = (opt->detect_directory_renames == 2);
+       clean = (opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_TRUE);
 
        is_add = (ren->dir_rename_original_type == 'A');
        if (ren->dir_rename_original_type == 'A' && clean) {
@@ -3679,9 +3682,12 @@ static void merge_recursive_config(struct merge_options *opt)
        if (!git_config_get_string("merge.directoryrenames", &value)) {
                int boolval = git_parse_maybe_bool(value);
                if (0 <= boolval) {
-                       opt->detect_directory_renames = boolval ? 2 : 0;
+                       opt->detect_directory_renames = boolval ?
+                               MERGE_DIRECTORY_RENAMES_TRUE :
+                               MERGE_DIRECTORY_RENAMES_NONE;
                } else if (!strcasecmp(value, "conflict")) {
-                       opt->detect_directory_renames = 1;
+                       opt->detect_directory_renames =
+                               MERGE_DIRECTORY_RENAMES_CONFLICT;
                } /* avoid erroring on values from future versions of git */
                free(value);
        }
@@ -3701,7 +3707,7 @@ void init_merge_options(struct merge_options *opt,
        opt->renormalize = 0;
        opt->diff_detect_rename = -1;
        opt->merge_detect_rename = -1;
-       opt->detect_directory_renames = 1;
+       opt->detect_directory_renames = MERGE_DIRECTORY_RENAMES_CONFLICT;
        merge_recursive_config(opt);
        merge_verbosity = getenv("GIT_MERGE_VERBOSITY");
        if (merge_verbosity)
index c2b7bb65c62ff51af1b89087bbf6692060b5962e..f1b6ef38ae1c91964beba094a50a9dd16a211cfc 100644 (file)
@@ -22,7 +22,11 @@ struct merge_options {
        unsigned renormalize : 1;
        long xdl_opts;
        int verbosity;
-       int detect_directory_renames;
+       enum {
+               MERGE_DIRECTORY_RENAMES_NONE = 0,
+               MERGE_DIRECTORY_RENAMES_CONFLICT = 1,
+               MERGE_DIRECTORY_RENAMES_TRUE = 2
+       } detect_directory_renames;
        int diff_detect_rename;
        int merge_detect_rename;
        int diff_rename_limit;