use of com.google.gerrit.entities.Patch.COMMIT_MSG in project gerrit by GerritCodeReview.
the class RevisionDiffIT method renamedUnrelatedFileIsIgnored_forPatchSetDiffWithRebase_whenEquallyModifiedInBoth.
@Test
@Ignore
public void renamedUnrelatedFileIsIgnored_forPatchSetDiffWithRebase_whenEquallyModifiedInBoth() throws Exception {
// TODO(ghareeb): fix this test for the new diff cache implementation
Function<String, String> contentModification = fileContent -> fileContent.replace("1st line\n", "First line\n");
addModifiedPatchSet(changeId, FILE_NAME2, contentModification);
String previousPatchSetId = gApi.changes().id(changeId).get().currentRevision;
// Revert the modification to be able to rebase.
addModifiedPatchSet(changeId, FILE_NAME2, fileContent -> fileContent.replace("First line\n", "1st line\n"));
String renamedFileName = "renamed_file.txt";
ObjectId commit2 = addCommitRenamingFile(commit1, FILE_NAME2, renamedFileName);
rebaseChangeOn(changeId, commit2);
addModifiedPatchSet(changeId, renamedFileName, contentModification);
addModifiedPatchSet(changeId, FILE_NAME, "Another line\n"::concat);
Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(previousPatchSetId);
assertThat(changedFiles.keySet()).containsExactly(COMMIT_MSG, FILE_NAME);
}
use of com.google.gerrit.entities.Patch.COMMIT_MSG 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.COMMIT_MSG 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.entities.Patch.COMMIT_MSG in project gerrit by GerritCodeReview.
the class RevisionDiffIT method unrelatedFileWhenRebasingOnAnotherChangeOrPatchSetIsIgnored.
/*
* change PS B
* |
* change PS A commit4
* | |
* commit2 commit3
* | /
* commit1 --------
*/
@Test
public void unrelatedFileWhenRebasingOnAnotherChangeOrPatchSetIsIgnored() throws Exception {
ObjectId commit2 = addCommit(commit1, FILE_NAME, FILE_CONTENT.replace("Line 5\n", "Line five\n"));
rebaseChangeOn(changeId, commit2);
String previousPatchSetId = gApi.changes().id(changeId).get().currentRevision;
ObjectId commit3 = addCommit(commit1, FILE_NAME2, FILE_CONTENT2.replace("2nd line\n", "Second line\n"));
ObjectId commit4 = addCommit(commit3, FILE_NAME, FILE_CONTENT.replace("Line 60\n", "Line sixty\n"));
rebaseChangeOn(changeId, commit4);
Function<String, String> contentModification = fileContent -> fileContent.replace("Line 20\n", "Line twenty\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification);
Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(previousPatchSetId);
assertThat(changedFiles.keySet()).containsExactly(COMMIT_MSG, FILE_NAME);
}
Aggregations