Merge "FileEdits: Simplify instance creation"
diff --git a/java/com/google/gerrit/server/patch/filediff/FileDiffCacheImpl.java b/java/com/google/gerrit/server/patch/filediff/FileDiffCacheImpl.java
index d20cfe4..b2a628b 100644
--- a/java/com/google/gerrit/server/patch/filediff/FileDiffCacheImpl.java
+++ b/java/com/google/gerrit/server/patch/filediff/FileDiffCacheImpl.java
@@ -14,6 +14,7 @@
package com.google.gerrit.server.patch.filediff;
+import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.Constants.EMPTY_TREE_ID;
@@ -457,9 +458,7 @@
new EditTransformer(
ImmutableList.of(
FileEdits.create(
- parentVsParentDiff.edits().stream()
- .map(Edit::toJGitEdit)
- .collect(Collectors.toList()),
+ parentVsParentDiff.edits().stream().collect(toImmutableList()),
parentVsParentDiff.oldPath(),
parentVsParentDiff.newPath())));
@@ -468,9 +467,7 @@
editTransformer.transformReferencesOfSideA(
ImmutableList.of(
FileEdits.create(
- oldVsParDiff.edits().stream()
- .map(Edit::toJGitEdit)
- .collect(Collectors.toList()),
+ oldVsParDiff.edits().stream().collect(toImmutableList()),
oldVsParDiff.oldPath(),
oldVsParDiff.newPath())));
}
@@ -480,9 +477,7 @@
editTransformer.transformReferencesOfSideB(
ImmutableList.of(
FileEdits.create(
- newVsParDiff.edits().stream()
- .map(Edit::toJGitEdit)
- .collect(Collectors.toList()),
+ newVsParDiff.edits().stream().collect(toImmutableList()),
newVsParDiff.oldPath(),
newVsParDiff.newPath())));
}
@@ -501,7 +496,8 @@
.map(ContextAwareEdit::toEdit)
.filter(Optional::isPresent)
.map(Optional::get)
- .collect(Collectors.toList()),
+ .map(Edit::fromJGitEdit)
+ .collect(toImmutableList()),
edits.iterator().next().getOldFilePath(),
edits.iterator().next().getNewFilePath());
}
diff --git a/java/com/google/gerrit/server/patch/filediff/FileEdits.java b/java/com/google/gerrit/server/patch/filediff/FileEdits.java
index 376bbc2..a009a02 100644
--- a/java/com/google/gerrit/server/patch/filediff/FileEdits.java
+++ b/java/com/google/gerrit/server/patch/filediff/FileEdits.java
@@ -18,7 +18,6 @@
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
-import java.util.List;
import java.util.Optional;
/**
@@ -28,12 +27,16 @@
@AutoValue
public abstract class FileEdits {
public static FileEdits create(
- List<org.eclipse.jgit.diff.Edit> jgitEdits,
+ ImmutableList<Edit> edits, Optional<String> oldPath, Optional<String> newPath) {
+ return new AutoValue_FileEdits(edits, oldPath, newPath);
+ }
+
+ public static FileEdits createFromJgitEdits(
+ ImmutableList<org.eclipse.jgit.diff.Edit> jgitEdits,
Optional<String> oldPath,
Optional<String> newPath) {
- ImmutableList<Edit> edits =
- jgitEdits.stream().map(Edit::fromJGitEdit).collect(toImmutableList());
- return new AutoValue_FileEdits(edits, oldPath, newPath);
+ return new AutoValue_FileEdits(
+ jgitEdits.stream().map(Edit::fromJGitEdit).collect(toImmutableList()), oldPath, newPath);
}
public abstract ImmutableList<Edit> edits();
diff --git a/java/com/google/gerrit/server/patch/filediff/PatchListLoader.java b/java/com/google/gerrit/server/patch/filediff/PatchListLoader.java
index 5b7eddb..d1c0b45 100644
--- a/java/com/google/gerrit/server/patch/filediff/PatchListLoader.java
+++ b/java/com/google/gerrit/server/patch/filediff/PatchListLoader.java
@@ -348,7 +348,7 @@
newName = Optional.of(patchListEntry.getNewName());
break;
}
- return FileEdits.create(patchListEntry.getEdits(), oldName, newName);
+ return FileEdits.createFromJgitEdits(patchListEntry.getEdits(), oldName, newName);
}
private static boolean isRootOrMergeCommit(RevCommit commit) {