use of com.google.gerrit.server.patch.DiffNotAvailableException in project gerrit by GerritCodeReview.
the class CommentSender method getGroupedInlineComments.
/**
* Returns a list of FileCommentGroup objects representing the inline comments grouped by the
* file.
*/
private List<CommentSender.FileCommentGroup> getGroupedInlineComments(Repository repo) {
List<CommentSender.FileCommentGroup> groups = new ArrayList<>();
// Loop over the comments and collect them into groups based on the file
// location of the comment.
FileCommentGroup currentGroup = null;
for (Comment c : inlineComments) {
// If it's a new group:
if (currentGroup == null || !c.key.filename.equals(currentGroup.filename) || c.key.patchSetId != currentGroup.patchSetId) {
currentGroup = new FileCommentGroup();
currentGroup.filename = c.key.filename;
currentGroup.patchSetId = c.key.patchSetId;
// Get the modified files:
Map<String, FileDiffOutput> modifiedFiles = null;
try {
modifiedFiles = listModifiedFiles(c.key.patchSetId);
} catch (DiffNotAvailableException e) {
logger.atSevere().withCause(e).log("Failed to get modified files");
}
groups.add(currentGroup);
if (modifiedFiles != null && !modifiedFiles.isEmpty()) {
try {
currentGroup.fileData = new PatchFile(repo, modifiedFiles, c.key.filename);
} catch (IOException e) {
logger.atWarning().withCause(e).log("Cannot load %s from %s in %s", c.key.filename, modifiedFiles.values().iterator().next().newCommitId().name(), projectState.getName());
currentGroup.fileData = null;
}
}
}
if (currentGroup.filename.equals(PATCHSET_LEVEL) || currentGroup.fileData != null) {
currentGroup.comments.add(c);
}
}
groups.sort(Comparator.comparing(g -> g.filename, FilenameComparator.INSTANCE));
return groups;
}
use of com.google.gerrit.server.patch.DiffNotAvailableException in project gerrit by GerritCodeReview.
the class EventFactory method addPatchSetFileNames.
public void addPatchSetFileNames(PatchSetAttribute patchSetAttribute, Change change, PatchSet patchSet) {
try {
Map<String, FileDiffOutput> modifiedFiles = diffOperations.listModifiedFilesAgainstParent(change.getProject(), patchSet.commitId(), /* parentNum= */
0, DiffOptions.DEFAULTS);
for (FileDiffOutput diff : modifiedFiles.values()) {
if (patchSetAttribute.files == null) {
patchSetAttribute.files = new ArrayList<>();
}
PatchAttribute p = new PatchAttribute();
p.file = FilePathAdapter.getNewPath(diff.oldPath(), diff.newPath(), diff.changeType());
p.fileOld = FilePathAdapter.getOldPath(diff.oldPath(), diff.changeType());
p.type = diff.changeType();
p.deletions -= diff.deletions();
p.insertions = diff.insertions();
patchSetAttribute.files.add(p);
}
} catch (DiffNotAvailableException e) {
logger.atSevere().withCause(e).log("Cannot get patch list");
}
}
use of com.google.gerrit.server.patch.DiffNotAvailableException 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);
}
}
Aggregations