1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.jgit.merge;
13
14 import java.io.IOException;
15
16 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
17 import org.eclipse.jgit.errors.MissingObjectException;
18 import org.eclipse.jgit.lib.AnyObjectId;
19 import org.eclipse.jgit.lib.ObjectId;
20 import org.eclipse.jgit.lib.ObjectInserter;
21 import org.eclipse.jgit.lib.Repository;
22 import org.eclipse.jgit.revwalk.RevCommit;
23 import org.eclipse.jgit.revwalk.RevTree;
24 import org.eclipse.jgit.treewalk.AbstractTreeIterator;
25 import org.eclipse.jgit.treewalk.EmptyTreeIterator;
26
27
28
29
30 public abstract class ThreeWayMerger extends Merger {
31 private RevTree baseTree;
32
33 private ObjectId baseCommitId;
34
35
36
37
38
39
40
41 protected ThreeWayMerger(Repository local) {
42 super(local);
43 }
44
45
46
47
48
49
50
51
52
53 protected ThreeWayMerger(Repository local, boolean inCore) {
54 this(local);
55 }
56
57
58
59
60
61
62
63
64 protected ThreeWayMerger(ObjectInserter inserter) {
65 super(inserter);
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 public void setBase(AnyObjectId id) throws MissingObjectException,
83 IncorrectObjectTypeException, IOException {
84 if (id != null) {
85 baseTree = walk.parseTree(id);
86 } else {
87 baseTree = null;
88 }
89 }
90
91
92 @Override
93 public boolean merge(AnyObjectId... tips) throws IOException {
94 if (tips.length != 2)
95 return false;
96 return super.merge(tips);
97 }
98
99
100 @Override
101 public ObjectId getBaseCommitId() {
102 return baseCommitId;
103 }
104
105
106
107
108
109
110
111
112 protected AbstractTreeIterator mergeBase() throws IOException {
113 if (baseTree != null) {
114 return openTree(baseTree);
115 }
116 RevCommit baseCommit = (baseCommitId != null) ? walk
117 .parseCommit(baseCommitId) : getBaseCommit(sourceCommits[0],
118 sourceCommits[1]);
119 if (baseCommit == null) {
120 baseCommitId = null;
121 return new EmptyTreeIterator();
122 }
123 baseCommitId = baseCommit.toObjectId();
124 return openTree(baseCommit.getTree());
125 }
126 }