use of com.google.gerrit.server.patch.filediff.FileDiffCacheKey in project gerrit by GerritCodeReview.
the class DiffOperationsImpl method getModifiedFilesForKeys.
/**
* Lookup the file diffs for the input {@code keys}. For results where the cache reports negative
* results, e.g. due to timeouts in the cache loader, this method requests the diff again using
* the fallback algorithm {@link DiffAlgorithm#HISTOGRAM_NO_FALLBACK}.
*/
private ImmutableMap<String, FileDiffOutput> getModifiedFilesForKeys(List<FileDiffCacheKey> keys, DiffOptions diffOptions) throws DiffNotAvailableException {
ImmutableMap<FileDiffCacheKey, FileDiffOutput> fileDiffs = fileDiffCache.getAll(keys);
List<FileDiffCacheKey> fallbackKeys = new ArrayList<>();
ImmutableList.Builder<FileDiffOutput> result = ImmutableList.builder();
// Use the fallback diff algorithm for negative results
for (FileDiffCacheKey key : fileDiffs.keySet()) {
FileDiffOutput diff = fileDiffs.get(key);
if (diff.isNegative()) {
FileDiffCacheKey fallbackKey = createFileDiffCacheKey(key.project(), key.oldCommit(), key.newCommit(), key.newFilePath(), // Use the fallback diff algorithm
DiffAlgorithm.HISTOGRAM_NO_FALLBACK, /* useTimeout= */
false, key.whitespace());
fallbackKeys.add(fallbackKey);
} else {
result.add(diff);
}
}
result.addAll(fileDiffCache.getAll(fallbackKeys).values());
return mapByFilePath(result.build(), diffOptions);
}
use of com.google.gerrit.server.patch.filediff.FileDiffCacheKey in project gerrit by GerritCodeReview.
the class DiffOperationsImpl method getModifiedFileAgainstParent.
@Override
public FileDiffOutput getModifiedFileAgainstParent(Project.NameKey project, ObjectId newCommit, int parent, String fileName, @Nullable DiffPreferencesInfo.Whitespace whitespace) throws DiffNotAvailableException {
try {
DiffParameters diffParams = computeDiffParameters(project, newCommit, parent);
FileDiffCacheKey key = createFileDiffCacheKey(project, diffParams.baseCommit(), newCommit, fileName, DEFAULT_DIFF_ALGORITHM, /* useTimeout= */
true, whitespace);
return getModifiedFileForKey(key);
} catch (IOException e) {
throw new DiffNotAvailableException("Failed to evaluate the parent/base commit for commit " + newCommit, e);
}
}
use of com.google.gerrit.server.patch.filediff.FileDiffCacheKey in project gerrit by GerritCodeReview.
the class DiffOperationsImpl method getModifiedFiles.
private ImmutableMap<String, FileDiffOutput> getModifiedFiles(DiffParameters diffParams, DiffOptions diffOptions) throws DiffNotAvailableException {
try {
Project.NameKey project = diffParams.project();
ObjectId newCommit = diffParams.newCommit();
ObjectId oldCommit = diffParams.baseCommit();
ComparisonType cmp = diffParams.comparisonType();
ImmutableList<ModifiedFile> modifiedFiles = modifiedFilesCache.get(createModifiedFilesKey(project, oldCommit, newCommit));
List<FileDiffCacheKey> fileCacheKeys = new ArrayList<>();
fileCacheKeys.add(createFileDiffCacheKey(project, oldCommit, newCommit, COMMIT_MSG, DEFAULT_DIFF_ALGORITHM, /* useTimeout= */
true, /* whitespace= */
null));
if (cmp.isAgainstAutoMerge() || isMergeAgainstParent(cmp, project, newCommit)) {
fileCacheKeys.add(createFileDiffCacheKey(project, oldCommit, newCommit, MERGE_LIST, DEFAULT_DIFF_ALGORITHM, /* useTimeout= */
true, /*whitespace = */
null));
}
if (diffParams.skipFiles() == null) {
modifiedFiles.stream().map(entity -> createFileDiffCacheKey(project, oldCommit, newCommit, entity.newPath().isPresent() ? entity.newPath().get() : entity.oldPath().get(), DEFAULT_DIFF_ALGORITHM, /* useTimeout= */
true, /* whitespace= */
null)).forEach(fileCacheKeys::add);
}
return getModifiedFilesForKeys(fileCacheKeys, diffOptions);
} catch (IOException e) {
throw new DiffNotAvailableException(e);
}
}
use of com.google.gerrit.server.patch.filediff.FileDiffCacheKey in project gerrit by GerritCodeReview.
the class FileDiffCacheKeySerializerTest method roundTrip.
@Test
public void roundTrip() {
FileDiffCacheKey key = FileDiffCacheKey.builder().project(Project.nameKey("project/x")).oldCommit(COMMIT_ID_1).newCommit(COMMIT_ID_2).newFilePath("some_file.txt").renameScore(65).diffAlgorithm(DiffAlgorithm.HISTOGRAM_WITH_FALLBACK_MYERS).whitespace(Whitespace.IGNORE_ALL).useTimeout(true).build();
byte[] serialized = FileDiffCacheKey.Serializer.INSTANCE.serialize(key);
assertThat(FileDiffCacheKey.Serializer.INSTANCE.deserialize(serialized)).isEqualTo(key);
}
Aggregations