aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@google.com>2019-07-29 10:58:50 +0200
committerHan-Wen Nienhuys <hanwen@google.com>2019-08-19 11:10:20 +0200
commitca9107d166ec2a06e8c16b73d05064ba28c049da (patch)
tree227905b468cdb664a8fda2fd19fb69ccf06e71ae /org.eclipse.jgit.test
parent5e44bfa3ad462e1220426492c53606c6a643a970 (diff)
downloadjgit-ca9107d166ec2a06e8c16b73d05064ba28c049da.tar.gz
jgit-ca9107d166ec2a06e8c16b73d05064ba28c049da.zip
reftable: fix seeking to refs in reflog implementation
Small reftables omit the log index. Currently, ReftableWriter#shouldHaveIndex does this if there is a single-block log, but other writers could decide on different criteria. In the case that the log index is missing, we have to linearly search for the right block. It is never appropriate to use binary search on blocks for log data, as the blocks are compressed and therefore irregularly sized. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Change-Id: Id59874edf6bf45c7dec502d9465888e077ffe198
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
index a142166983..db9a4d0ac1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
@@ -472,6 +472,51 @@ public class ReftableTest {
}
@Test
+ public void reflogSeek() throws IOException {
+ PersonIdent who = new PersonIdent("Log", "Ger", 1500079709, -8 * 60);
+ String msg = "test";
+ String msgNext = "test next";
+
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(1)
+ .setMaxUpdateIndex(1)
+ .begin(buffer);
+
+ writer.writeLog(MASTER, 1, who, ObjectId.zeroId(), id(1), msg);
+ writer.writeLog(NEXT, 1, who, ObjectId.zeroId(), id(2), msgNext);
+
+ writer.finish();
+ byte[] table = buffer.toByteArray();
+
+ ReftableReader t = read(table);
+ try (LogCursor c = t.seekLog(MASTER, Long.MAX_VALUE)) {
+ assertTrue(c.next());
+ assertEquals(c.getReflogEntry().getComment(), msg);
+ }
+ try (LogCursor c = t.seekLog(MASTER, 0)) {
+ assertFalse(c.next());
+ }
+ try (LogCursor c = t.seekLog(MASTER, 1)) {
+ assertTrue(c.next());
+ assertEquals(c.getUpdateIndex(), 1);
+ assertEquals(c.getReflogEntry().getComment(), msg);
+ }
+ try (LogCursor c = t.seekLog(NEXT, Long.MAX_VALUE)) {
+ assertTrue(c.next());
+ assertEquals(c.getReflogEntry().getComment(), msgNext);
+ }
+ try (LogCursor c = t.seekLog(NEXT, 0)) {
+ assertFalse(c.next());
+ }
+ try (LogCursor c = t.seekLog(NEXT, 1)) {
+ assertTrue(c.next());
+ assertEquals(c.getUpdateIndex(), 1);
+ assertEquals(c.getReflogEntry().getComment(), msgNext);
+ }
+ }
+
+ @Test
public void onlyReflog() throws IOException {
PersonIdent who = new PersonIdent("Log", "Ger", 1500079709, -8 * 60);
String msg = "test";