Class AutoMerger

java.lang.Object
com.google.gerrit.server.patch.AutoMerger

public class AutoMerger extends Object
Utility class for creating an auto-merge commit of a merge commit.

An auto-merge commit is the result of merging the 2 parents of a merge commit automatically. If there are conflicts the auto-merge commit contains Git conflict markers that indicate these conflicts.

Creating auto-merge commits for octopus merges (merge commits with more than 2 parents) is not supported. In this case the auto-merge is created between the first 2 parent commits.

All created auto-merge commits are stored in the repository of their merge commit as refs/cache-automerge/ branches. These branches serve:

  • as a cache so that the each auto-merge gets computed only once
  • as base for merge commits on which users can comment

The second point means that these commits are referenced from NoteDb. The consequence of this is that these refs should never be deleted.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    cacheAutomerge(org.eclipse.jgit.lib.Config cfg)
     
    Optional<org.eclipse.jgit.transport.ReceiveCommand>
    createAutoMergeCommitIfNecessary(RepoView repoView, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectInserter ins, org.eclipse.jgit.revwalk.RevCommit maybeMergeCommit)
    Creates an auto merge commit for the provided commit in case it is a merge commit.
    static boolean
    diff3ConflictView(org.eclipse.jgit.lib.Config cfg)
     
    org.eclipse.jgit.revwalk.RevCommit
    lookupFromGitOrMergeInMemory(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevWalk rw, InMemoryInserter ins, org.eclipse.jgit.revwalk.RevCommit merge, org.eclipse.jgit.merge.ThreeWayMergeStrategy mergeStrategy)
    Reads or creates an auto-merge commit of the parents of the given merge commit.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • cacheAutomerge

      public static boolean cacheAutomerge(org.eclipse.jgit.lib.Config cfg)
    • diff3ConflictView

      public static boolean diff3ConflictView(org.eclipse.jgit.lib.Config cfg)
    • lookupFromGitOrMergeInMemory

      public org.eclipse.jgit.revwalk.RevCommit lookupFromGitOrMergeInMemory(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevWalk rw, InMemoryInserter ins, org.eclipse.jgit.revwalk.RevCommit merge, org.eclipse.jgit.merge.ThreeWayMergeStrategy mergeStrategy) throws IOException
      Reads or creates an auto-merge commit of the parents of the given merge commit.

      The result is read from Git or computed in-memory and not written back to Git. This method exists for backwards compatibility only. All new changes have their auto-merge commits written transactionally when the change or patch set is created.

      Returns:
      auto-merge commit. Headers of the returned RevCommit are parsed.
      Throws:
      IOException
    • createAutoMergeCommitIfNecessary

      public Optional<org.eclipse.jgit.transport.ReceiveCommand> createAutoMergeCommitIfNecessary(RepoView repoView, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectInserter ins, org.eclipse.jgit.revwalk.RevCommit maybeMergeCommit) throws IOException
      Creates an auto merge commit for the provided commit in case it is a merge commit. To be used whenever Gerrit creates new patch sets.

      Callers need to include the returned ReceiveCommand in their ref transaction.

      Returns:
      A ReceiveCommand wrapped in an Optional to be used in a BatchRefUpdate. Optional.empty() in case we don't need an auto merge commit.
      Throws:
      IOException