Skip to content

Commit 7c0a6c8

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c749ab1 commit 7c0a6c8

File tree

2 files changed

+73
-45
lines changed

2 files changed

+73
-45
lines changed

merge-recursive.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ static unsigned int path_hash(const char *path)
5454
return ignore_case ? strihash(path) : strhash(path);
5555
}
5656

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+
5775
static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
5876
char *dir)
5977
{
@@ -92,6 +110,13 @@ static void dir_rename_entry_init(struct dir_rename_entry *entry,
92110
string_list_init(&entry->possible_new_dirs, 0);
93111
}
94112

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+
95120
static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
96121
char *target_file)
97122
{
@@ -358,6 +383,12 @@ static int add_cacheinfo(struct merge_options *opt,
358383
return ret;
359384
}
360385

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+
361392
static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
362393
{
363394
parse_tree(tree);

merge-recursive.h

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,47 +43,50 @@ struct merge_options {
4343
struct repository *repo;
4444
};
4545

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+
4651
/*
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.
5557
*/
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-
};
7058

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);
7673

7774
/*
7875
* 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.
8177
*
8278
* NOTE: empirically, about a decade ago it was determined that with more
8379
* than two merge bases, optimal behavior was found when the
8480
* merge_bases were passed in the order of oldest commit to newest
8581
* commit. Also, merge_bases will be consumed (emptied) so make a
8682
* 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
8790
*/
8891
int merge_recursive(struct merge_options *opt,
8992
struct commit *h1,
@@ -92,17 +95,16 @@ int merge_recursive(struct merge_options *opt,
9295
struct commit **result);
9396

9497
/*
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
106108
*/
107109
int merge_recursive_generic(struct merge_options *opt,
108110
const struct object_id *head,
@@ -111,9 +113,4 @@ int merge_recursive_generic(struct merge_options *opt,
111113
const struct object_id **merge_bases,
112114
struct commit **result);
113115

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-
119116
#endif

0 commit comments

Comments
 (0)