use of com.google.gerrit.entities.Patch.MERGE_LIST in project gerrit by GerritCodeReview.
the class CommentContextLoader method getContext.
/**
* Load the comment context for multiple contextInputs at once. This method will open the
* repository and read the source files for all necessary contextInputs' file paths.
*
* @param contextInputs a list of contextInputs.
* @return a Map where all entries consist of the input contextInputs and the values are their
* corresponding {@link CommentContext}.
*/
public Map<ContextInput, CommentContext> getContext(Collection<ContextInput> contextInputs) throws IOException {
ImmutableMap.Builder<ContextInput, CommentContext> result = ImmutableMap.builderWithExpectedSize(Iterables.size(contextInputs));
// Group contextInputs by commit ID so that each commit is parsed only once
Map<ObjectId, List<ContextInput>> commentsByCommitId = contextInputs.stream().collect(groupingBy(ContextInput::commitId));
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
for (ObjectId commitId : commentsByCommitId.keySet()) {
RevCommit commit;
try {
commit = rw.parseCommit(commitId);
} catch (IncorrectObjectTypeException | MissingObjectException e) {
logger.atWarning().log("Commit %s is missing or has an incorrect object type", commitId);
commentsByCommitId.get(commitId).forEach(contextInput -> result.put(contextInput, CommentContext.empty()));
continue;
}
for (ContextInput contextInput : commentsByCommitId.get(commitId)) {
Optional<Range> range = getStartAndEndLines(contextInput);
if (!range.isPresent()) {
result.put(contextInput, CommentContext.empty());
continue;
}
String filePath = contextInput.filePath();
switch(filePath) {
case COMMIT_MSG:
result.put(contextInput, getContextForCommitMessage(rw.getObjectReader(), commit, range.get(), contextInput.contextPadding()));
break;
case MERGE_LIST:
result.put(contextInput, getContextForMergeList(rw.getObjectReader(), commit, range.get(), contextInput.contextPadding()));
break;
default:
result.put(contextInput, getContextForFilePath(repo, rw, commit, filePath, range.get(), contextInput.contextPadding()));
}
}
}
return result.build();
}
}
use of com.google.gerrit.entities.Patch.MERGE_LIST 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);
}
}
Aggregations