Class Merger

    • Field Detail

      • db

        protected final Repository db
        The repository this merger operates on.
      • 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.
      • sourceObjects

        protected RevObject[] sourceObjects
        The original objects supplied in the merge; this can be any tree-ish.
    • 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.
      • 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().
      • 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 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()
        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

        @Deprecated
        public RevCommit getBaseCommit​(int aIdx,
                                       int bIdx)
                                throws IncorrectObjectTypeException,
                                       IOException
        Deprecated.
        use getBaseCommitId() instead, as that does not require walking the commits again
        Return the merge base of two commits.

        May only be called after #merge(RevCommit...).

        Parameters:
        aIdx - index of the first commit in tips passed to #merge(RevCommit...).
        bIdx - index of the second commit in tips passed to #merge(RevCommit...).
        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.
      • 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.