|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* Copyright (C) the libgit2 contributors. All rights reserved.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
Packit Service |
20376f |
* a Linking Exception. For full terms see the included COPYING file.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
#ifndef INCLUDE_merge_h__
|
|
Packit Service |
20376f |
#define INCLUDE_merge_h__
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#include "vector.h"
|
|
Packit Service |
20376f |
#include "commit_list.h"
|
|
Packit Service |
20376f |
#include "pool.h"
|
|
Packit Service |
20376f |
#include "iterator.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#include "git2/types.h"
|
|
Packit Service |
20376f |
#include "git2/merge.h"
|
|
Packit Service |
20376f |
#include "git2/sys/merge.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#define GIT_MERGE_MSG_FILE "MERGE_MSG"
|
|
Packit Service |
20376f |
#define GIT_MERGE_MODE_FILE "MERGE_MODE"
|
|
Packit Service |
20376f |
#define GIT_MERGE_FILE_MODE 0666
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#define GIT_MERGE_DEFAULT_RENAME_THRESHOLD 50
|
|
Packit Service |
20376f |
#define GIT_MERGE_DEFAULT_TARGET_LIMIT 1000
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** Internal merge flags. */
|
|
Packit Service |
20376f |
enum {
|
|
Packit Service |
20376f |
/** The merge is for a virtual base in a recursive merge. */
|
|
Packit Service |
20376f |
GIT_MERGE__VIRTUAL_BASE = (1 << 31),
|
|
Packit Service |
20376f |
};
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
enum {
|
|
Packit Service |
20376f |
/** Accept the conflict file, staging it as the merge result. */
|
|
Packit Service |
20376f |
GIT_MERGE_FILE_FAVOR__CONFLICTED = 4,
|
|
Packit Service |
20376f |
};
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/** Types of changes when files are merged from branch to branch. */
|
|
Packit Service |
20376f |
typedef enum {
|
|
Packit Service |
20376f |
/* No conflict - a change only occurs in one branch. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_NONE = 0,
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when a file is modified in both branches. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_BOTH_MODIFIED = (1 << 0),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when a file is added in both branches. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_BOTH_ADDED = (1 << 1),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when a file is deleted in both branches. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_BOTH_DELETED = (1 << 2),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when a file is modified in one branch and deleted in the other. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_MODIFIED_DELETED = (1 << 3),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when a file is renamed in one branch and modified in the other. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_RENAMED_MODIFIED = (1 << 4),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when a file is renamed in one branch and deleted in the other. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_RENAMED_DELETED = (1 << 5),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when a file is renamed in one branch and a file with the same
|
|
Packit Service |
20376f |
* name is added in the other. Eg, A->B and new file B. Core git calls
|
|
Packit Service |
20376f |
* this a "rename/delete". */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_RENAMED_ADDED = (1 << 6),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when both a file is renamed to the same name in the ours and
|
|
Packit Service |
20376f |
* theirs branches. Eg, A->B and A->B in both. Automergeable. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_BOTH_RENAMED = (1 << 7),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when a file is renamed to different names in the ours and theirs
|
|
Packit Service |
20376f |
* branches. Eg, A->B and A->C. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_BOTH_RENAMED_1_TO_2 = (1 << 8),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when two files are renamed to the same name in the ours and
|
|
Packit Service |
20376f |
* theirs branches. Eg, A->C and B->C. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1 = (1 << 9),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Occurs when an item at a path in one branch is a directory, and an
|
|
Packit Service |
20376f |
* item at the same path in a different branch is a file. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_DIRECTORY_FILE = (1 << 10),
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* The child of a folder that is in a directory/file conflict. */
|
|
Packit Service |
20376f |
GIT_MERGE_DIFF_DF_CHILD = (1 << 11),
|
|
Packit Service |
20376f |
} git_merge_diff_type_t;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
typedef struct {
|
|
Packit Service |
20376f |
git_repository *repo;
|
|
Packit Service |
20376f |
git_pool pool;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Vector of git_index_entry that represent the merged items that
|
|
Packit Service |
20376f |
* have been staged, either because only one side changed, or because
|
|
Packit Service |
20376f |
* the two changes were non-conflicting and mergeable. These items
|
|
Packit Service |
20376f |
* will be written as staged entries in the main index.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
git_vector staged;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Vector of git_merge_diff entries that represent the conflicts that
|
|
Packit Service |
20376f |
* have not been automerged. These items will be written to high-stage
|
|
Packit Service |
20376f |
* entries in the main index.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
git_vector conflicts;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Vector of git_merge_diff that have been automerged. These items
|
|
Packit Service |
20376f |
* will be written to the REUC when the index is produced.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
git_vector resolved;
|
|
Packit Service |
20376f |
} git_merge_diff_list;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/**
|
|
Packit Service |
20376f |
* Description of changes to one file across three trees.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
typedef struct {
|
|
Packit Service |
20376f |
git_merge_diff_type_t type;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_index_entry ancestor_entry;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_index_entry our_entry;
|
|
Packit Service |
20376f |
git_delta_t our_status;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_index_entry their_entry;
|
|
Packit Service |
20376f |
git_delta_t their_status;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
} git_merge_diff;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_merge__bases_many(
|
|
Packit Service |
20376f |
git_commit_list **out,
|
|
Packit Service |
20376f |
git_revwalk *walk,
|
|
Packit Service |
20376f |
git_commit_list_node *one,
|
|
Packit Service |
20376f |
git_vector *twos);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* Three-way tree differencing
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_merge_diff_list__find_differences(
|
|
Packit Service |
20376f |
git_merge_diff_list *merge_diff_list,
|
|
Packit Service |
20376f |
git_iterator *ancestor_iterator,
|
|
Packit Service |
20376f |
git_iterator *ours_iter,
|
|
Packit Service |
20376f |
git_iterator *theirs_iter);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_merge_diff_list__find_renames(git_repository *repo, git_merge_diff_list *merge_diff_list, const git_merge_options *opts);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void git_merge_diff_list__free(git_merge_diff_list *diff_list);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Merge metadata setup */
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_merge__setup(
|
|
Packit Service |
20376f |
git_repository *repo,
|
|
Packit Service |
20376f |
const git_annotated_commit *our_head,
|
|
Packit Service |
20376f |
const git_annotated_commit *heads[],
|
|
Packit Service |
20376f |
size_t heads_len);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_merge__iterators(
|
|
Packit Service |
20376f |
git_index **out,
|
|
Packit Service |
20376f |
git_repository *repo,
|
|
Packit Service |
20376f |
git_iterator *ancestor_iter,
|
|
Packit Service |
20376f |
git_iterator *our_iter,
|
|
Packit Service |
20376f |
git_iterator *their_iter,
|
|
Packit Service |
20376f |
const git_merge_options *given_opts);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_merge__check_result(git_repository *repo, git_index *index_new);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_merge__append_conflicts_to_merge_msg(git_repository *repo, git_index *index);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Merge files */
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
GIT_INLINE(const char *) git_merge_file__best_path(
|
|
Packit Service |
20376f |
const char *ancestor,
|
|
Packit Service |
20376f |
const char *ours,
|
|
Packit Service |
20376f |
const char *theirs)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
if (!ancestor) {
|
|
Packit Service |
20376f |
if (ours && theirs && strcmp(ours, theirs) == 0)
|
|
Packit Service |
20376f |
return ours;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
return NULL;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (ours && strcmp(ancestor, ours) == 0)
|
|
Packit Service |
20376f |
return theirs;
|
|
Packit Service |
20376f |
else if(theirs && strcmp(ancestor, theirs) == 0)
|
|
Packit Service |
20376f |
return ours;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
return NULL;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
GIT_INLINE(uint32_t) git_merge_file__best_mode(
|
|
Packit Service |
20376f |
uint32_t ancestor, uint32_t ours, uint32_t theirs)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* If ancestor didn't exist and either ours or theirs is executable,
|
|
Packit Service |
20376f |
* assume executable. Otherwise, if any mode changed from the ancestor,
|
|
Packit Service |
20376f |
* use that one.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
if (!ancestor) {
|
|
Packit Service |
20376f |
if (ours == GIT_FILEMODE_BLOB_EXECUTABLE ||
|
|
Packit Service |
20376f |
theirs == GIT_FILEMODE_BLOB_EXECUTABLE)
|
|
Packit Service |
20376f |
return GIT_FILEMODE_BLOB_EXECUTABLE;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
return GIT_FILEMODE_BLOB;
|
|
Packit Service |
20376f |
} else if (ours && theirs) {
|
|
Packit Service |
20376f |
if (ancestor == ours)
|
|
Packit Service |
20376f |
return theirs;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
return ours;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
return 0;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#endif
|