merge-recursive: future-proof update_file_flags() against memory leaks
[git] / merge-recursive.h
1 #ifndef MERGE_RECURSIVE_H
2 #define MERGE_RECURSIVE_H
3
4 #include "string-list.h"
5 #include "unpack-trees.h"
6
7 struct commit;
8
9 struct repository;
10
11 struct merge_options {
12         const char *ancestor;
13         const char *branch1;
14         const char *branch2;
15         enum {
16                 MERGE_RECURSIVE_NORMAL = 0,
17                 MERGE_RECURSIVE_OURS,
18                 MERGE_RECURSIVE_THEIRS
19         } recursive_variant;
20         const char *subtree_shift;
21         unsigned buffer_output; /* 1: output at end, 2: keep buffered */
22         unsigned renormalize : 1;
23         long xdl_opts;
24         int verbosity;
25         enum {
26                 MERGE_DIRECTORY_RENAMES_NONE = 0,
27                 MERGE_DIRECTORY_RENAMES_CONFLICT = 1,
28                 MERGE_DIRECTORY_RENAMES_TRUE = 2
29         } detect_directory_renames;
30         int diff_detect_rename;
31         int merge_detect_rename;
32         int diff_rename_limit;
33         int merge_rename_limit;
34         int rename_score;
35         int needed_rename_limit;
36         int show_rename_progress;
37         int call_depth;
38         struct strbuf obuf;
39         struct hashmap current_file_dir_set;
40         struct string_list df_conflict_file_set;
41         struct unpack_trees_options unpack_opts;
42         struct index_state orig_index;
43         struct repository *repo;
44 };
45
46 /*
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
55  */
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 };
70
71 static inline int merge_detect_rename(struct merge_options *o)
72 {
73         return o->merge_detect_rename >= 0 ? o->merge_detect_rename :
74                 o->diff_detect_rename >= 0 ? o->diff_detect_rename : 1;
75 }
76
77 /* merge_trees() but with recursive ancestor consolidation */
78 int merge_recursive(struct merge_options *o,
79                     struct commit *h1,
80                     struct commit *h2,
81                     struct commit_list *ancestors,
82                     struct commit **result);
83
84 /* rename-detecting three-way merge, no recursion */
85 int merge_trees(struct merge_options *o,
86                 struct tree *head,
87                 struct tree *merge,
88                 struct tree *common,
89                 struct tree **result);
90
91 /*
92  * "git-merge-recursive" can be fed trees; wrap them into
93  * virtual commits and call merge_recursive() proper.
94  */
95 int merge_recursive_generic(struct merge_options *o,
96                             const struct object_id *head,
97                             const struct object_id *merge,
98                             int num_ca,
99                             const struct object_id **ca,
100                             struct commit **result);
101
102 void init_merge_options(struct merge_options *o,
103                         struct repository *repo);
104 struct tree *write_tree_from_memory(struct merge_options *o);
105
106 int parse_merge_opt(struct merge_options *out, const char *s);
107
108 #endif