org.eclipse.jgit.merge
Class Merger

java.lang.Object
  extended by org.eclipse.jgit.merge.Merger
Direct Known Subclasses:
ThreeWayMerger

public abstract class Merger
extends Object

Instance of a specific MergeStrategy for a single Repository.


Field Summary
protected  Repository db
          The repository this merger operates on.
protected  ObjectReader reader
          Reader to support walk and other object loading.
protected  RevCommit[] sourceCommits
          If sourceObjects[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 in sourceObjects.
protected  RevWalk walk
          A RevWalk for computing merge bases, or listing incoming commits.
 
Constructor Summary
protected Merger(Repository local)
          Create a new merge instance for a repository.
 
Method Summary
 RevCommit getBaseCommit(int aIdx, int bIdx)
          Return the merge base of two commits.
 ObjectInserter getObjectInserter()
           
 Repository getRepository()
           
abstract  ObjectId getResultTreeId()
           
 boolean merge(AnyObjectId... tips)
          Merge together two or more tree-ish objects.
protected  AbstractTreeIterator mergeBase(int aIdx, int bIdx)
          Create an iterator to walk the merge base of two commits.
protected abstract  boolean mergeImpl()
          Execute the merge.
protected  AbstractTreeIterator openTree(AnyObjectId treeId)
          Open an iterator over a tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db

protected final Repository db
The repository this merger operates on.


reader

protected final ObjectReader reader
Reader to support walk and other object loading.


walk

protected final 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
If sourceObjects[i] is a commit, this is the commit.


sourceTrees

protected RevTree[] sourceTrees
The trees matching every entry in sourceObjects.

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.
Method Detail

getRepository

public Repository getRepository()
Returns:
the repository this merger operates on.

getObjectInserter

public ObjectInserter getObjectInserter()
Returns:
an object writer to create objects in getRepository().

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.

mergeBase

protected AbstractTreeIterator mergeBase(int aIdx,
                                         int bIdx)
                                  throws IOException
Create an iterator to walk the merge base of two commits.

Parameters:
aIdx - index of the first commit in sourceObjects.
bIdx - index of the second commit in sourceObjects.
Returns:
the new iterator
Throws:
IncorrectObjectTypeException - one of the input objects is not a commit.
IOException - objects are missing or multiple merge bases were found.

getBaseCommit

public RevCommit getBaseCommit(int aIdx,
                               int bIdx)
                        throws IncorrectObjectTypeException,
                               IOException
Return the merge base of two commits.

Parameters:
aIdx - index of the first commit in sourceObjects.
bIdx - index of the second commit in sourceObjects.
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.

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 the sourceObjects, sourceCommits and sourceTrees 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()
Returns:
resulting tree, if merge(AnyObjectId[]) returned true.


Copyright © 2012. All Rights Reserved.