2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_merge_h__
8 #define INCLUDE_merge_h__
11 #include "commit_list.h"
15 #include "git2/merge.h"
16 #include "git2/types.h"
18 #define GIT_MERGE_MSG_FILE "MERGE_MSG"
19 #define GIT_MERGE_MODE_FILE "MERGE_MODE"
20 #define GIT_MERGE_FILE_MODE 0666
22 #define GIT_MERGE_TREE_RENAME_THRESHOLD 50
23 #define GIT_MERGE_TREE_TARGET_LIMIT 1000
25 /** Types of changes when files are merged from branch to branch. */
27 /* No conflict - a change only occurs in one branch. */
28 GIT_MERGE_DIFF_NONE
= 0,
30 /* Occurs when a file is modified in both branches. */
31 GIT_MERGE_DIFF_BOTH_MODIFIED
= (1 << 0),
33 /* Occurs when a file is added in both branches. */
34 GIT_MERGE_DIFF_BOTH_ADDED
= (1 << 1),
36 /* Occurs when a file is deleted in both branches. */
37 GIT_MERGE_DIFF_BOTH_DELETED
= (1 << 2),
39 /* Occurs when a file is modified in one branch and deleted in the other. */
40 GIT_MERGE_DIFF_MODIFIED_DELETED
= (1 << 3),
42 /* Occurs when a file is renamed in one branch and modified in the other. */
43 GIT_MERGE_DIFF_RENAMED_MODIFIED
= (1 << 4),
45 /* Occurs when a file is renamed in one branch and deleted in the other. */
46 GIT_MERGE_DIFF_RENAMED_DELETED
= (1 << 5),
48 /* Occurs when a file is renamed in one branch and a file with the same
49 * name is added in the other. Eg, A->B and new file B. Core git calls
50 * this a "rename/delete". */
51 GIT_MERGE_DIFF_RENAMED_ADDED
= (1 << 6),
53 /* Occurs when both a file is renamed to the same name in the ours and
54 * theirs branches. Eg, A->B and A->B in both. Automergeable. */
55 GIT_MERGE_DIFF_BOTH_RENAMED
= (1 << 7),
57 /* Occurs when a file is renamed to different names in the ours and theirs
58 * branches. Eg, A->B and A->C. */
59 GIT_MERGE_DIFF_BOTH_RENAMED_1_TO_2
= (1 << 8),
61 /* Occurs when two files are renamed to the same name in the ours and
62 * theirs branches. Eg, A->C and B->C. */
63 GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1
= (1 << 9),
65 /* Occurs when an item at a path in one branch is a directory, and an
66 * item at the same path in a different branch is a file. */
67 GIT_MERGE_DIFF_DIRECTORY_FILE
= (1 << 10),
69 /* The child of a folder that is in a directory/file conflict. */
70 GIT_MERGE_DIFF_DF_CHILD
= (1 << 11),
71 } git_merge_diff_type_t
;
78 /* Vector of git_index_entry that represent the merged items that
79 * have been staged, either because only one side changed, or because
80 * the two changes were non-conflicting and mergeable. These items
81 * will be written as staged entries in the main index.
85 /* Vector of git_merge_diff entries that represent the conflicts that
86 * have not been automerged. These items will be written to high-stage
87 * entries in the main index.
91 /* Vector of git_merge_diff that have been automerged. These items
92 * will be written to the REUC when the index is produced.
95 } git_merge_diff_list
;
98 * Description of changes to one file across three trees.
101 git_merge_diff_type_t type
;
103 git_index_entry ancestor_entry
;
105 git_index_entry our_entry
;
106 git_delta_t our_status
;
108 git_index_entry their_entry
;
109 git_delta_t their_status
;
113 int git_merge__bases_many(
114 git_commit_list
**out
,
116 git_commit_list_node
*one
,
120 * Three-way tree differencing
123 git_merge_diff_list
*git_merge_diff_list__alloc(git_repository
*repo
);
125 int git_merge_diff_list__find_differences(
126 git_merge_diff_list
*merge_diff_list
,
127 git_iterator
*ancestor_iterator
,
128 git_iterator
*ours_iter
,
129 git_iterator
*theirs_iter
);
131 int git_merge_diff_list__find_renames(git_repository
*repo
, git_merge_diff_list
*merge_diff_list
, const git_merge_options
*opts
);
133 void git_merge_diff_list__free(git_merge_diff_list
*diff_list
);
135 /* Merge metadata setup */
137 int git_merge__setup(
138 git_repository
*repo
,
139 const git_annotated_commit
*our_head
,
140 const git_annotated_commit
*heads
[],
143 int git_merge__iterators(
145 git_repository
*repo
,
146 git_iterator
*ancestor_iter
,
147 git_iterator
*our_iter
,
148 git_iterator
*their_iter
,
149 const git_merge_options
*given_opts
);
151 int git_merge__check_result(git_repository
*repo
, git_index
*index_new
);
153 int git_merge__append_conflicts_to_merge_msg(git_repository
*repo
, git_index
*index
);