Package com.google.gerrit.server.patch
Class DiffOperationsImpl
java.lang.Object
com.google.gerrit.server.patch.DiffOperationsImpl
- All Implemented Interfaces:
- DiffOperations
Provides different file diff operations. Uses the underlying Git/Gerrit caches to speed up the
 diff computation.
- 
Constructor SummaryConstructorsConstructorDescriptionDiffOperationsImpl(GitRepositoryManager repoManager, ModifiedFilesCache modifiedFilesCache, ModifiedFilesCacheImpl modifiedFilesCacheImpl, ModifiedFilesLoader.Factory modifiedFilesLoaderFactory, FileDiffCache fileDiffCache, com.google.gerrit.server.patch.BaseCommitUtil baseCommit) 
- 
Method SummaryModifier and TypeMethodDescriptiongetModifiedFile(Project.NameKey project, org.eclipse.jgit.lib.ObjectId oldCommit, org.eclipse.jgit.lib.ObjectId newCommit, String fileName, DiffPreferencesInfo.Whitespace whitespace) Returns the diff for a single file between two patchset commits.getModifiedFileAgainstParent(Project.NameKey project, org.eclipse.jgit.lib.ObjectId newCommit, int parent, String fileName, DiffPreferencesInfo.Whitespace whitespace) Returns the diff for a single file between a patchset commit against its parent or the auto-merge commit.listModifiedFiles(Project.NameKey project, org.eclipse.jgit.lib.ObjectId oldCommit, org.eclipse.jgit.lib.ObjectId newCommit, DiffOptions diffOptions) Returns the list of added, deleted or modified files between two commits (patchsets).listModifiedFilesAgainstParent(Project.NameKey project, org.eclipse.jgit.lib.ObjectId newCommit, int parent, DiffOptions diffOptions) Returns the list of added, deleted or modified files between a commit against its base.loadModifiedFilesAgainstParentIfNecessary(Project.NameKey project, org.eclipse.jgit.lib.ObjectId newCommit, int parentNum, RepoView repoView, org.eclipse.jgit.lib.ObjectInserter ins, boolean enableRenameDetection) This method is similar toDiffOperations.listModifiedFilesAgainstParent(NameKey, ObjectId, int, DiffOptions)but it loads the modified files directly if the modified files are not cached yet (instead of loading them via the diff cache).loadModifiedFilesIfNecessary(Project.NameKey project, org.eclipse.jgit.lib.ObjectId oldCommit, org.eclipse.jgit.lib.ObjectId newCommit, org.eclipse.jgit.revwalk.RevWalk revWalk, org.eclipse.jgit.lib.Config repoConfig, boolean enableRenameDetection) This method is similar toDiffOperations.listModifiedFilesAgainstParent(NameKey, ObjectId, int, DiffOptions)but it loads the modified files directly if the modified files are not cached yet (instead of loading them via the diff cache).static com.google.inject.Modulemodule()
- 
Constructor Details- 
DiffOperationsImpl@Inject public DiffOperationsImpl(GitRepositoryManager repoManager, ModifiedFilesCache modifiedFilesCache, ModifiedFilesCacheImpl modifiedFilesCacheImpl, ModifiedFilesLoader.Factory modifiedFilesLoaderFactory, FileDiffCache fileDiffCache, com.google.gerrit.server.patch.BaseCommitUtil baseCommit) 
 
- 
- 
Method Details- 
modulepublic static com.google.inject.Module module()
- 
listModifiedFilesAgainstParentpublic Map<String,FileDiffOutput> listModifiedFilesAgainstParent(Project.NameKey project, org.eclipse.jgit.lib.ObjectId newCommit, int parent, DiffOptions diffOptions) throws DiffNotAvailableException Description copied from interface:DiffOperationsReturns the list of added, deleted or modified files between a commit against its base. ThePatch.COMMIT_MSGandPatch.MERGE_LIST(for merge commits) are also returned.If parentNum is set, it is used as the old commit in the diff. Otherwise, if the newCommithas only one parent, it is used as base. IfnewCommithas two parents, the auto-merge commit is computed and used as base. The auto-merge for more than two parents is not supported.- Specified by:
- listModifiedFilesAgainstParentin interface- DiffOperations
- Parameters:
- project- a project name representing a git repository.
- newCommit- 20 bytes SHA-1 of the new commit used in the diff.
- parent- 1-based integer specifying which parent to use as base. If zero, the only parent will be used or the auto-merge if- newCommitis a merge commit.
- Returns:
- map of file paths to the file diffs. The map key is the new file path for all Patch.ChangeTypefile diffs exceptPatch.ChangeType.DELETEDentries where the map key contains the old file path. The map entries are not sorted by key.
- Throws:
- DiffNotAvailableException- if auto-merge is requested for a commit having more than two parents, if the- newCommitcould not be parsed for extracting the base commit, or if an internal error occurred in Git while evaluating the diff.
 
- 
loadModifiedFilesAgainstParentIfNecessarypublic Map<String,ModifiedFile> loadModifiedFilesAgainstParentIfNecessary(Project.NameKey project, org.eclipse.jgit.lib.ObjectId newCommit, int parentNum, RepoView repoView, org.eclipse.jgit.lib.ObjectInserter ins, boolean enableRenameDetection) throws DiffNotAvailableException Description copied from interface:DiffOperationsThis method is similar toDiffOperations.listModifiedFilesAgainstParent(NameKey, ObjectId, int, DiffOptions)but it loads the modified files directly if the modified files are not cached yet (instead of loading them via the diff cache).Commits are looked up from the provided RepoView. This way this method can also read new commits which are being created by the current request.- Specified by:
- loadModifiedFilesAgainstParentIfNecessaryin interface- DiffOperations
- repoView- view to the repo from which commits IDs are looked up
- ins-- ObjectInserterto be used to create the auto-merge if the diff is done for a merge commit against the auto-merge and the auto-merge ref doesn't exist yet. This may be an- InMemoryInserter.
- enableRenameDetection- whether rename detection should be enabled
- Returns:
- a map of file paths to ModifiedFile. TheModifiedFilecontains the old/new file paths and the change type (added, deleted, etc...).
- Throws:
- DiffNotAvailableException
 
- 
listModifiedFilespublic Map<String,FileDiffOutput> listModifiedFiles(Project.NameKey project, org.eclipse.jgit.lib.ObjectId oldCommit, org.eclipse.jgit.lib.ObjectId newCommit, DiffOptions diffOptions) throws DiffNotAvailableException Description copied from interface:DiffOperationsReturns the list of added, deleted or modified files between two commits (patchsets). The commit message and merge list (for merge commits) are also returned.- Specified by:
- listModifiedFilesin interface- DiffOperations
- Parameters:
- project- a project name representing a git repository.
- oldCommit- 20 bytes SHA-1 of the old commit used in the diff.
- newCommit- 20 bytes SHA-1 of the new commit used in the diff.
- Returns:
- map of file paths to the file diffs. The map key is the new file path for all Patch.ChangeTypefile diffs exceptPatch.ChangeType.DELETEDentries where the map key contains the old file path. The map entries are not sorted by key.
- Throws:
- DiffNotAvailableException- if an internal error occurred in Git while evaluating the diff.
 
- 
loadModifiedFilesIfNecessarypublic Map<String,ModifiedFile> loadModifiedFilesIfNecessary(Project.NameKey project, org.eclipse.jgit.lib.ObjectId oldCommit, org.eclipse.jgit.lib.ObjectId newCommit, org.eclipse.jgit.revwalk.RevWalk revWalk, org.eclipse.jgit.lib.Config repoConfig, boolean enableRenameDetection) throws DiffNotAvailableException Description copied from interface:DiffOperationsThis method is similar toDiffOperations.listModifiedFilesAgainstParent(NameKey, ObjectId, int, DiffOptions)but it loads the modified files directly if the modified files are not cached yet (instead of loading them via the diff cache).A RevWalk and repoConfig are also supplied and are used to look up the commit IDs. This is useful in case one the commits is currently being created, that's why the revWalkparameter is needed.- Specified by:
- loadModifiedFilesIfNecessaryin interface- DiffOperations
- enableRenameDetection- whether rename detection should be enabled
- Returns:
- a map of file paths to ModifiedFile. TheModifiedFilecontains the old/new file paths and the change type (added, deleted, etc...).
- Throws:
- DiffNotAvailableException
 
- 
getModifiedFileAgainstParentpublic FileDiffOutput getModifiedFileAgainstParent(Project.NameKey project, org.eclipse.jgit.lib.ObjectId newCommit, int parent, String fileName, DiffPreferencesInfo.Whitespace whitespace) throws DiffNotAvailableException Description copied from interface:DiffOperationsReturns the diff for a single file between a patchset commit against its parent or the auto-merge commit. For deleted files, thefileNameparameter should contain the old name of the file. This method will returnFileDiffOutput.empty(String, ObjectId, ObjectId)if the requested file identified byfileNamehas unchanged content or does not exist at both commits.- Specified by:
- getModifiedFileAgainstParentin interface- DiffOperations
- Parameters:
- project- a project name representing a git repository.
- newCommit- 20 bytes SHA-1 of the new commit used in the diff.
- parent- 1-based integer specifying which parent to use as base. If zero, the only parent will be used or the auto-merge if- newCommitis a merge commit.
- fileName- the file name for which the diff should be evaluated.
- whitespace- preference controlling whitespace effect in diff computation.
- Returns:
- the diff for the single file between the two commits.
- Throws:
- DiffNotAvailableException- if an internal error occurred in Git while evaluating the diff, or if an exception happened while parsing the base commit.
 
- 
getModifiedFilepublic FileDiffOutput getModifiedFile(Project.NameKey project, org.eclipse.jgit.lib.ObjectId oldCommit, org.eclipse.jgit.lib.ObjectId newCommit, String fileName, DiffPreferencesInfo.Whitespace whitespace) throws DiffNotAvailableException Description copied from interface:DiffOperationsReturns the diff for a single file between two patchset commits. For deleted files, thefileNameparameter should contain the old name of the file. This method will returnFileDiffOutput.empty(String, ObjectId, ObjectId)if the requested file identified byfileNamehas unchanged content or does not exist at both commits.- Specified by:
- getModifiedFilein interface- DiffOperations
- Parameters:
- project- a project name representing a git repository.
- oldCommit- 20 bytes SHA-1 of the old commit used in the diff.
- newCommit- 20 bytes SHA-1 of the new commit used in the diff.
- fileName- the file name for which the diff should be evaluated.
- whitespace- preference controlling whitespace effect in diff computation.
- Returns:
- the diff for the single file between the two commits.
- Throws:
- DiffNotAvailableException- if an internal error occurred in Git while evaluating the diff.
 
 
-