本文整理汇总了Java中com.google.gerrit.extensions.common.DiffInfo类的典型用法代码示例。如果您正苦于以下问题:Java DiffInfo类的具体用法?Java DiffInfo怎么用?Java DiffInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DiffInfo类属于com.google.gerrit.extensions.common包,在下文中一共展示了DiffInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
private DiffInfo get(DiffRequest r) throws RestApiException {
if (r.getBase() != null) {
getDiff.setBase(r.getBase());
}
if (r.getContext() != null) {
getDiff.setContext(r.getContext());
}
if (r.getIntraline() != null) {
getDiff.setIntraline(r.getIntraline());
}
if (r.getWhitespace() != null) {
getDiff.setWhitespace(r.getWhitespace());
}
r.getParent().ifPresent(getDiff::setParent);
try {
return getDiff.apply(file).value();
} catch (Exception e) {
throw asRestApiException("Cannot retrieve diff", e);
}
}
示例2: diffOnMergeCommitChange
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Test
public void diffOnMergeCommitChange() throws Exception {
PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
DiffInfo diff;
// automerge
diff = getDiffRequest(r.getChangeId(), r.getCommit().name(), "foo").get();
assertThat(diff.metaA.lines).isEqualTo(5);
assertThat(diff.metaB.lines).isEqualTo(1);
diff = getDiffRequest(r.getChangeId(), r.getCommit().name(), "bar").get();
assertThat(diff.metaA.lines).isEqualTo(5);
assertThat(diff.metaB.lines).isEqualTo(1);
// parent 1
diff = getDiffRequest(r.getChangeId(), r.getCommit().name(), "bar").withParent(1).get();
assertThat(diff.metaA.lines).isEqualTo(1);
assertThat(diff.metaB.lines).isEqualTo(1);
// parent 2
diff = getDiffRequest(r.getChangeId(), r.getCommit().name(), "foo").withParent(2).get();
assertThat(diff.metaA.lines).isEqualTo(1);
assertThat(diff.metaB.lines).isEqualTo(1);
}
示例3: deletedFileDuringRebaseConsideredAsRegularHunkWhenModifiedInDiff
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Test
public void deletedFileDuringRebaseConsideredAsRegularHunkWhenModifiedInDiff() throws Exception {
// Modify the file and revert the modifications to allow rebasing.
addModifiedPatchSet(
changeId, FILE_NAME, fileContent -> fileContent.replace("Line 50\n", "Line fifty\n"));
String previousPatchSetId = gApi.changes().id(changeId).get().currentRevision;
addModifiedPatchSet(
changeId, FILE_NAME, fileContent -> fileContent.replace("Line fifty\n", "Line 50\n"));
ObjectId commit2 = addCommitRemovingFiles(commit1, FILE_NAME);
rebaseChangeOn(changeId, commit2);
DiffInfo diffInfo =
getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(previousPatchSetId).get();
assertThat(diffInfo).changeType().isEqualTo(ChangeType.DELETED);
assertThat(diffInfo).content().element(0).linesOfA().hasSize(100);
assertThat(diffInfo).content().element(0).linesOfB().isNull();
assertThat(diffInfo).content().element(0).isNotDueToRebase();
Map<String, FileInfo> changedFiles =
gApi.changes().id(changeId).current().files(previousPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isNull();
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(100);
}
示例4: addedFileDuringRebaseConsideredAsRegularHunkWhenModifiedInDiff
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Test
public void addedFileDuringRebaseConsideredAsRegularHunkWhenModifiedInDiff() throws Exception {
String newFilePath = "a_new_file.txt";
ObjectId commit2 = addCommit(commit1, newFilePath, "1st line\n2nd line\n3rd line\n");
rebaseChangeOn(changeId, commit2);
addModifiedPatchSet(
changeId, newFilePath, fileContent -> fileContent.replace("1st line\n", "First line\n"));
DiffInfo diffInfo =
getDiffRequest(changeId, CURRENT, newFilePath).withBase(initialPatchSetId).get();
assertThat(diffInfo).changeType().isEqualTo(ChangeType.ADDED);
assertThat(diffInfo).content().element(0).linesOfA().isNull();
assertThat(diffInfo).content().element(0).linesOfB().hasSize(3);
assertThat(diffInfo).content().element(0).isNotDueToRebase();
Map<String, FileInfo> changedFiles =
gApi.changes().id(changeId).current().files(initialPatchSetId);
assertThat(changedFiles.get(newFilePath)).linesInserted().isEqualTo(3);
assertThat(changedFiles.get(newFilePath)).linesDeleted().isNull();
}
示例5: diff
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
private DiffInfo diff(DiffRequest diffRequest) throws RestApiException {
String query = "";
if (!Strings.isNullOrEmpty(diffRequest.getBase())) {
query = UrlUtils.appendToUrlQuery(query, "base=" + diffRequest.getBase());
}
if (diffRequest.getContext() != null) {
query = UrlUtils.appendToUrlQuery(query, "context=" + diffRequest.getContext());
}
if (diffRequest.getIntraline() != null) {
query = UrlUtils.appendToUrlQuery(query, "intraline=" + diffRequest.getIntraline());
}
if (diffRequest.getWhitespace() != null) {
query = UrlUtils.appendToUrlQuery(query, "whitespace=" + diffRequest.getWhitespace());
}
String url = getRequestPath() + "/diff";
if (!Strings.isNullOrEmpty(query)) {
url += '?' + query;
}
JsonElement jsonElement = gerritRestClient.getRequest(url);
return diffInfoParser.parseDiffInfo(jsonElement);
}
示例6: testDiff
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
private void testDiff(Function<FileApiRestClient, Void> method, String expectedRequestUrl) throws Exception {
JsonElement jsonElement = EasyMock.createMock(JsonElement.class);
DiffInfo diffInfo = EasyMock.createMock(DiffInfo.class);
DiffInfoParser diffInfoParser = EasyMock.createMock(DiffInfoParser.class);
EasyMock.expect(diffInfoParser.parseDiffInfo(jsonElement)).andReturn(diffInfo).once();
EasyMock.replay(diffInfoParser);
setupServices();
GerritRestClient gerritRestClient = new GerritRestClientBuilder().expectGet(expectedRequestUrl, jsonElement).get();
FileApiRestClient fileApiRestClient = new FileApiRestClient(gerritRestClient, revisionApiRestClient, diffInfoParser, FILE_PATH);
method.apply(fileApiRestClient);
EasyMock.verify(gerritRestClient, diffInfoParser);
}
示例7: assertDiffForNewFile
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
protected void assertDiffForNewFile(
DiffInfo diff, RevCommit commit, String path, String expectedContentSideB) throws Exception {
List<String> expectedLines = new ArrayList<>();
for (String line : expectedContentSideB.split("\n")) {
expectedLines.add(line);
}
assertThat(diff.binary).isNull();
assertThat(diff.changeType).isEqualTo(ChangeType.ADDED);
assertThat(diff.diffHeader).isNotNull();
assertThat(diff.intralineStatus).isNull();
assertThat(diff.webLinks).isNull();
assertThat(diff.metaA).isNull();
assertThat(diff.metaB).isNotNull();
assertThat(diff.metaB.commitId).isEqualTo(commit.name());
String expectedContentType = "text/plain";
if (COMMIT_MSG.equals(path)) {
expectedContentType = FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE;
} else if (MERGE_LIST.equals(path)) {
expectedContentType = FileContentUtil.TEXT_X_GERRIT_MERGE_LIST;
}
assertThat(diff.metaB.contentType).isEqualTo(expectedContentType);
assertThat(diff.metaB.lines).isEqualTo(expectedLines.size());
assertThat(diff.metaB.name).isEqualTo(path);
assertThat(diff.metaB.webLinks).isNull();
assertThat(diff.content).hasSize(1);
DiffInfo.ContentEntry contentEntry = diff.content.get(0);
assertThat(contentEntry.b).containsExactlyElementsIn(expectedLines).inOrder();
assertThat(contentEntry.a).isNull();
assertThat(contentEntry.ab).isNull();
assertThat(contentEntry.common).isNull();
assertThat(contentEntry.editA).isNull();
assertThat(contentEntry.editB).isNull();
assertThat(contentEntry.skip).isNull();
}
示例8: diff
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Override
public DiffInfo diff() throws RestApiException {
try {
return getDiff.apply(file).value();
} catch (Exception e) {
throw asRestApiException("Cannot retrieve diff", e);
}
}
示例9: diffRequest
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Override
public DiffRequest diffRequest() {
return new DiffRequest() {
@Override
public DiffInfo get() throws RestApiException {
return FileApiImpl.this.get(this);
}
};
}
示例10: diffDeletedFile
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Test
public void diffDeletedFile() throws Exception {
gApi.changes().id(changeId).edit().deleteFile(FILE_NAME);
gApi.changes().id(changeId).edit().publish();
Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files();
assertThat(changedFiles.keySet()).containsExactly(COMMIT_MSG, FILE_NAME);
DiffInfo diff = getDiffRequest(changeId, CURRENT, FILE_NAME).get();
assertThat(diff.metaA.lines).isEqualTo(100);
assertThat(diff.metaB).isNull();
}
示例11: rebaseHunksAtStartOfFileAreIdentified
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Test
public void rebaseHunksAtStartOfFileAreIdentified() throws Exception {
String newFileContent =
FILE_CONTENT.replace("Line 1\n", "Line one\n").replace("Line 5\n", "Line five\n");
ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
rebaseChangeOn(changeId, commit2);
Function<String, String> contentModification =
fileContent -> fileContent.replace("Line 50\n", "Line fifty\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification);
DiffInfo diffInfo =
getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(initialPatchSetId).get();
assertThat(diffInfo).content().element(0).linesOfA().containsExactly("Line 1");
assertThat(diffInfo).content().element(0).linesOfB().containsExactly("Line one");
assertThat(diffInfo).content().element(0).isDueToRebase();
assertThat(diffInfo).content().element(1).commonLines().hasSize(3);
assertThat(diffInfo).content().element(2).linesOfA().containsExactly("Line 5");
assertThat(diffInfo).content().element(2).linesOfB().containsExactly("Line five");
assertThat(diffInfo).content().element(2).isDueToRebase();
assertThat(diffInfo).content().element(3).commonLines().hasSize(44);
assertThat(diffInfo).content().element(4).linesOfA().containsExactly("Line 50");
assertThat(diffInfo).content().element(4).linesOfB().containsExactly("Line fifty");
assertThat(diffInfo).content().element(4).isNotDueToRebase();
assertThat(diffInfo).content().element(5).commonLines().hasSize(50);
Map<String, FileInfo> changedFiles =
gApi.changes().id(changeId).current().files(initialPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(1);
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}
示例12: rebaseHunksAtEndOfFileAreIdentified
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Test
public void rebaseHunksAtEndOfFileAreIdentified() throws Exception {
String newFileContent =
FILE_CONTENT
.replace("Line 60\n", "Line sixty\n")
.replace("Line 100\n", "Line one hundred\n");
ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
rebaseChangeOn(changeId, commit2);
Function<String, String> contentModification =
fileContent -> fileContent.replace("Line 50\n", "Line fifty\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification);
DiffInfo diffInfo =
getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(initialPatchSetId).get();
assertThat(diffInfo).content().element(0).commonLines().hasSize(49);
assertThat(diffInfo).content().element(1).linesOfA().containsExactly("Line 50");
assertThat(diffInfo).content().element(1).linesOfB().containsExactly("Line fifty");
assertThat(diffInfo).content().element(1).isNotDueToRebase();
assertThat(diffInfo).content().element(2).commonLines().hasSize(9);
assertThat(diffInfo).content().element(3).linesOfA().containsExactly("Line 60");
assertThat(diffInfo).content().element(3).linesOfB().containsExactly("Line sixty");
assertThat(diffInfo).content().element(3).isDueToRebase();
assertThat(diffInfo).content().element(4).commonLines().hasSize(39);
assertThat(diffInfo).content().element(5).linesOfA().containsExactly("Line 100");
assertThat(diffInfo).content().element(5).linesOfB().containsExactly("Line one hundred");
assertThat(diffInfo).content().element(5).isDueToRebase();
Map<String, FileInfo> changedFiles =
gApi.changes().id(changeId).current().files(initialPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(1);
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}
示例13: rebaseHunksInBetweenRegularHunksAreIdentified
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Test
public void rebaseHunksInBetweenRegularHunksAreIdentified() throws Exception {
String newFileContent =
FILE_CONTENT.replace("Line 40\n", "Line forty\n").replace("Line 45\n", "Line forty five\n");
ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
rebaseChangeOn(changeId, commit2);
Function<String, String> contentModification =
fileContent ->
fileContent
.replace("Line 1\n", "Line one\n")
.replace("Line 100\n", "Line one hundred\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification);
DiffInfo diffInfo =
getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(initialPatchSetId).get();
assertThat(diffInfo).content().element(0).linesOfA().containsExactly("Line 1");
assertThat(diffInfo).content().element(0).linesOfB().containsExactly("Line one");
assertThat(diffInfo).content().element(0).isNotDueToRebase();
assertThat(diffInfo).content().element(1).commonLines().hasSize(38);
assertThat(diffInfo).content().element(2).linesOfA().containsExactly("Line 40");
assertThat(diffInfo).content().element(2).linesOfB().containsExactly("Line forty");
assertThat(diffInfo).content().element(2).isDueToRebase();
assertThat(diffInfo).content().element(3).commonLines().hasSize(4);
assertThat(diffInfo).content().element(4).linesOfA().containsExactly("Line 45");
assertThat(diffInfo).content().element(4).linesOfB().containsExactly("Line forty five");
assertThat(diffInfo).content().element(4).isDueToRebase();
assertThat(diffInfo).content().element(5).commonLines().hasSize(54);
assertThat(diffInfo).content().element(6).linesOfA().containsExactly("Line 100");
assertThat(diffInfo).content().element(6).linesOfB().containsExactly("Line one hundred");
assertThat(diffInfo).content().element(6).isNotDueToRebase();
Map<String, FileInfo> changedFiles =
gApi.changes().id(changeId).current().files(initialPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(2);
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(2);
}
示例14: rebaseHunkIsIdentifiedWhenMovedDownInPreviousPatchSet
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Test
public void rebaseHunkIsIdentifiedWhenMovedDownInPreviousPatchSet() throws Exception {
// Move the code down by introducing additional lines (pure insert + enlarging replacement) in
// the previous patch set.
Function<String, String> contentModification1 =
fileContent ->
"Line zero\n" + fileContent.replace("Line 10\n", "Line ten\nLine ten and a half\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification1);
String previousPatchSetId = gApi.changes().id(changeId).get().currentRevision;
String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
rebaseChangeOn(changeId, commit2);
Function<String, String> contentModification2 =
fileContent -> fileContent.replace("Line 100\n", "Line one hundred\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification2);
DiffInfo diffInfo =
getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(previousPatchSetId).get();
assertThat(diffInfo).content().element(0).commonLines().hasSize(41);
assertThat(diffInfo).content().element(1).linesOfA().containsExactly("Line 40");
assertThat(diffInfo).content().element(1).linesOfB().containsExactly("Line forty");
assertThat(diffInfo).content().element(1).isDueToRebase();
assertThat(diffInfo).content().element(2).commonLines().hasSize(59);
assertThat(diffInfo).content().element(3).linesOfA().containsExactly("Line 100");
assertThat(diffInfo).content().element(3).linesOfB().containsExactly("Line one hundred");
assertThat(diffInfo).content().element(3).isNotDueToRebase();
Map<String, FileInfo> changedFiles =
gApi.changes().id(changeId).current().files(previousPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(1);
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}
示例15: rebaseHunkIsIdentifiedWhenMovedDownInLatestPatchSet
import com.google.gerrit.extensions.common.DiffInfo; //导入依赖的package包/类
@Test
public void rebaseHunkIsIdentifiedWhenMovedDownInLatestPatchSet() throws Exception {
String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
rebaseChangeOn(changeId, commit2);
// Move the code down by introducing additional lines (pure insert + enlarging replacement) in
// the latest patch set.
Function<String, String> contentModification =
fileContent ->
"Line zero\n" + fileContent.replace("Line 10\n", "Line ten\nLine ten and a half\n");
addModifiedPatchSet(changeId, FILE_NAME, contentModification);
DiffInfo diffInfo =
getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(initialPatchSetId).get();
assertThat(diffInfo).content().element(0).linesOfA().isNull();
assertThat(diffInfo).content().element(0).linesOfB().containsExactly("Line zero");
assertThat(diffInfo).content().element(0).isNotDueToRebase();
assertThat(diffInfo).content().element(1).commonLines().hasSize(9);
assertThat(diffInfo).content().element(2).linesOfA().containsExactly("Line 10");
assertThat(diffInfo)
.content()
.element(2)
.linesOfB()
.containsExactly("Line ten", "Line ten and a half");
assertThat(diffInfo).content().element(2).isNotDueToRebase();
assertThat(diffInfo).content().element(3).commonLines().hasSize(29);
assertThat(diffInfo).content().element(4).linesOfA().containsExactly("Line 40");
assertThat(diffInfo).content().element(4).linesOfB().containsExactly("Line forty");
assertThat(diffInfo).content().element(4).isDueToRebase();
assertThat(diffInfo).content().element(5).commonLines().hasSize(60);
Map<String, FileInfo> changedFiles =
gApi.changes().id(changeId).current().files(initialPatchSetId);
assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(3);
assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}