blob: c2b7bb65c62ff51af1b89087bbf6692060b5962e [file] [log] [blame]
Daniel Barkalowe1b3a2c2008-02-07 11:40:05 -05001#ifndef MERGE_RECURSIVE_H
2#define MERGE_RECURSIVE_H
3
Miklos Vajna696ee232008-09-03 19:08:56 +02004#include "string-list.h"
Elijah Newrenef3ca952018-08-15 10:54:05 -07005#include "unpack-trees.h"
6
7struct commit;
Miklos Vajna696ee232008-09-03 19:08:56 +02008
Nguyễn Thái Ngọc Duy0d6caa22019-01-12 09:13:29 +07009struct repository;
10
Miklos Vajna8a2fce12008-08-25 16:25:57 +020011struct merge_options {
Jonathan Nieder4c5868f2010-03-20 19:41:38 -050012 const char *ancestor;
Miklos Vajna8a2fce12008-08-25 16:25:57 +020013 const char *branch1;
14 const char *branch2;
Avery Pennarun8cc5b292009-11-25 21:23:55 -050015 enum {
Junio C Hamano85e51b72008-06-30 22:18:57 -070016 MERGE_RECURSIVE_NORMAL = 0,
Avery Pennarun8cc5b292009-11-25 21:23:55 -050017 MERGE_RECURSIVE_OURS,
Gary V. Vaughan4b055482010-05-14 09:31:35 +000018 MERGE_RECURSIVE_THEIRS
Avery Pennarun8cc5b292009-11-25 21:23:55 -050019 } recursive_variant;
Junio C Hamano85e51b72008-06-30 22:18:57 -070020 const char *subtree_shift;
Johannes Schindelinf1e24262016-08-01 13:44:50 +020021 unsigned buffer_output; /* 1: output at end, 2: keep buffered */
Jonathan Nieder1bc0ab72010-08-05 06:15:32 -050022 unsigned renormalize : 1;
Justin Frankel58a1ece2010-08-26 00:50:45 -050023 long xdl_opts;
Miklos Vajna8a2fce12008-08-25 16:25:57 +020024 int verbosity;
Elijah Newren5fdddd92018-08-29 00:06:12 -070025 int detect_directory_renames;
Ben Peart85b46032018-05-02 16:01:14 +000026 int diff_detect_rename;
27 int merge_detect_rename;
Miklos Vajna8a2fce12008-08-25 16:25:57 +020028 int diff_rename_limit;
29 int merge_rename_limit;
Kevin Ballard10ae7522010-09-27 16:58:25 -070030 int rename_score;
Jeff Kingbf0ab102011-02-19 05:20:51 -050031 int needed_rename_limit;
Jeff King99bfc662011-02-20 04:53:21 -050032 int show_rename_progress;
Miklos Vajna50336392008-09-02 23:30:09 +020033 int call_depth;
Miklos Vajnac7d84922008-09-03 02:30:03 +020034 struct strbuf obuf;
Kevin Willfordfc65b002017-09-07 10:25:56 -060035 struct hashmap current_file_dir_set;
Elijah Newren70cc3d32011-08-11 23:19:58 -060036 struct string_list df_conflict_file_set;
Elijah Newren64b1abe2018-04-19 10:58:12 -070037 struct unpack_trees_options unpack_opts;
Elijah Newrena35edc82018-04-19 10:58:20 -070038 struct index_state orig_index;
Nguyễn Thái Ngọc Duy0d6caa22019-01-12 09:13:29 +070039 struct repository *repo;
Elijah Newrenea625cb2018-02-14 10:51:57 -080040};
41
Elijah Newren7fe40b82018-04-19 10:58:05 -070042/*
43 * For dir_rename_entry, directory names are stored as a full path from the
44 * toplevel of the repository and do not include a trailing '/'. Also:
45 *
46 * dir: original name of directory being renamed
47 * non_unique_new_dir: if true, could not determine new_dir
48 * new_dir: final name of directory being renamed
49 * possible_new_dirs: temporary used to help determine new_dir; see comments
50 * in get_directory_renames() for details
51 */
52struct dir_rename_entry {
53 struct hashmap_entry ent; /* must be the first member! */
54 char *dir;
55 unsigned non_unique_new_dir:1;
56 struct strbuf new_dir;
57 struct string_list possible_new_dirs;
58};
59
Elijah Newrene95ab702018-04-19 10:58:07 -070060struct collision_entry {
61 struct hashmap_entry ent; /* must be the first member! */
62 char *target_file;
63 struct string_list source_files;
64 unsigned reported_already:1;
65};
66
Ben Peart85b46032018-05-02 16:01:14 +000067static inline int merge_detect_rename(struct merge_options *o)
68{
69 return o->merge_detect_rename >= 0 ? o->merge_detect_rename :
70 o->diff_detect_rename >= 0 ? o->diff_detect_rename : 1;
71}
72
Miklos Vajna8a2fce12008-08-25 16:25:57 +020073/* merge_trees() but with recursive ancestor consolidation */
74int merge_recursive(struct merge_options *o,
75 struct commit *h1,
Daniel Barkalowe1b3a2c2008-02-07 11:40:05 -050076 struct commit *h2,
Daniel Barkalowe1b3a2c2008-02-07 11:40:05 -050077 struct commit_list *ancestors,
78 struct commit **result);
79
Miklos Vajna8a2fce12008-08-25 16:25:57 +020080/* rename-detecting three-way merge, no recursion */
81int merge_trees(struct merge_options *o,
82 struct tree *head,
Daniel Barkalowe1b3a2c2008-02-07 11:40:05 -050083 struct tree *merge,
84 struct tree *common,
Daniel Barkalowe1b3a2c2008-02-07 11:40:05 -050085 struct tree **result);
Daniel Barkalowe1b3a2c2008-02-07 11:40:05 -050086
Miklos Vajna8a2fce12008-08-25 16:25:57 +020087/*
88 * "git-merge-recursive" can be fed trees; wrap them into
89 * virtual commits and call merge_recursive() proper.
90 */
91int merge_recursive_generic(struct merge_options *o,
brian m. carlson4e8161a2016-06-24 23:09:28 +000092 const struct object_id *head,
93 const struct object_id *merge,
Miklos Vajna8a2fce12008-08-25 16:25:57 +020094 int num_ca,
brian m. carlson4e8161a2016-06-24 23:09:28 +000095 const struct object_id **ca,
Miklos Vajna8a2fce12008-08-25 16:25:57 +020096 struct commit **result);
97
Nguyễn Thái Ngọc Duy0d6caa22019-01-12 09:13:29 +070098void init_merge_options(struct merge_options *o,
99 struct repository *repo);
Miklos Vajna8a2fce12008-08-25 16:25:57 +0200100struct tree *write_tree_from_memory(struct merge_options *o);
Miklos Vajna9047ebb2008-08-12 18:45:14 +0200101
Jonathan Nieder635a7bb2010-08-26 00:47:58 -0500102int parse_merge_opt(struct merge_options *out, const char *s);
103
Daniel Barkalowe1b3a2c2008-02-07 11:40:05 -0500104#endif