use of com.google.gerrit.server.patch.filediff.FileDiffOutput 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.FileDiffOutput in project gerrit by GerritCodeReview.
the class DiffSummaryLoader method call.
@Override
public DiffSummary call() throws Exception {
ObjectId oldId = key.toPatchListKey().getOldId();
ObjectId newId = key.toPatchListKey().getNewId();
Map<String, FileDiffOutput> diffList = oldId == null ? diffOperations.listModifiedFilesAgainstParent(project, newId, /* parentNum= */
0, DiffOptions.DEFAULTS) : diffOperations.listModifiedFiles(project, oldId, newId, DiffOptions.DEFAULTS);
return toDiffSummary(diffList);
}
use of com.google.gerrit.server.patch.filediff.FileDiffOutput in project gerrit by GerritCodeReview.
the class DiffSummaryLoader method toDiffSummary.
private DiffSummary toDiffSummary(Map<String, FileDiffOutput> fileDiffs) {
List<String> r = new ArrayList<>(fileDiffs.size());
int linesInserted = 0;
int linesDeleted = 0;
for (String path : fileDiffs.keySet()) {
if (Patch.isMagic(path)) {
continue;
}
FileDiffOutput fileDiff = fileDiffs.get(path);
linesInserted += fileDiff.insertions();
linesDeleted += fileDiff.deletions();
switch(fileDiff.changeType()) {
case ADDED:
case MODIFIED:
case DELETED:
case COPIED:
case REWRITE:
r.add(FilePathAdapter.getNewPath(fileDiff.oldPath(), fileDiff.newPath(), fileDiff.changeType()));
break;
case RENAMED:
r.add(FilePathAdapter.getOldPath(fileDiff.oldPath(), fileDiff.changeType()));
r.add(FilePathAdapter.getNewPath(fileDiff.oldPath(), fileDiff.newPath(), fileDiff.changeType()));
break;
}
}
return new DiffSummary(r.stream().sorted().toArray(String[]::new), linesInserted, linesDeleted);
}
use of com.google.gerrit.server.patch.filediff.FileDiffOutput in project gerrit by GerritCodeReview.
the class ChangeEmail method getChangeDetail.
/**
* Create the change message and the affected file list.
*/
public String getChangeDetail() {
try {
StringBuilder detail = new StringBuilder();
if (patchSetInfo != null) {
detail.append(patchSetInfo.getMessage().trim()).append("\n");
} else {
detail.append(change.getSubject().trim()).append("\n");
}
if (patchSet != null) {
detail.append("---\n");
// Sort files by name.
TreeMap<String, FileDiffOutput> modifiedFiles = new TreeMap<>(listModifiedFiles());
for (FileDiffOutput fileDiff : modifiedFiles.values()) {
if (fileDiff.newPath().isPresent() && Patch.isMagic(fileDiff.newPath().get())) {
continue;
}
detail.append(fileDiff.changeType().getCode()).append(" ").append(FilePathAdapter.getNewPath(fileDiff.oldPath(), fileDiff.newPath(), fileDiff.changeType())).append("\n");
}
Integer insertions = modifiedFiles.values().stream().map(FileDiffOutput::insertions).reduce(0, Integer::sum);
Integer deletions = modifiedFiles.values().stream().map(FileDiffOutput::deletions).reduce(0, Integer::sum);
detail.append(MessageFormat.format(//
"" + //
"{0,choice,0#0 files|1#1 file|1<{0} files} changed, " + //
"{1,choice,0#0 insertions|1#1 insertion|1<{1} insertions}(+), " + //
"{2,choice,0#0 deletions|1#1 deletion|1<{2} deletions}(-)" + "\n", //
modifiedFiles.size() - 1, //
insertions, deletions));
detail.append("\n");
}
return detail.toString();
} catch (Exception err) {
logger.atWarning().withCause(err).log("Cannot format change detail");
return "";
}
}
use of com.google.gerrit.server.patch.filediff.FileDiffOutput 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;
}
Aggregations