merge-recursive: move some definitions around to clean up the header

No substantive code changes (view this with diff --color-moved), but a few small code cleanups: * Move structs and an inline function only used by merge-recursive.c into merge-recursive.c * Re-order function declarations to be more logical * Add or fix some explanatory comments Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Aug 17, 2019 at 11:41 UTC 7c0a6c8e477bd9009001590f49274e892e92fce8
2 files changed +73 -45
merge-recursive.c
+31
@@ -54,6 +54,24 @@ static unsigned int path_hash(const char *path)
54 return ignore_case ? strihash(path) : strhash(path);
55 }
56
57 +/*
58 + * For dir_rename_entry, directory names are stored as a full path from the
59 + * toplevel of the repository and do not include a trailing '/'. Also:
60 + *
61 + * dir: original name of directory being renamed
62 + * non_unique_new_dir: if true, could not determine new_dir
63 + * new_dir: final name of directory being renamed
64 + * possible_new_dirs: temporary used to help determine new_dir; see comments
65 + * in get_directory_renames() for details
66 + */
67 +struct dir_rename_entry {
68 + struct hashmap_entry ent; /* must be the first member! */
69 + char *dir;
70 + unsigned non_unique_new_dir:1;
71 + struct strbuf new_dir;
72 + struct string_list possible_new_dirs;
73 +};
74 +
75 static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
76 char *dir)
77 {
@@ -92,6 +110,13 @@ static void dir_rename_entry_init(struct dir_rename_entry *entry,
110 string_list_init(&entry->possible_new_dirs, 0);
111 }
112
113 +struct collision_entry {
114 + struct hashmap_entry ent; /* must be the first member! */
115 + char *target_file;
116 + struct string_list source_files;
117 + unsigned reported_already:1;
118 +};
119 +
120 static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
121 char *target_file)
122 {
@@ -358,6 +383,12 @@ static int add_cacheinfo(struct merge_options *opt,
383 return ret;
384 }
385
386 +static inline int merge_detect_rename(struct merge_options *opt)
387 +{
388 + return opt->merge_detect_rename >= 0 ? opt->merge_detect_rename :
389 + opt->diff_detect_rename >= 0 ? opt->diff_detect_rename : 1;
390 +}
391 +
392 static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
393 {
394 parse_tree(tree);
merge-recursive.h
+42 -45
@@ -43,47 +43,50 @@ struct merge_options {
43 struct repository *repo;
44 };
45
46 +void init_merge_options(struct merge_options *opt, struct repository *repo);
47 +
48 +/* parse the option in s and update the relevant field of opt */
49 +int parse_merge_opt(struct merge_options *opt, const char *s);
50 +
51 /*
47 - * For dir_rename_entry, directory names are stored as a full path from the
48 - * toplevel of the repository and do not include a trailing '/'. Also:
49 - *
50 - * dir: original name of directory being renamed
51 - * non_unique_new_dir: if true, could not determine new_dir
52 - * new_dir: final name of directory being renamed
53 - * possible_new_dirs: temporary used to help determine new_dir; see comments
54 - * in get_directory_renames() for details
52 + * RETURN VALUES: All the merge_* functions below return a value as follows:
53 + * > 0 Merge was clean
54 + * = 0 Merge had conflicts
55 + * < 0 Merge hit an unexpected and unrecoverable problem (e.g. disk
56 + * full) and aborted merge part-way through.
57 */
56 -struct dir_rename_entry {
57 - struct hashmap_entry ent; /* must be the first member! */
58 - char *dir;
59 - unsigned non_unique_new_dir:1;
60 - struct strbuf new_dir;
61 - struct string_list possible_new_dirs;
62 -};
63 -
64 -struct collision_entry {
65 - struct hashmap_entry ent; /* must be the first member! */
66 - char *target_file;
67 - struct string_list source_files;
68 - unsigned reported_already:1;
69 -};
58
71 -static inline int merge_detect_rename(struct merge_options *opt)
72 -{
73 - return opt->merge_detect_rename >= 0 ? opt->merge_detect_rename :
74 - opt->diff_detect_rename >= 0 ? opt->diff_detect_rename : 1;
75 -}
59 +/*
60 + * rename-detecting three-way merge, no recursion.
61 + *
62 + * Outputs:
63 + * - See RETURN VALUES above
64 + * - No commit is created
65 + * - opt->repo->index has the new index
66 + * - $GIT_INDEX_FILE is not updated
67 + * - The working tree is updated with results of the merge
68 + */
69 +int merge_trees(struct merge_options *opt,
70 + struct tree *head,
71 + struct tree *merge,
72 + struct tree *merge_base);
73
74 /*
75 * merge_recursive is like merge_trees() but with recursive ancestor
79 - * consolidation, and when successful, it creates an actual commit
80 - * and writes its address to *result.
76 + * consolidation and, if the commit is clean, creation of a commit.
77 *
78 * NOTE: empirically, about a decade ago it was determined that with more
79 * than two merge bases, optimal behavior was found when the
80 * merge_bases were passed in the order of oldest commit to newest
81 * commit. Also, merge_bases will be consumed (emptied) so make a
82 * copy if you need it.
83 + *
84 + * Outputs:
85 + * - See RETURN VALUES above
86 + * - If merge is clean, a commit is created and its address written to *result
87 + * - opt->repo->index has the new index
88 + * - $GIT_INDEX_FILE is not updated
89 + * - The working tree is updated with results of the merge
90 */
91 int merge_recursive(struct merge_options *opt,
92 struct commit *h1,
@@ -92,17 +95,16 @@ int merge_recursive(struct merge_options *opt,
95 struct commit **result);
96
97 /*
95 - * rename-detecting three-way merge, no recursion; result of merge is written
96 - * to opt->repo->index.
97 - */
98 -int merge_trees(struct merge_options *opt,
99 - struct tree *head,
100 - struct tree *merge,
101 - struct tree *merge_base);
102 -
103 -/*
104 - * "git-merge-recursive" can be fed trees; wrap them into
105 - * virtual commits and call merge_recursive() proper.
98 + * merge_recursive_generic can operate on trees instead of commits, by
99 + * wrapping the trees into virtual commits, and calling merge_recursive().
100 + * It also writes out the in-memory index to disk if the merge is successful.
101 + *
102 + * Outputs:
103 + * - See RETURN VALUES above
104 + * - If merge is clean, a commit is created and its address written to *result
105 + * - opt->repo->index has the new index
106 + * - $GIT_INDEX_FILE is updated
107 + * - The working tree is updated with results of the merge
108 */
109 int merge_recursive_generic(struct merge_options *opt,
110 const struct object_id *head,
@@ -111,9 +113,4 @@ int merge_recursive_generic(struct merge_options *opt,
113 const struct object_id **merge_bases,
114 struct commit **result);
115
114 -void init_merge_options(struct merge_options *opt,
115 - struct repository *repo);
116 -
117 -int parse_merge_opt(struct merge_options *opt, const char *s);
118 -
116 #endif