1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.notes;
12
13 import java.io.IOException;
14
15 import org.eclipse.jgit.lib.Constants;
16 import org.eclipse.jgit.lib.ObjectId;
17 import org.eclipse.jgit.lib.ObjectInserter;
18 import org.eclipse.jgit.lib.ObjectLoader;
19 import org.eclipse.jgit.lib.ObjectReader;
20 import org.eclipse.jgit.util.io.UnionInputStream;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class DefaultNoteMerger implements NoteMerger {
36
37
38 @Override
39 public Note merge(Note base, Note ours, Note theirs, ObjectReader reader,
40 ObjectInserter inserter) throws IOException {
41 if (ours == null)
42 return theirs;
43
44 if (theirs == null)
45 return ours;
46
47 if (ours.getData().equals(theirs.getData()))
48 return ours;
49
50 ObjectLoader lo = reader.open(ours.getData());
51 ObjectLoader lt = reader.open(theirs.getData());
52 try (UnionInputStream union = new UnionInputStream(lo.openStream(),
53 lt.openStream())) {
54 ObjectId noteData = inserter.insert(Constants.OBJ_BLOB,
55 lo.getSize() + lt.getSize(), union);
56 return new Note(ours, noteData);
57 }
58 }
59 }