Merge "Correct file list when comparing patchsets"

This commit is contained in:
Edwin Kempin 2015-06-26 06:42:28 +00:00 committed by Gerrit Code Review
commit 996e5dfe21
2 changed files with 27 additions and 5 deletions

View File

@ -155,11 +155,19 @@ public class PatchListCacheIT extends AbstractDaemonTest {
.create();
pushHead(testRepo, "refs/for/master", false);
// Compare Change 1,1 with Change 1,2 (+FILE_B)
// Compare Change 1,1 with Change 1,2 (+FILE_B, -FILE_C)
List<PatchListEntry> entries = getPatches(a, b);
assertThat(entries).hasSize(2);
assertThat(entries).hasSize(3);
assertModified(Patch.COMMIT_MSG, entries.get(0));
assertAdded(FILE_B, entries.get(1));
assertDeleted(FILE_C, entries.get(2));
// Compare Change 1,2 with Change 1,1 (-FILE_B, +FILE_C)
List<PatchListEntry> entriesReverse = getPatches(b, a);
assertThat(entriesReverse).hasSize(3);
assertModified(Patch.COMMIT_MSG, entriesReverse.get(0));
assertDeleted(FILE_B, entriesReverse.get(1));
assertAdded(FILE_C, entriesReverse.get(2));
}
@Test
@ -198,6 +206,12 @@ public class PatchListCacheIT extends AbstractDaemonTest {
assertThat(entries).hasSize(2);
assertModified(Patch.COMMIT_MSG, entries.get(0));
assertAdded(FILE_C, entries.get(1));
// Compare Change 1,2 with Change 1,1 (-FILE_C)
List<PatchListEntry> entriesReverse = getPatches(b, a);
assertThat(entriesReverse).hasSize(2);
assertModified(Patch.COMMIT_MSG, entriesReverse.get(0));
assertDeleted(FILE_C, entriesReverse.get(1));
}
private static void assertAdded(String expectedNewName, PatchListEntry e) {

View File

@ -19,6 +19,7 @@ import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Iterables;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.RefNames;
@ -159,9 +160,16 @@ public class PatchListLoader extends CacheLoader<PatchListKey, PatchList> {
List<DiffEntry> diffEntries = df.scan(aTree, bTree);
Set<String> paths = key.getOldId() != null
? FluentIterable.from(patchListCache.get(
new PatchListKey(key.projectKey, null, key.getNewId(),
key.getWhitespace())).getPatches())
? FluentIterable.from(
Iterables.concat(
patchListCache.get(
new PatchListKey(key.projectKey, null,
key.getNewId(), key.getWhitespace()))
.getPatches(),
patchListCache.get(
new PatchListKey(key.projectKey, null,
key.getOldId(), key.getWhitespace()))
.getPatches()))
.transform(new Function<PatchListEntry, String>() {
@Override
public String apply(PatchListEntry entry) {