use of com.google.gerrit.entities.Patch.ChangeType in project gerrit by GerritCodeReview.
the class DiffOperationsImpl method loadModifiedFilesWithoutCache.
/**
* Loads the modified file paths between two commits without inspecting the diff cache.
*/
private static Map<String, ModifiedFile> loadModifiedFilesWithoutCache(Project.NameKey project, DiffParameters diffParams, RevWalk revWalk, Config repoConfig) throws DiffNotAvailableException {
ObjectId newCommit = diffParams.newCommit();
ObjectId oldCommit = diffParams.baseCommit();
try {
ObjectReader reader = revWalk.getObjectReader();
List<DiffEntry> diffEntries;
try (DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE)) {
df.setReader(reader, repoConfig);
df.setDetectRenames(false);
diffEntries = df.scan(oldCommit.equals(ObjectId.zeroId()) ? null : oldCommit, newCommit);
}
List<ModifiedFile> modifiedFiles = diffEntries.stream().map(entry -> ModifiedFile.builder().changeType(toChangeType(entry.getChangeType())).oldPath(getGitPath(entry.getOldPath())).newPath(getGitPath(entry.getNewPath())).build()).collect(Collectors.toList());
return DiffUtil.mergeRewrittenModifiedFiles(modifiedFiles).stream().collect(ImmutableMap.toImmutableMap(ModifiedFile::getDefaultPath, Function.identity()));
} catch (IOException e) {
throw new DiffNotAvailableException(String.format("Failed to compute the modified files for project '%s'," + " old commit '%s', new commit '%s'.", project, oldCommit.name(), newCommit.name()), e);
}
}
use of com.google.gerrit.entities.Patch.ChangeType in project gerrit by GerritCodeReview.
the class PatchListEntry method readFrom.
static PatchListEntry readFrom(InputStream in) throws IOException {
ChangeType changeType = readEnum(in, ChangeType.values());
PatchType patchType = readEnum(in, PatchType.values());
String oldName = readString(in);
String newName = readString(in);
byte[] hdr = readBytes(in);
int ins = readVarInt32(in);
int del = readVarInt32(in);
long size = readFixInt64(in);
long sizeDelta = readFixInt64(in);
Edit[] editArray = readEditArray(in);
Edit[] editsDueToRebase = readEditArray(in);
return new PatchListEntry(changeType, patchType, oldName, newName, hdr, ImmutableList.copyOf(editArray), ImmutableSet.copyOf(editsDueToRebase), ins, del, size, sizeDelta);
}
Aggregations