From d48ac5bf0175632324651c12900f575bb4e2d036 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Thu, 13 Jul 2017 11:04:20 -0700 Subject: 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 --- .../storage/reftable/MergedReftableTest.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'org.eclipse.jgit.test') 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 delta1 = Arrays.asList( + ref("refs/heads/next", 4), + ref("refs/heads/master", 1)); + List delta2 = Arrays.asList(delete("refs/heads/next")); + List 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 stack = new ArrayList<>(table.length); for (byte[] b : table) { -- cgit v1.2.3