Browse Source
The ref points to an ObjectId that then is translated into a RevCommit. This translation can be costly and with the incremental reachability check is probably not needed for most of the elements. Delay the translation from ObjectId to RevCommit to when it is needed. Use Streams, that have the laziness built-in, all the way from Ref to RevCommit. This should reduce the latency for reachability checks over big sets of references. Change-Id: I28693087321b2beff3eaa1f3d2e7840ab0eedc6d Signed-off-by: Ivan Frade <ifrade@google.com>stable-5.6
Ivan Frade
5 years ago
2 changed files with 69 additions and 40 deletions
@ -0,0 +1,33 @@
|
||||
package org.eclipse.jgit.transport; |
||||
|
||||
import static org.hamcrest.Matchers.contains; |
||||
import static org.junit.Assert.assertThat; |
||||
|
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
import java.util.stream.Stream; |
||||
|
||||
import org.eclipse.jgit.lib.ObjectId; |
||||
import org.eclipse.jgit.lib.ObjectIdRef.Unpeeled; |
||||
import org.eclipse.jgit.lib.Ref; |
||||
import org.eclipse.jgit.lib.Ref.Storage; |
||||
import org.junit.Test; |
||||
|
||||
public class UploadPackRefSortingForReachabilityTest { |
||||
|
||||
@Test |
||||
public void sortReferences() { |
||||
List<Ref> refs = Stream.of("refs/changes/12/12", "refs/changes/12/1", |
||||
"refs/heads/master", "refs/heads/something", |
||||
"refs/changes/55/1", "refs/tags/v1.1") |
||||
.map(s -> new Unpeeled(Storage.LOOSE, s, ObjectId.zeroId())) |
||||
.collect(Collectors.toList()); |
||||
Stream<Ref> sorted = UploadPack.importantRefsFirst(refs); |
||||
List<String> collected = sorted.map(Ref::getName) |
||||
.collect(Collectors.toList()); |
||||
assertThat(collected, |
||||
contains("refs/heads/master", "refs/heads/something", |
||||
"refs/tags/v1.1", "refs/changes/12/12", |
||||
"refs/changes/12/1", "refs/changes/55/1")); |
||||
} |
||||
} |
Loading…
Reference in new issue