Class Merger

    • 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 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.
      • sourceObjects

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