From 5185d288c11171a21a3057f0df906782493d0b39 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 17 Nov 2019 16:29:16 -0800 Subject: Introduce RefDatabase#hasFastTipsWithSha1 The reftable format supports fast inverse (SHA1 => ref) queries. If the ref database does not support fast inverse queries, it may be advantageous to build a complete SHA1 to ref map in advance for multiple uses. To let applications decide, this function indicates whether the inverse map is available. Signed-off-by: Han-Wen Nienhuys Change-Id: Idaf7e01075906972ec21332cade285289619c2b3 --- .../internal/storage/file/FileReftableTest.java | 4 ++ .../internal/storage/reftable/ReftableTest.java | 66 ++++++++++++++++++++++ 2 files changed, 70 insertions(+) (limited to 'org.eclipse.jgit.test/tst/org/eclipse') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java index 0e06d459a2..cdc64fa1b2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java @@ -155,6 +155,8 @@ public class FileReftableTest extends SampleDataRepositoryTestCase { assertFalse(b.isSymbolic()); assertTrue(b.isPeeled()); assertEquals(bCommit, b.getObjectId().name()); + + assertTrue(db.getRefDatabase().hasFastTipsWithSha1()); } @Test @@ -169,6 +171,8 @@ public class FileReftableTest extends SampleDataRepositoryTestCase { assertFalse(b.isSymbolic()); assertTrue(b.isPeeled()); assertEquals(bCommit, b.getObjectId().name()); + + assertFalse(db.getRefDatabase().hasFastTipsWithSha1()); } @Test 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 45e6c7d128..daf540c413 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 @@ -176,6 +176,67 @@ public class ReftableTest { assertEquals(expBytes, table.length); } + @Test + public void hasObjMapRefs() throws IOException { + ArrayList refs = new ArrayList<>(); + refs.add(ref(MASTER, 1)); + byte[] table = write(refs); + ReftableReader t = read(table); + assertTrue(t.hasObjectMap()); + } + + @Test + public void hasObjMapRefsSmallTable() throws IOException { + ArrayList refs = new ArrayList<>(); + ReftableConfig cfg = new ReftableConfig(); + cfg.setIndexObjects(false); + refs.add(ref(MASTER, 1)); + byte[] table = write(refs); + ReftableReader t = read(table); + assertTrue(t.hasObjectMap()); + } + + @Test + public void hasObjLogs() throws IOException { + PersonIdent who = new PersonIdent("Log", "Ger", 1500079709, -8 * 60); + String msg = "test"; + ReftableConfig cfg = new ReftableConfig(); + cfg.setIndexObjects(false); + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ReftableWriter writer = new ReftableWriter(buffer) + .setMinUpdateIndex(1) + .setConfig(cfg) + .setMaxUpdateIndex(1) + .begin(); + + writer.writeLog("master", 1, who, ObjectId.zeroId(), id(1), msg); + writer.finish(); + byte[] table = buffer.toByteArray(); + + ReftableReader t = read(table); + assertTrue(t.hasObjectMap()); + } + + @Test + public void hasObjMapRefsNoIndexObjects() throws IOException { + ArrayList refs = new ArrayList<>(); + ReftableConfig cfg = new ReftableConfig(); + cfg.setIndexObjects(false); + cfg.setRefBlockSize(256); + cfg.setAlignBlocks(true); + + // Fill up 5 blocks. + int N = 256 * 5 / 25; + for (int i= 0; i < N; i++) { + refs.add(ref(String.format("%02d/xxxxxxxxxx", i), i)); + } + byte[] table = write(refs, cfg); + + ReftableReader t = read(table); + assertFalse(t.hasObjectMap()); + } + @Test public void oneIdRef() throws IOException { Ref exp = ref(MASTER, 1); @@ -936,8 +997,13 @@ public class ReftableTest { } private byte[] write(Collection refs) throws IOException { + return write(refs, new ReftableConfig()); + } + + private byte[] write(Collection refs, ReftableConfig cfg) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); stats = new ReftableWriter(buffer) + .setConfig(cfg) .begin() .sortAndWriteRefs(refs) .finish() -- cgit v1.2.3