aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2017-07-13 11:04:20 -0700
committerShawn Pearce <spearce@spearce.org>2017-08-17 15:06:51 -0700
commitd48ac5bf0175632324651c12900f575bb4e2d036 (patch)
treeb4d692259b52c00da7364ed2fd84464eda42e582 /org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage
parent77d8eead6d0ea3f7bbc44d5c079ab67007a2afd7 (diff)
downloadjgit-d48ac5bf0175632324651c12900f575bb4e2d036.tar.gz
jgit-d48ac5bf0175632324651c12900f575bb4e2d036.zip
reftable: compact merged tables
A compaction of reftables is just copying the results of a MergedReftable into a ReftableWriter. Wrap this up into a utility. Change-Id: I6f5677d923e9628993a2d8b4b007a9b8662c9045
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
index b6306d09e4..f9ebaf6926 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
@@ -261,6 +261,33 @@ public class MergedReftableTest {
}
}
+ @Test
+ public void compaction() throws IOException {
+ List<Ref> delta1 = Arrays.asList(
+ ref("refs/heads/next", 4),
+ ref("refs/heads/master", 1));
+ List<Ref> delta2 = Arrays.asList(delete("refs/heads/next"));
+ List<Ref> delta3 = Arrays.asList(ref("refs/heads/master", 8));
+
+ ReftableCompactor compactor = new ReftableCompactor();
+ compactor.addAll(Arrays.asList(
+ read(write(delta1)),
+ read(write(delta2)),
+ read(write(delta3))));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ compactor.compact(out);
+ byte[] table = out.toByteArray();
+
+ ReftableReader reader = read(table);
+ try (RefCursor rc = reader.allRefs()) {
+ assertTrue(rc.next());
+ Ref r = rc.getRef();
+ assertEquals("refs/heads/master", r.getName());
+ assertEquals(id(8), r.getObjectId());
+ assertFalse(rc.next());
+ }
+ }
+
private static MergedReftable merge(byte[]... table) {
List<Reftable> stack = new ArrayList<>(table.length);
for (byte[] b : table) {