summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@google.com>2019-11-17 16:29:16 -0800
committerMatthias Sohn <matthias.sohn@sap.com>2019-12-04 23:35:32 +0100
commit5185d288c11171a21a3057f0df906782493d0b39 (patch)
tree681704b7cf11b337c5c5a1d107a90e68ab782659 /org.eclipse.jgit.test/tst/org/eclipse
parent3198df1860316306788332700a0bf6f4413d415f (diff)
downloadjgit-5185d288c11171a21a3057f0df906782493d0b39.tar.gz
jgit-5185d288c11171a21a3057f0df906782493d0b39.zip
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 <hanwen@google.com> Change-Id: Idaf7e01075906972ec21332cade285289619c2b3
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java66
2 files changed, 70 insertions, 0 deletions
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
@@ -177,6 +177,67 @@ public class ReftableTest {
}
@Test
+ public void hasObjMapRefs() throws IOException {
+ ArrayList<Ref> 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<Ref> 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<Ref> 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);
byte[] table = write(exp);
@@ -936,8 +997,13 @@ public class ReftableTest {
}
private byte[] write(Collection<Ref> refs) throws IOException {
+ return write(refs, new ReftableConfig());
+ }
+
+ private byte[] write(Collection<Ref> refs, ReftableConfig cfg) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
stats = new ReftableWriter(buffer)
+ .setConfig(cfg)
.begin()
.sortAndWriteRefs(refs)
.finish()