WalkSorter: Short-circuit sorting a single element
Change-Id: I00646c54df3dcdc057b620011e9f2de2fd1adfd9
This commit is contained in:
@@ -131,6 +131,8 @@ class WalkSorter {
|
|||||||
Multimap<RevCommit, PatchSetData> byCommit = byCommit(rw, in);
|
Multimap<RevCommit, PatchSetData> byCommit = byCommit(rw, in);
|
||||||
if (byCommit.isEmpty()) {
|
if (byCommit.isEmpty()) {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
|
} else if (byCommit.size() == 1) {
|
||||||
|
return ImmutableList.of(byCommit.values().iterator().next());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk from all patch set SHA-1s, and terminate as soon as we've found
|
// Walk from all patch set SHA-1s, and terminate as soon as we've found
|
||||||
|
|||||||
@@ -219,6 +219,18 @@ public class WalkSorterTest {
|
|||||||
assertThat(actual.getRawBuffer()).isNull();
|
assertThat(actual.getRawBuffer()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void oneChange() throws Exception {
|
||||||
|
TestRepository<Repo> p = newRepo("p");
|
||||||
|
RevCommit c = p.commit().create();
|
||||||
|
ChangeData cd = newChange(p, c);
|
||||||
|
|
||||||
|
List<ChangeData> changes = ImmutableList.of(cd);
|
||||||
|
WalkSorter sorter = new WalkSorter(repoManager);
|
||||||
|
|
||||||
|
assertSorted(sorter, changes, ImmutableList.of(patchSetData(cd, c)));
|
||||||
|
}
|
||||||
|
|
||||||
private ChangeData newChange(TestRepository<Repo> tr, ObjectId id)
|
private ChangeData newChange(TestRepository<Repo> tr, ObjectId id)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Project.NameKey project = tr.getRepository().getDescription().getProject();
|
Project.NameKey project = tr.getRepository().getDescription().getProject();
|
||||||
|
|||||||
Reference in New Issue
Block a user