Class Merger
- Direct Known Subclasses:
StrategyOneSided.OneSide
,ThreeWayMerger
MergeStrategy
for a
single Repository
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Repository
The repository this merger operates on.private ObjectInserter
protected ProgressMonitor
A progress monitor.protected ObjectReader
Reader to supportwalk
and other object loading.protected RevCommit[]
IfsourceObjects
[i] is a commit, this is the commit.protected RevObject[]
The original objects supplied in the merge; this can be any tree-ish.protected RevTree[]
The trees matching every entry insourceObjects
.protected RevWalk
A RevWalk for computing merge bases, or listing incoming commits. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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
Modifier and TypeMethodDescriptionprotected RevCommit
getBaseCommit
(RevCommit a, RevCommit b) Return the merge base of two commits.abstract ObjectId
Get the ID of the commit that was used as merge base for mergingGet an object writer to create objects, writing objects togetRepository()
Get the repository this merger operates on.abstract ObjectId
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
Execute the merge.protected Repository
Get non-null repository instanceprotected AbstractTreeIterator
openTree
(AnyObjectId treeId) Open an iterator over a tree.void
Set the inserter this merger will use to create objects.void
setProgressMonitor
(ProgressMonitor monitor) Set a progress monitor.
-
Field Details
-
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
Reader to supportwalk
and other object loading. -
walk
A RevWalk for computing merge bases, or listing incoming commits. -
inserter
-
sourceObjects
The original objects supplied in the merge; this can be any tree-ish. -
sourceCommits
IfsourceObjects
[i] is a commit, this is the commit. -
sourceTrees
The trees matching every entry insourceObjects
. -
monitor
A progress monitor.- Since:
- 4.2
-
-
Constructor Details
-
Merger
Create a new merge instance for a repository.- Parameters:
local
- the repository this merger will read and write data on.
-
Merger
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 Details
-
getRepository
Get the repository this merger operates on.- Returns:
- the repository this merger operates on.
-
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
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
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
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
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
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
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
Get resulting tree.- Returns:
- resulting tree, if
merge(AnyObjectId[])
returned true.
-
setProgressMonitor
Set a progress monitor.- Parameters:
monitor
- Monitor to use, can be null to indicate no progress reporting is desired.- Since:
- 4.2
-