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>maint
parent
c749ab1da8
commit
7c0a6c8e47
|
@ -54,6 +54,24 @@ static unsigned int path_hash(const char *path)
|
||||||
return ignore_case ? strihash(path) : strhash(path);
|
return ignore_case ? strihash(path) : strhash(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For dir_rename_entry, directory names are stored as a full path from the
|
||||||
|
* toplevel of the repository and do not include a trailing '/'. Also:
|
||||||
|
*
|
||||||
|
* dir: original name of directory being renamed
|
||||||
|
* non_unique_new_dir: if true, could not determine new_dir
|
||||||
|
* new_dir: final name of directory being renamed
|
||||||
|
* possible_new_dirs: temporary used to help determine new_dir; see comments
|
||||||
|
* in get_directory_renames() for details
|
||||||
|
*/
|
||||||
|
struct dir_rename_entry {
|
||||||
|
struct hashmap_entry ent; /* must be the first member! */
|
||||||
|
char *dir;
|
||||||
|
unsigned non_unique_new_dir:1;
|
||||||
|
struct strbuf new_dir;
|
||||||
|
struct string_list possible_new_dirs;
|
||||||
|
};
|
||||||
|
|
||||||
static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
|
static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
|
||||||
char *dir)
|
char *dir)
|
||||||
{
|
{
|
||||||
|
@ -92,6 +110,13 @@ static void dir_rename_entry_init(struct dir_rename_entry *entry,
|
||||||
string_list_init(&entry->possible_new_dirs, 0);
|
string_list_init(&entry->possible_new_dirs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct collision_entry {
|
||||||
|
struct hashmap_entry ent; /* must be the first member! */
|
||||||
|
char *target_file;
|
||||||
|
struct string_list source_files;
|
||||||
|
unsigned reported_already:1;
|
||||||
|
};
|
||||||
|
|
||||||
static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
|
static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
|
||||||
char *target_file)
|
char *target_file)
|
||||||
{
|
{
|
||||||
|
@ -358,6 +383,12 @@ static int add_cacheinfo(struct merge_options *opt,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int merge_detect_rename(struct merge_options *opt)
|
||||||
|
{
|
||||||
|
return opt->merge_detect_rename >= 0 ? opt->merge_detect_rename :
|
||||||
|
opt->diff_detect_rename >= 0 ? opt->diff_detect_rename : 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
|
static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
|
||||||
{
|
{
|
||||||
parse_tree(tree);
|
parse_tree(tree);
|
||||||
|
|
|
@ -43,47 +43,50 @@ struct merge_options {
|
||||||
struct repository *repo;
|
struct repository *repo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void init_merge_options(struct merge_options *opt, struct repository *repo);
|
||||||
|
|
||||||
|
/* parse the option in s and update the relevant field of opt */
|
||||||
|
int parse_merge_opt(struct merge_options *opt, const char *s);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For dir_rename_entry, directory names are stored as a full path from the
|
* RETURN VALUES: All the merge_* functions below return a value as follows:
|
||||||
* toplevel of the repository and do not include a trailing '/'. Also:
|
* > 0 Merge was clean
|
||||||
*
|
* = 0 Merge had conflicts
|
||||||
* dir: original name of directory being renamed
|
* < 0 Merge hit an unexpected and unrecoverable problem (e.g. disk
|
||||||
* non_unique_new_dir: if true, could not determine new_dir
|
* full) and aborted merge part-way through.
|
||||||
* new_dir: final name of directory being renamed
|
|
||||||
* possible_new_dirs: temporary used to help determine new_dir; see comments
|
|
||||||
* in get_directory_renames() for details
|
|
||||||
*/
|
*/
|
||||||
struct dir_rename_entry {
|
|
||||||
struct hashmap_entry ent; /* must be the first member! */
|
|
||||||
char *dir;
|
|
||||||
unsigned non_unique_new_dir:1;
|
|
||||||
struct strbuf new_dir;
|
|
||||||
struct string_list possible_new_dirs;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct collision_entry {
|
/*
|
||||||
struct hashmap_entry ent; /* must be the first member! */
|
* rename-detecting three-way merge, no recursion.
|
||||||
char *target_file;
|
*
|
||||||
struct string_list source_files;
|
* Outputs:
|
||||||
unsigned reported_already:1;
|
* - See RETURN VALUES above
|
||||||
};
|
* - No commit is created
|
||||||
|
* - opt->repo->index has the new index
|
||||||
static inline int merge_detect_rename(struct merge_options *opt)
|
* - $GIT_INDEX_FILE is not updated
|
||||||
{
|
* - The working tree is updated with results of the merge
|
||||||
return opt->merge_detect_rename >= 0 ? opt->merge_detect_rename :
|
*/
|
||||||
opt->diff_detect_rename >= 0 ? opt->diff_detect_rename : 1;
|
int merge_trees(struct merge_options *opt,
|
||||||
}
|
struct tree *head,
|
||||||
|
struct tree *merge,
|
||||||
|
struct tree *merge_base);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* merge_recursive is like merge_trees() but with recursive ancestor
|
* merge_recursive is like merge_trees() but with recursive ancestor
|
||||||
* consolidation, and when successful, it creates an actual commit
|
* consolidation and, if the commit is clean, creation of a commit.
|
||||||
* and writes its address to *result.
|
|
||||||
*
|
*
|
||||||
* NOTE: empirically, about a decade ago it was determined that with more
|
* NOTE: empirically, about a decade ago it was determined that with more
|
||||||
* than two merge bases, optimal behavior was found when the
|
* than two merge bases, optimal behavior was found when the
|
||||||
* merge_bases were passed in the order of oldest commit to newest
|
* merge_bases were passed in the order of oldest commit to newest
|
||||||
* commit. Also, merge_bases will be consumed (emptied) so make a
|
* commit. Also, merge_bases will be consumed (emptied) so make a
|
||||||
* copy if you need it.
|
* copy if you need it.
|
||||||
|
*
|
||||||
|
* Outputs:
|
||||||
|
* - See RETURN VALUES above
|
||||||
|
* - If merge is clean, a commit is created and its address written to *result
|
||||||
|
* - opt->repo->index has the new index
|
||||||
|
* - $GIT_INDEX_FILE is not updated
|
||||||
|
* - The working tree is updated with results of the merge
|
||||||
*/
|
*/
|
||||||
int merge_recursive(struct merge_options *opt,
|
int merge_recursive(struct merge_options *opt,
|
||||||
struct commit *h1,
|
struct commit *h1,
|
||||||
|
@ -92,17 +95,16 @@ int merge_recursive(struct merge_options *opt,
|
||||||
struct commit **result);
|
struct commit **result);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* rename-detecting three-way merge, no recursion; result of merge is written
|
* merge_recursive_generic can operate on trees instead of commits, by
|
||||||
* to opt->repo->index.
|
* wrapping the trees into virtual commits, and calling merge_recursive().
|
||||||
*/
|
* It also writes out the in-memory index to disk if the merge is successful.
|
||||||
int merge_trees(struct merge_options *opt,
|
*
|
||||||
struct tree *head,
|
* Outputs:
|
||||||
struct tree *merge,
|
* - See RETURN VALUES above
|
||||||
struct tree *merge_base);
|
* - If merge is clean, a commit is created and its address written to *result
|
||||||
|
* - opt->repo->index has the new index
|
||||||
/*
|
* - $GIT_INDEX_FILE is updated
|
||||||
* "git-merge-recursive" can be fed trees; wrap them into
|
* - The working tree is updated with results of the merge
|
||||||
* virtual commits and call merge_recursive() proper.
|
|
||||||
*/
|
*/
|
||||||
int merge_recursive_generic(struct merge_options *opt,
|
int merge_recursive_generic(struct merge_options *opt,
|
||||||
const struct object_id *head,
|
const struct object_id *head,
|
||||||
|
@ -111,9 +113,4 @@ int merge_recursive_generic(struct merge_options *opt,
|
||||||
const struct object_id **merge_bases,
|
const struct object_id **merge_bases,
|
||||||
struct commit **result);
|
struct commit **result);
|
||||||
|
|
||||||
void init_merge_options(struct merge_options *opt,
|
|
||||||
struct repository *repo);
|
|
||||||
|
|
||||||
int parse_merge_opt(struct merge_options *opt, const char *s);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue