merge.h 4.46 KB
Newer Older
Edward Thomson committed
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
Edward Thomson committed
3 4 5 6 7 8 9
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
#ifndef INCLUDE_merge_h__
#define INCLUDE_merge_h__

10
#include "vector.h"
Edward Thomson committed
11 12 13 14 15
#include "commit_list.h"
#include "pool.h"

#include "git2/merge.h"
#include "git2/types.h"
Edward Thomson committed
16 17 18

#define GIT_MERGE_MSG_FILE		"MERGE_MSG"
#define GIT_MERGE_MODE_FILE		"MERGE_MODE"
19
#define GIT_MERGE_FILE_MODE		0666
Edward Thomson committed
20

Edward Thomson committed
21 22 23 24 25 26 27
#define GIT_MERGE_TREE_RENAME_THRESHOLD	50
#define GIT_MERGE_TREE_TARGET_LIMIT		1000

/** Types of changes when files are merged from branch to branch. */
typedef enum {
	/* No conflict - a change only occurs in one branch. */
	GIT_MERGE_DIFF_NONE = 0,
nulltoken committed
28

Edward Thomson committed
29 30
	/* Occurs when a file is modified in both branches. */
	GIT_MERGE_DIFF_BOTH_MODIFIED = (1 << 0),
nulltoken committed
31

Edward Thomson committed
32 33
	/* Occurs when a file is added in both branches. */
	GIT_MERGE_DIFF_BOTH_ADDED = (1 << 1),
nulltoken committed
34

Edward Thomson committed
35 36
	/* Occurs when a file is deleted in both branches. */
	GIT_MERGE_DIFF_BOTH_DELETED = (1 << 2),
nulltoken committed
37

Edward Thomson committed
38 39
	/* Occurs when a file is modified in one branch and deleted in the other. */
	GIT_MERGE_DIFF_MODIFIED_DELETED = (1 << 3),
nulltoken committed
40

Edward Thomson committed
41 42
	/* Occurs when a file is renamed in one branch and modified in the other. */
	GIT_MERGE_DIFF_RENAMED_MODIFIED = (1 << 4),
nulltoken committed
43

Edward Thomson committed
44 45
	/* Occurs when a file is renamed in one branch and deleted in the other. */
	GIT_MERGE_DIFF_RENAMED_DELETED = (1 << 5),
nulltoken committed
46

Edward Thomson committed
47 48 49 50
	/* Occurs when a file is renamed in one branch and a file with the same
	 * name is added in the other.  Eg, A->B and new file B.  Core git calls
	 * this a "rename/delete". */
	GIT_MERGE_DIFF_RENAMED_ADDED = (1 << 6),
nulltoken committed
51

Edward Thomson committed
52 53 54
	/* Occurs when both a file is renamed to the same name in the ours and
	 * theirs branches.  Eg, A->B and A->B in both.  Automergeable. */
	GIT_MERGE_DIFF_BOTH_RENAMED = (1 << 7),
nulltoken committed
55

Edward Thomson committed
56 57 58
	/* Occurs when a file is renamed to different names in the ours and theirs
	 * branches.  Eg, A->B and A->C. */
	GIT_MERGE_DIFF_BOTH_RENAMED_1_TO_2 = (1 << 8),
nulltoken committed
59

Edward Thomson committed
60 61 62
	/* Occurs when two files are renamed to the same name in the ours and
	 * theirs branches.  Eg, A->C and B->C. */
	GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1 = (1 << 9),
nulltoken committed
63

Edward Thomson committed
64 65 66
	/* Occurs when an item at a path in one branch is a directory, and an
	 * item at the same path in a different branch is a file. */
	GIT_MERGE_DIFF_DIRECTORY_FILE = (1 << 10),
nulltoken committed
67

Edward Thomson committed
68 69 70 71 72 73
	/* The child of a folder that is in a directory/file conflict. */
	GIT_MERGE_DIFF_DF_CHILD = (1 << 11),
} git_merge_diff_type_t;


typedef struct {
Linquize committed
74 75
	git_repository *repo;
	git_pool pool;
nulltoken committed
76

Linquize committed
77
	/* Vector of git_index_entry that represent the merged items that
Edward Thomson committed
78 79 80 81
	 * have been staged, either because only one side changed, or because
	 * the two changes were non-conflicting and mergeable.  These items
	 * will be written as staged entries in the main index.
	 */
Linquize committed
82
	git_vector staged;
nulltoken committed
83

Linquize committed
84
	/* Vector of git_merge_diff entries that represent the conflicts that
Edward Thomson committed
85 86 87
	 * have not been automerged.  These items will be written to high-stage
	 * entries in the main index.
	 */
Linquize committed
88
	git_vector conflicts;
nulltoken committed
89

Linquize committed
90
	/* Vector of git_merge_diff that have been automerged.  These items
Edward Thomson committed
91 92
	 * will be written to the REUC when the index is produced.
	 */
Linquize committed
93
	git_vector resolved;
Edward Thomson committed
94 95 96 97 98 99
} git_merge_diff_list;

/**
 * Description of changes to one file across three trees.
 */
typedef struct {
Linquize committed
100
	git_merge_diff_type_t type;
nulltoken committed
101

Linquize committed
102
	git_index_entry ancestor_entry;
nulltoken committed
103

Linquize committed
104 105
	git_index_entry our_entry;
	git_delta_t our_status;
nulltoken committed
106

Linquize committed
107 108
	git_index_entry their_entry;
	git_delta_t their_status;
109 110

	int binary:1;
Edward Thomson committed
111 112
} git_merge_diff;

Edward Thomson committed
113 114 115 116 117 118
/** Internal structure for merge inputs */
struct git_merge_head {
	char *ref_name;
	char *remote_url;

	git_oid oid;
119
	char oid_str[GIT_OID_HEXSZ+1];
Edward Thomson committed
120 121 122
	git_commit *commit;
};

Edward Thomson committed
123 124 125 126 127 128
int git_merge__bases_many(
	git_commit_list **out,
	git_revwalk *walk,
	git_commit_list_node *one,
	git_vector *twos);

Edward Thomson committed
129 130 131 132
/*
 * Three-way tree differencing
 */

Edward Thomson committed
133 134 135 136 137 138 139
git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo);

int git_merge_diff_list__find_differences(git_merge_diff_list *merge_diff_list,
	const git_tree *ancestor_tree,
	const git_tree *ours_tree,
	const git_tree *theirs_tree);

140
int git_merge_diff_list__find_renames(git_repository *repo, git_merge_diff_list *merge_diff_list, const git_merge_options *opts);
Edward Thomson committed
141

Edward Thomson committed
142
void git_merge_diff_list__free(git_merge_diff_list *diff_list);
Edward Thomson committed
143

Edward Thomson committed
144 145 146 147 148
/* Merge metadata setup */

int git_merge__setup(
	git_repository *repo,
	const git_merge_head *our_head,
149 150
	const git_merge_head *heads[],
	size_t heads_len);
Edward Thomson committed
151

152 153
int git_merge__indexes(git_repository *repo, git_index *index_new);

154 155
int git_merge__append_conflicts_to_merge_msg(git_repository *repo, git_index *index);

Edward Thomson committed
156
#endif