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 String
AUTO_MERGE_MSG_PREFIX
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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.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.
-
-
-
Field Detail
-
AUTO_MERGE_MSG_PREFIX
public static final String AUTO_MERGE_MSG_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
cacheAutomerge
public static boolean cacheAutomerge(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 anOptional
to be used in aBatchRefUpdate
.Optional.empty()
in case we don't need an auto merge commit. - Throws:
IOException
-
-