use of com.google.gerrit.server.patch.gitdiff.ModifiedFile in project gerrit by GerritCodeReview.
the class ListOfFilesUnchangedPredicate method match.
@Override
public boolean match(ApprovalContext ctx) {
PatchSet targetPatchSet = ctx.target();
PatchSet sourcePatchSet = ctx.changeNotes().getPatchSets().get(ctx.patchSetApproval().patchSetId());
Integer parentNum = isInitialCommit(ctx.changeNotes().getProjectName(), targetPatchSet.commitId()) ? 0 : 1;
try {
Map<String, ModifiedFile> baseVsCurrent = diffOperations.loadModifiedFilesAgainstParent(ctx.changeNotes().getProjectName(), targetPatchSet.commitId(), parentNum, DiffOptions.DEFAULTS, ctx.revWalk(), ctx.repoConfig());
Map<String, ModifiedFile> baseVsPrior = diffOperations.loadModifiedFilesAgainstParent(ctx.changeNotes().getProjectName(), sourcePatchSet.commitId(), parentNum, DiffOptions.DEFAULTS, ctx.revWalk(), ctx.repoConfig());
Map<String, ModifiedFile> priorVsCurrent = diffOperations.loadModifiedFiles(ctx.changeNotes().getProjectName(), sourcePatchSet.commitId(), targetPatchSet.commitId(), DiffOptions.DEFAULTS, ctx.revWalk(), ctx.repoConfig());
return match(baseVsCurrent, baseVsPrior, priorVsCurrent);
} catch (DiffNotAvailableException ex) {
throw new StorageException("failed to compute difference in files, so won't copy" + " votes on labels even if list of files is the same and " + "copyAllIfListOfFilesDidNotChange", ex);
}
}
use of com.google.gerrit.server.patch.gitdiff.ModifiedFile in project gerrit by GerritCodeReview.
the class DiffOperationsTest method loadModifiedFiles_withSymlinkConvertedToRegularFile.
@Test
public void loadModifiedFiles_withSymlinkConvertedToRegularFile() throws Exception {
// Commit 1: Create a regular fileName1 with fileContent1
ImmutableList<FileEntity> oldFiles = ImmutableList.of(new FileEntity(fileName1, fileContent1));
ObjectId oldCommitId = createCommit(repo, null, oldFiles);
// Commit 2: Create a symlink with name FileName1 pointing to target file "target"
ImmutableList<FileEntity> newFiles = ImmutableList.of(new FileEntity(fileName1, "target", FileType.SYMLINK));
ObjectId newCommitId = createCommit(repo, oldCommitId, newFiles);
Repository repository = repoManager.openRepository(testProjectName);
ObjectReader objectReader = repository.newObjectReader();
Map<String, ModifiedFile> modifiedFiles = diffOperations.loadModifiedFiles(testProjectName, newCommitId, oldCommitId, DiffOptions.DEFAULTS, new RevWalk(objectReader), repository.getConfig());
assertThat(modifiedFiles).containsExactly(fileName1, ModifiedFile.builder().changeType(ChangeType.REWRITE).oldPath(Optional.empty()).newPath(Optional.of(fileName1)).build());
}
use of com.google.gerrit.server.patch.gitdiff.ModifiedFile in project gerrit by GerritCodeReview.
the class DiffOperationsTest method loadModifiedFilesAgainstParent.
@Test
public void loadModifiedFilesAgainstParent() throws Exception {
ImmutableList<FileEntity> oldFiles = ImmutableList.of(new FileEntity(fileName1, fileContent1), new FileEntity(fileName2, fileContent2));
ObjectId oldCommitId = createCommit(repo, null, oldFiles);
ImmutableList<FileEntity> newFiles = ImmutableList.of(new FileEntity(fileName1, fileContent1), new FileEntity(fileName2, fileContent2 + "\nnew line here"));
ObjectId newCommitId = createCommit(repo, oldCommitId, newFiles);
Repository repository = repoManager.openRepository(testProjectName);
ObjectReader objectReader = repository.newObjectReader();
RevWalk rw = new RevWalk(objectReader);
StoredConfig repoConfig = repository.getConfig();
// This call loads modified files directly without going through the diff cache.
Map<String, ModifiedFile> modifiedFiles = diffOperations.loadModifiedFilesAgainstParent(testProjectName, newCommitId, /* parentNum=*/
0, DiffOptions.DEFAULTS, rw, repoConfig);
assertThat(modifiedFiles).containsExactly(fileName2, ModifiedFile.builder().changeType(ChangeType.MODIFIED).oldPath(Optional.of(fileName2)).newPath(Optional.of(fileName2)).build());
}
Aggregations