Class Merger
- java.lang.Object
-
- org.eclipse.jgit.merge.Merger
-
- Direct Known Subclasses:
ThreeWayMerger
public abstract class Merger extends Object
Instance of a specificMergeStrategy
for a singleRepository
.
-
-
Field Summary
Fields Modifier and Type Field Description protected Repository
db
The repository this merger operates on.protected ProgressMonitor
monitor
A progress monitor.protected ObjectReader
reader
Reader to supportwalk
and other object loading.protected RevCommit[]
sourceCommits
IfsourceObjects
[i] is a commit, this is the commit.protected RevObject[]
sourceObjects
The original objects supplied in the merge; this can be any tree-ish.protected RevTree[]
sourceTrees
The trees matching every entry insourceObjects
.protected RevWalk
walk
A RevWalk for computing merge bases, or listing incoming commits.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Merger(ObjectInserter oi)
Create a new in-core merge instance from an inserter.protected
Merger(Repository local)
Create a new merge instance for a repository.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected RevCommit
getBaseCommit(RevCommit a, RevCommit b)
Return the merge base of two commits.abstract ObjectId
getBaseCommitId()
Get the ID of the commit that was used as merge base for mergingObjectInserter
getObjectInserter()
Get an object writer to create objects, writing objects togetRepository()
Repository
getRepository()
Get the repository this merger operates on.abstract ObjectId
getResultTreeId()
Get resulting tree.boolean
merge(boolean flush, AnyObjectId... tips)
Merge together two or more tree-ish objects.boolean
merge(AnyObjectId... tips)
Merge together two or more tree-ish objects.protected abstract boolean
mergeImpl()
Execute the merge.protected Repository
nonNullRepo()
Get non-null repository instanceprotected AbstractTreeIterator
openTree(AnyObjectId treeId)
Open an iterator over a tree.void
setObjectInserter(ObjectInserter oi)
Set the inserter this merger will use to create objects.void
setProgressMonitor(ProgressMonitor monitor)
Set a progress monitor.
-
-
-
Field Detail
-
db
@Nullable protected final Repository db
The repository this merger operates on.Null if and only if the merger was constructed with
Merger(ObjectInserter)
. Callers that want to assume the repo is not null (e.g. because of a previous check that the merger is not in-core) may usenonNullRepo()
.
-
reader
protected ObjectReader reader
Reader to supportwalk
and other object loading.
-
walk
protected RevWalk walk
A RevWalk for computing merge bases, or listing incoming commits.
-
sourceObjects
protected RevObject[] sourceObjects
The original objects supplied in the merge; this can be any tree-ish.
-
sourceCommits
protected RevCommit[] sourceCommits
IfsourceObjects
[i] is a commit, this is the commit.
-
sourceTrees
protected RevTree[] sourceTrees
The trees matching every entry insourceObjects
.
-
monitor
protected ProgressMonitor monitor
A progress monitor.- Since:
- 4.2
-
-
Constructor Detail
-
Merger
protected Merger(Repository local)
Create a new merge instance for a repository.- Parameters:
local
- the repository this merger will read and write data on.
-
Merger
protected Merger(ObjectInserter oi)
Create a new in-core merge instance from an inserter.- Parameters:
oi
- the inserter to write objects to. Will be closed at the conclusion ofmerge
, unlessflush
is false.- Since:
- 4.8
-
-
Method Detail
-
getRepository
@Nullable public Repository getRepository()
Get the repository this merger operates on.- Returns:
- the repository this merger operates on.
-
nonNullRepo
protected Repository nonNullRepo()
Get non-null repository instance- Returns:
- non-null repository instance
- Throws:
NullPointerException
- if the merger was constructed without a repository.- Since:
- 4.8
-
getObjectInserter
public ObjectInserter getObjectInserter()
Get an object writer to create objects, writing objects togetRepository()
- Returns:
- an object writer to create objects, writing objects to
getRepository()
(if a repository was provided).
-
setObjectInserter
public void setObjectInserter(ObjectInserter oi)
Set the inserter this merger will use to create objects.If an inserter was already set on this instance (such as by a prior set, or a prior call to
getObjectInserter()
), the prior inserter as well as the in-progress walk will be released.- Parameters:
oi
- the inserter instance to use. Must be associated with the repository instance returned bygetRepository()
(if a repository was provided). Will be closed at the conclusion ofmerge
, unlessflush
is false.
-
merge
public boolean merge(AnyObjectId... tips) throws IOException
Merge together two or more tree-ish objects.Any tree-ish may be supplied as inputs. Commits and/or tags pointing at trees or commits may be passed as input objects.
- Parameters:
tips
- source trees to be combined together. The merge base is not included in this set.- Returns:
- true if the merge was completed without conflicts; false if the merge strategy cannot handle this merge or there were conflicts preventing it from automatically resolving all paths.
- Throws:
IncorrectObjectTypeException
- one of the input objects is not a commit, but the strategy requires it to be a commit.IOException
- one or more sources could not be read, or outputs could not be written to the Repository.
-
merge
public boolean merge(boolean flush, AnyObjectId... tips) throws IOException
Merge together two or more tree-ish objects.Any tree-ish may be supplied as inputs. Commits and/or tags pointing at trees or commits may be passed as input objects.
- Parameters:
flush
- whether to flush and close the underlying object inserter when finished to store any content-merged blobs and virtual merged bases; if false, callers are responsible for flushing.tips
- source trees to be combined together. The merge base is not included in this set.- Returns:
- true if the merge was completed without conflicts; false if the merge strategy cannot handle this merge or there were conflicts preventing it from automatically resolving all paths.
- Throws:
IncorrectObjectTypeException
- one of the input objects is not a commit, but the strategy requires it to be a commit.IOException
- one or more sources could not be read, or outputs could not be written to the Repository.- Since:
- 3.5
-
getBaseCommitId
public abstract ObjectId getBaseCommitId()
Get the ID of the commit that was used as merge base for merging- Returns:
- the ID of the commit that was used as merge base for merging, or null if no merge base was used or it was set manually
- Since:
- 3.2
-
getBaseCommit
protected RevCommit getBaseCommit(RevCommit a, RevCommit b) throws IncorrectObjectTypeException, IOException
Return the merge base of two commits.- Parameters:
a
- the first commit insourceObjects
.b
- the second commit insourceObjects
.- Returns:
- the merge base of two commits
- Throws:
IncorrectObjectTypeException
- one of the input objects is not a commit.IOException
- objects are missing or multiple merge bases were found.- Since:
- 3.0
-
openTree
protected AbstractTreeIterator openTree(AnyObjectId treeId) throws IncorrectObjectTypeException, IOException
Open an iterator over a tree.- Parameters:
treeId
- the tree to scan; must be a tree (not a treeish).- Returns:
- an iterator for the tree.
- Throws:
IncorrectObjectTypeException
- the input object is not a tree.IOException
- the tree object is not found or cannot be read.
-
mergeImpl
protected abstract boolean mergeImpl() throws IOException
Execute the merge.This method is called from
merge(AnyObjectId[])
after thesourceObjects
,sourceCommits
andsourceTrees
have been populated.- Returns:
- true if the merge was completed without conflicts; false if the merge strategy cannot handle this merge or there were conflicts preventing it from automatically resolving all paths.
- Throws:
IncorrectObjectTypeException
- one of the input objects is not a commit, but the strategy requires it to be a commit.IOException
- one or more sources could not be read, or outputs could not be written to the Repository.
-
getResultTreeId
public abstract ObjectId getResultTreeId()
Get resulting tree.- Returns:
- resulting tree, if
merge(AnyObjectId[])
returned true.
-
setProgressMonitor
public void setProgressMonitor(ProgressMonitor monitor)
Set a progress monitor.- Parameters:
monitor
- Monitor to use, can be null to indicate no progress reporting is desired.- Since:
- 4.2
-
-