]>
Commit | Line | Data |
---|---|---|
632d8b23 | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
632d8b23 ET |
3 | * |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
6 | */ | |
7 | #ifndef INCLUDE_merge_h__ | |
8 | #define INCLUDE_merge_h__ | |
9 | ||
42e50b5e | 10 | #include "vector.h" |
bec65a5e ET |
11 | #include "commit_list.h" |
12 | #include "pool.h" | |
13 | ||
14 | #include "git2/merge.h" | |
15 | #include "git2/types.h" | |
632d8b23 ET |
16 | |
17 | #define GIT_MERGE_MSG_FILE "MERGE_MSG" | |
18 | #define GIT_MERGE_MODE_FILE "MERGE_MODE" | |
1d3a8aeb | 19 | #define GIT_MERGE_FILE_MODE 0666 |
632d8b23 | 20 | |
bec65a5e ET |
21 | #define GIT_MERGE_TREE_RENAME_THRESHOLD 50 |
22 | #define GIT_MERGE_TREE_TARGET_LIMIT 1000 | |
23 | ||
24 | /** Types of changes when files are merged from branch to branch. */ | |
25 | typedef enum { | |
26 | /* No conflict - a change only occurs in one branch. */ | |
27 | GIT_MERGE_DIFF_NONE = 0, | |
1fed6b07 | 28 | |
bec65a5e ET |
29 | /* Occurs when a file is modified in both branches. */ |
30 | GIT_MERGE_DIFF_BOTH_MODIFIED = (1 << 0), | |
1fed6b07 | 31 | |
bec65a5e ET |
32 | /* Occurs when a file is added in both branches. */ |
33 | GIT_MERGE_DIFF_BOTH_ADDED = (1 << 1), | |
1fed6b07 | 34 | |
bec65a5e ET |
35 | /* Occurs when a file is deleted in both branches. */ |
36 | GIT_MERGE_DIFF_BOTH_DELETED = (1 << 2), | |
1fed6b07 | 37 | |
bec65a5e ET |
38 | /* Occurs when a file is modified in one branch and deleted in the other. */ |
39 | GIT_MERGE_DIFF_MODIFIED_DELETED = (1 << 3), | |
1fed6b07 | 40 | |
bec65a5e ET |
41 | /* Occurs when a file is renamed in one branch and modified in the other. */ |
42 | GIT_MERGE_DIFF_RENAMED_MODIFIED = (1 << 4), | |
1fed6b07 | 43 | |
bec65a5e ET |
44 | /* Occurs when a file is renamed in one branch and deleted in the other. */ |
45 | GIT_MERGE_DIFF_RENAMED_DELETED = (1 << 5), | |
1fed6b07 | 46 | |
bec65a5e ET |
47 | /* Occurs when a file is renamed in one branch and a file with the same |
48 | * name is added in the other. Eg, A->B and new file B. Core git calls | |
49 | * this a "rename/delete". */ | |
50 | GIT_MERGE_DIFF_RENAMED_ADDED = (1 << 6), | |
1fed6b07 | 51 | |
bec65a5e ET |
52 | /* Occurs when both a file is renamed to the same name in the ours and |
53 | * theirs branches. Eg, A->B and A->B in both. Automergeable. */ | |
54 | GIT_MERGE_DIFF_BOTH_RENAMED = (1 << 7), | |
1fed6b07 | 55 | |
bec65a5e ET |
56 | /* Occurs when a file is renamed to different names in the ours and theirs |
57 | * branches. Eg, A->B and A->C. */ | |
58 | GIT_MERGE_DIFF_BOTH_RENAMED_1_TO_2 = (1 << 8), | |
1fed6b07 | 59 | |
bec65a5e ET |
60 | /* Occurs when two files are renamed to the same name in the ours and |
61 | * theirs branches. Eg, A->C and B->C. */ | |
62 | GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1 = (1 << 9), | |
1fed6b07 | 63 | |
bec65a5e ET |
64 | /* Occurs when an item at a path in one branch is a directory, and an |
65 | * item at the same path in a different branch is a file. */ | |
66 | GIT_MERGE_DIFF_DIRECTORY_FILE = (1 << 10), | |
1fed6b07 | 67 | |
bec65a5e ET |
68 | /* The child of a folder that is in a directory/file conflict. */ |
69 | GIT_MERGE_DIFF_DF_CHILD = (1 << 11), | |
70 | } git_merge_diff_type_t; | |
71 | ||
72 | ||
73 | typedef struct { | |
0cb16fe9 L |
74 | git_repository *repo; |
75 | git_pool pool; | |
1fed6b07 | 76 | |
0cb16fe9 | 77 | /* Vector of git_index_entry that represent the merged items that |
bec65a5e ET |
78 | * have been staged, either because only one side changed, or because |
79 | * the two changes were non-conflicting and mergeable. These items | |
80 | * will be written as staged entries in the main index. | |
81 | */ | |
0cb16fe9 | 82 | git_vector staged; |
1fed6b07 | 83 | |
0cb16fe9 | 84 | /* Vector of git_merge_diff entries that represent the conflicts that |
bec65a5e ET |
85 | * have not been automerged. These items will be written to high-stage |
86 | * entries in the main index. | |
87 | */ | |
0cb16fe9 | 88 | git_vector conflicts; |
1fed6b07 | 89 | |
0cb16fe9 | 90 | /* Vector of git_merge_diff that have been automerged. These items |
bec65a5e ET |
91 | * will be written to the REUC when the index is produced. |
92 | */ | |
0cb16fe9 | 93 | git_vector resolved; |
bec65a5e ET |
94 | } git_merge_diff_list; |
95 | ||
96 | /** | |
97 | * Description of changes to one file across three trees. | |
98 | */ | |
99 | typedef struct { | |
0cb16fe9 | 100 | git_merge_diff_type_t type; |
1fed6b07 | 101 | |
0cb16fe9 | 102 | git_index_entry ancestor_entry; |
1fed6b07 | 103 | |
0cb16fe9 L |
104 | git_index_entry our_entry; |
105 | git_delta_t our_status; | |
1fed6b07 | 106 | |
0cb16fe9 L |
107 | git_index_entry their_entry; |
108 | git_delta_t their_status; | |
6b92c99b ET |
109 | |
110 | int binary:1; | |
bec65a5e ET |
111 | } git_merge_diff; |
112 | ||
9c06b250 ET |
113 | /** Internal structure for merge inputs */ |
114 | struct git_merge_head { | |
115 | char *ref_name; | |
116 | char *remote_url; | |
117 | ||
118 | git_oid oid; | |
039db728 | 119 | char oid_str[GIT_OID_HEXSZ+1]; |
9c06b250 ET |
120 | git_commit *commit; |
121 | }; | |
122 | ||
039db728 ET |
123 | /** Internal structure for merge results */ |
124 | struct git_merge_result { | |
125 | bool is_uptodate; | |
126 | ||
127 | bool is_fastforward; | |
128 | git_oid fastforward_oid; | |
129 | ||
130 | git_index *index; | |
131 | }; | |
132 | ||
bec65a5e ET |
133 | int git_merge__bases_many( |
134 | git_commit_list **out, | |
135 | git_revwalk *walk, | |
136 | git_commit_list_node *one, | |
137 | git_vector *twos); | |
138 | ||
9c06b250 ET |
139 | /* |
140 | * Three-way tree differencing | |
141 | */ | |
142 | ||
bec65a5e ET |
143 | git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo); |
144 | ||
145 | int git_merge_diff_list__find_differences(git_merge_diff_list *merge_diff_list, | |
146 | const git_tree *ancestor_tree, | |
147 | const git_tree *ours_tree, | |
148 | const git_tree *theirs_tree); | |
149 | ||
150 | int git_merge_diff_list__find_renames(git_repository *repo, git_merge_diff_list *merge_diff_list, const git_merge_tree_opts *opts); | |
632d8b23 | 151 | |
bec65a5e | 152 | void git_merge_diff_list__free(git_merge_diff_list *diff_list); |
632d8b23 | 153 | |
9c06b250 ET |
154 | /* Merge metadata setup */ |
155 | ||
156 | int git_merge__setup( | |
157 | git_repository *repo, | |
158 | const git_merge_head *our_head, | |
159 | const git_merge_head *their_heads[], | |
160 | size_t their_heads_len, | |
161 | unsigned int flags); | |
162 | ||
300d192f ET |
163 | int git_merge__indexes(git_repository *repo, git_index *index_new); |
164 | ||
632d8b23 | 165 | #endif |