Class Merger

java.lang.Object
org.eclipse.jgit.merge.Merger
Direct Known Subclasses:
StrategyOneSided.OneSide, ThreeWayMerger

public abstract class Merger extends Object
Instance of a specific MergeStrategy for a single Repository.
  • Field Details

    • 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 use nonNullRepo().

    • reader

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

      protected RevWalk walk
      A RevWalk for computing merge bases, or listing incoming commits.
    • inserter

      private ObjectInserter inserter
    • 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.
    • monitor

      protected ProgressMonitor monitor
      A progress monitor.
      Since:
      4.2
  • Constructor Details

    • 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 of merge, unless flush is false.
      Since:
      4.8
  • Method Details

    • 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 to getRepository()
      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 by getRepository() (if a repository was provided). Will be closed at the conclusion of merge, unless flush 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 in sourceObjects.
      b - 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.
      Since:
      3.0
    • openTree

      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()
      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