Class DiffOperationsForCommitValidation

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

public class DiffOperationsForCommitValidation extends Object
Class to get modified files in CommitValidationListeners.

Computing the modified files for a merge commit may require the creation of the auto-merge commit (usually the auto-merge commit is not created yet when the commit validators are invoked). However commit validators should not write any commits (as the name CommitValidationListener suggests they are only intended to validate and listen). In particular commit validators must not write the auto-merge commit with a new ObjectInserter instance that competes with the main ObjectInserter instance that is being used to create changes, patch sets and auto-merge commits. This class wraps the computation of modified files and takes care of creating any missing auto-merge commit with the main ObjectInserter instance, so that the auto-merge commit is only created by this ObjectInserter instance and there is no competing ObjectInserter instance that creates the same auto-merge commit. Creating the same auto-merge commit with competing ObjectInserter instances must be avoided as it can result issues during object quorum.

  • Method Details

    • loadModifiedFilesAgainstParentIfNecessary

      public Map<String,ModifiedFile> loadModifiedFilesAgainstParentIfNecessary(Project.NameKey project, org.eclipse.jgit.lib.ObjectId newCommit, int parentNum, boolean enableRenameDetection) throws DiffNotAvailableException
      Retrieves the modified files from the ModifiedFilesCache if they are already cached. If not, the modified files are loaded directly (using the main RevWalk instance that can see newly inserted objects) rather than loading them via the ModifiedFilesCache (that would open a new RevWalk instance).

      If the loading requires the creation of the auto-merge commit it is created with the main ObjectInserter instance (also see the class javadoc).

      The results will be stored in the ModifiedFilesCache so that calling this method multiple times loads the modified files only once (for the first call, for further calls the cached modified files are returned).

      Throws:
      DiffNotAvailableException