]> git.proxmox.com Git - libgit2.git/blob - src/merge.h
push: remove own copy of callbacks
[libgit2.git] / src / merge.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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
10 #include "vector.h"
11 #include "commit_list.h"
12 #include "pool.h"
13 #include "iterator.h"
14
15 #include "git2/merge.h"
16 #include "git2/types.h"
17
18 #define GIT_MERGE_MSG_FILE "MERGE_MSG"
19 #define GIT_MERGE_MODE_FILE "MERGE_MODE"
20 #define GIT_MERGE_FILE_MODE 0666
21
22 #define GIT_MERGE_TREE_RENAME_THRESHOLD 50
23 #define GIT_MERGE_TREE_TARGET_LIMIT 1000
24
25 /** Types of changes when files are merged from branch to branch. */
26 typedef enum {
27 /* No conflict - a change only occurs in one branch. */
28 GIT_MERGE_DIFF_NONE = 0,
29
30 /* Occurs when a file is modified in both branches. */
31 GIT_MERGE_DIFF_BOTH_MODIFIED = (1 << 0),
32
33 /* Occurs when a file is added in both branches. */
34 GIT_MERGE_DIFF_BOTH_ADDED = (1 << 1),
35
36 /* Occurs when a file is deleted in both branches. */
37 GIT_MERGE_DIFF_BOTH_DELETED = (1 << 2),
38
39 /* Occurs when a file is modified in one branch and deleted in the other. */
40 GIT_MERGE_DIFF_MODIFIED_DELETED = (1 << 3),
41
42 /* Occurs when a file is renamed in one branch and modified in the other. */
43 GIT_MERGE_DIFF_RENAMED_MODIFIED = (1 << 4),
44
45 /* Occurs when a file is renamed in one branch and deleted in the other. */
46 GIT_MERGE_DIFF_RENAMED_DELETED = (1 << 5),
47
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),
52
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),
56
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),
60
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),
64
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),
68
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;
72
73
74 typedef struct {
75 git_repository *repo;
76 git_pool pool;
77
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.
82 */
83 git_vector staged;
84
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.
88 */
89 git_vector conflicts;
90
91 /* Vector of git_merge_diff that have been automerged. These items
92 * will be written to the REUC when the index is produced.
93 */
94 git_vector resolved;
95 } git_merge_diff_list;
96
97 /**
98 * Description of changes to one file across three trees.
99 */
100 typedef struct {
101 git_merge_diff_type_t type;
102
103 git_index_entry ancestor_entry;
104
105 git_index_entry our_entry;
106 git_delta_t our_status;
107
108 git_index_entry their_entry;
109 git_delta_t their_status;
110
111 } git_merge_diff;
112
113 int git_merge__bases_many(
114 git_commit_list **out,
115 git_revwalk *walk,
116 git_commit_list_node *one,
117 git_vector *twos);
118
119 /*
120 * Three-way tree differencing
121 */
122
123 git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo);
124
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);
130
131 int git_merge_diff_list__find_renames(git_repository *repo, git_merge_diff_list *merge_diff_list, const git_merge_options *opts);
132
133 void git_merge_diff_list__free(git_merge_diff_list *diff_list);
134
135 /* Merge metadata setup */
136
137 int git_merge__setup(
138 git_repository *repo,
139 const git_annotated_commit *our_head,
140 const git_annotated_commit *heads[],
141 size_t heads_len);
142
143 int git_merge__iterators(
144 git_index **out,
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);
150
151 int git_merge__check_result(git_repository *repo, git_index *index_new);
152
153 int git_merge__append_conflicts_to_merge_msg(git_repository *repo, git_index *index);
154
155 #endif