Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 758e50c

Browse files
author
Vicent Martí
committed
Merge pull request #1389 from ethomson/merge_trees
Merge trees
2 parents cfcdbc1 + 75d1c8c commit 758e50c

File tree

427 files changed

+4714
-143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

427 files changed

+4714
-143
lines changed

docs/merge-df_conflicts.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Anc / Our / Thr represent the ancestor / ours / theirs side of a merge
2+
from branch "branch" into HEAD. Workdir represents the expected files in
3+
the working directory. Index represents the expected files in the index,
4+
with stage markers.
5+
6+
Anc Our Thr Workdir Index
7+
1 D D
8+
D/F D/F D/F [0]
9+
10+
2 D D+ D~HEAD (mod/del) D/F [0]
11+
D/F D/F D [1]
12+
D [2]
13+
14+
3 D D D/F D/F [0]
15+
D/F
16+
17+
4 D D+ D~branch (mod/del) D/F [0]
18+
D/F D/F D [1]
19+
D [3]
20+
21+
5 D D/F (add/add) D/F [2]
22+
D/F D/F [3]
23+
D/F
24+
25+
6 D/F D/F D D [0]
26+
D
27+
28+
7 D/F D/F+ D/F (mod/del) D/F [1]
29+
D D~branch (fil/dir) D/F [2]
30+
D [3]
31+
32+
8 D/F D/F D D [0]
33+
D
34+
35+
9 D/F D/F+ D/F (mod/del) D/F [1]
36+
D D~HEAD (fil/dir) D [2]
37+
D/F [3]
38+
39+
10 D/F D/F (fil/dir) D/F [0]
40+
D D~HEAD D [2]
41+
D

include/git2/index.h

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ typedef struct git_index_entry {
8484
char *path;
8585
} git_index_entry;
8686

87-
/** Representation of a resolve undo entry in the index. */
88-
typedef struct git_index_reuc_entry {
89-
unsigned int mode[3];
90-
git_oid oid[3];
91-
char *path;
92-
} git_index_reuc_entry;
93-
9487
/** Capabilities of system that affect index actions. */
9588
enum {
9689
GIT_INDEXCAP_IGNORE_CASE = 1,
@@ -478,102 +471,6 @@ GIT_EXTERN(int) git_index_has_conflicts(const git_index *index);
478471

479472
/**@}*/
480473

481-
/** @name Resolve Undo (REUC) index entry manipulation.
482-
*
483-
* These functions work on the Resolve Undo index extension and contains
484-
* data about the original files that led to a merge conflict.
485-
*/
486-
/**@{*/
487-
488-
/**
489-
* Get the count of resolve undo entries currently in the index.
490-
*
491-
* @param index an existing index object
492-
* @return integer of count of current resolve undo entries
493-
*/
494-
GIT_EXTERN(unsigned int) git_index_reuc_entrycount(git_index *index);
495-
496-
/**
497-
* Finds the resolve undo entry that points to the given path in the Git
498-
* index.
499-
*
500-
* @param at_pos the address to which the position of the reuc entry is written (optional)
501-
* @param index an existing index object
502-
* @param path path to search
503-
* @return 0 if found, < 0 otherwise (GIT_ENOTFOUND)
504-
*/
505-
GIT_EXTERN(int) git_index_reuc_find(size_t *at_pos, git_index *index, const char *path);
506-
507-
/**
508-
* Get a resolve undo entry from the index.
509-
*
510-
* The returned entry is read-only and should not be modified
511-
* or freed by the caller.
512-
*
513-
* @param index an existing index object
514-
* @param path path to search
515-
* @return the resolve undo entry; NULL if not found
516-
*/
517-
GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *index, const char *path);
518-
519-
/**
520-
* Get a resolve undo entry from the index.
521-
*
522-
* The returned entry is read-only and should not be modified
523-
* or freed by the caller.
524-
*
525-
* @param index an existing index object
526-
* @param n the position of the entry
527-
* @return a pointer to the resolve undo entry; NULL if out of bounds
528-
*/
529-
GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *index, size_t n);
530-
531-
/**
532-
* Adds a resolve undo entry for a file based on the given parameters.
533-
*
534-
* The resolve undo entry contains the OIDs of files that were involved
535-
* in a merge conflict after the conflict has been resolved. This allows
536-
* conflicts to be re-resolved later.
537-
*
538-
* If there exists a resolve undo entry for the given path in the index,
539-
* it will be removed.
540-
*
541-
* This method will fail in bare index instances.
542-
*
543-
* @param index an existing index object
544-
* @param path filename to add
545-
* @param ancestor_mode mode of the ancestor file
546-
* @param ancestor_id oid of the ancestor file
547-
* @param our_mode mode of our file
548-
* @param our_id oid of our file
549-
* @param their_mode mode of their file
550-
* @param their_id oid of their file
551-
* @return 0 or an error code
552-
*/
553-
GIT_EXTERN(int) git_index_reuc_add(git_index *index, const char *path,
554-
int ancestor_mode, git_oid *ancestor_id,
555-
int our_mode, git_oid *our_id,
556-
int their_mode, git_oid *their_id);
557-
558-
/**
559-
* Remove an resolve undo entry from the index
560-
*
561-
* @param index an existing index object
562-
* @param n position of the resolve undo entry to remove
563-
* @return 0 or an error code
564-
*/
565-
GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n);
566-
567-
/**
568-
* Remove all resolve undo entries from the index
569-
*
570-
* @param index an existing index object
571-
* @return 0 or an error code
572-
*/
573-
GIT_EXTERN(void) git_index_reuc_clear(git_index *index);
574-
575-
/**@}*/
576-
577474
/** @} */
578475
GIT_END_DECL
579476
#endif

include/git2/merge.h

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,64 @@
77
#ifndef INCLUDE_git_merge_h__
88
#define INCLUDE_git_merge_h__
99

10-
#include "common.h"
11-
#include "types.h"
12-
#include "oid.h"
10+
#include "git2/common.h"
11+
#include "git2/types.h"
12+
#include "git2/oid.h"
13+
#include "git2/checkout.h"
14+
#include "git2/index.h"
1315

1416
/**
1517
* @file git2/merge.h
16-
* @brief Git merge-base routines
17-
* @defgroup git_revwalk Git merge-base routines
18+
* @brief Git merge routines
19+
* @defgroup git_merge Git merge routines
1820
* @ingroup Git
1921
* @{
2022
*/
2123
GIT_BEGIN_DECL
2224

25+
/**
26+
* Flags for tree_many diff options. A combination of these flags can be
27+
* passed in via the `flags` value in the `git_diff_tree_many_options`.
28+
*/
29+
typedef enum {
30+
/** Detect renames */
31+
GIT_MERGE_TREE_FIND_RENAMES = (1 << 0),
32+
} git_merge_tree_flags;
33+
34+
/**
35+
* Automerge options for `git_merge_trees_opts`.
36+
*/
37+
typedef enum {
38+
GIT_MERGE_AUTOMERGE_NORMAL = 0,
39+
GIT_MERGE_AUTOMERGE_NONE = 1,
40+
GIT_MERGE_AUTOMERGE_FAVOR_OURS = 2,
41+
GIT_MERGE_AUTOMERGE_FAVOR_THEIRS = 3,
42+
} git_merge_automerge_flags;
43+
44+
45+
typedef struct {
46+
unsigned int version;
47+
git_merge_tree_flags flags;
48+
49+
/** Similarity to consider a file renamed (default 50) */
50+
unsigned int rename_threshold;
51+
52+
/** Maximum similarity sources to examine (overrides the
53+
* `merge.renameLimit` config) (default 200)
54+
*/
55+
unsigned int target_limit;
56+
57+
/** Pluggable similarity metric; pass NULL to use internal metric */
58+
git_diff_similarity_metric *metric;
59+
60+
/** Flags for automerging content. */
61+
git_merge_automerge_flags automerge_flags;
62+
} git_merge_tree_opts;
63+
64+
#define GIT_MERGE_TREE_OPTS_VERSION 1
65+
#define GIT_MERGE_TREE_OPTS_INIT {GIT_MERGE_TREE_OPTS_VERSION}
66+
67+
2368
/**
2469
* Find a merge base between two commits
2570
*
@@ -50,6 +95,28 @@ GIT_EXTERN(int) git_merge_base_many(
5095
const git_oid input_array[],
5196
size_t length);
5297

98+
/**
99+
* Merge two trees, producing a `git_index` that reflects the result of
100+
* the merge.
101+
*
102+
* The returned index must be freed explicitly with `git_index_free`.
103+
*
104+
* @param out pointer to store the index result in
105+
* @param repo repository that contains the given trees
106+
* @param ancestor_tree the common ancestor between the trees (or null if none)
107+
* @param our_tree the tree that reflects the destination tree
108+
* @param their_tree the tree to merge in to `our_tree`
109+
* @param opts the merge tree options (or null for defaults)
110+
* @return zero on success, -1 on failure.
111+
*/
112+
GIT_EXTERN(int) git_merge_trees(
113+
git_index **out,
114+
git_repository *repo,
115+
const git_tree *ancestor_tree,
116+
const git_tree *our_tree,
117+
const git_tree *their_tree,
118+
const git_merge_tree_opts *opts);
119+
53120
/** @} */
54121
GIT_END_DECL
55122
#endif

0 commit comments

Comments
 (0)