Search in sources :

Example 6 with ModifiedFile

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);
    }
}
Also used : DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) ModifiedFile(com.google.gerrit.server.patch.gitdiff.ModifiedFile) PatchSet(com.google.gerrit.entities.PatchSet) StorageException(com.google.gerrit.exceptions.StorageException)

Example 7 with ModifiedFile

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());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) ModifiedFile(com.google.gerrit.server.patch.gitdiff.ModifiedFile) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Test(org.junit.Test)

Example 8 with ModifiedFile

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());
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) ModifiedFile(com.google.gerrit.server.patch.gitdiff.ModifiedFile) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Test(org.junit.Test)

Aggregations

ModifiedFile (com.google.gerrit.server.patch.gitdiff.ModifiedFile)8 ObjectId (org.eclipse.jgit.lib.ObjectId)6 ObjectReader (org.eclipse.jgit.lib.ObjectReader)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 Map (java.util.Map)3 AutoValue (com.google.auto.value.AutoValue)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 FluentLogger (com.google.common.flogger.FluentLogger)2 Nullable (com.google.gerrit.common.Nullable)2 Patch (com.google.gerrit.entities.Patch)2 COMMIT_MSG (com.google.gerrit.entities.Patch.COMMIT_MSG)2 ChangeType (com.google.gerrit.entities.Patch.ChangeType)2 MERGE_LIST (com.google.gerrit.entities.Patch.MERGE_LIST)2 PatchSet (com.google.gerrit.entities.PatchSet)2 Project (com.google.gerrit.entities.Project)2 DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)2 Whitespace (com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace)2 CacheModule (com.google.gerrit.server.cache.CacheModule)2