]> source.dussan.org Git - jgit.git/commitdiff
MergedReftable: Include the last reftable in determining minUpdateIndex 29/165329/2
authorMinh Thai <mthai@google.com>
Mon, 22 Jun 2020 23:44:32 +0000 (16:44 -0700)
committerMinh Thai <mthai@google.com>
Tue, 23 Jun 2020 00:14:35 +0000 (17:14 -0700)
MergedReftable ignores the last reftable in the stack while calculating the
minUpdateIndex.

Update the loop indices to include all reftables in the minUpdateIndex
calculation, while skipping position 0 as it is read outside the loop.

Change-Id: I12d3e714581e93d178be79c02408a67ab2bd838e
Signed-off-by: Minh Thai <mthai@google.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/MergedReftable.java

index a246ac9e9c1b180117569881e599aaacba605646..0a03fc352347955728a1f9ffbe5b6ea5c65a0353 100644 (file)
@@ -329,21 +329,21 @@ public class MergedReftableTest {
        public void overlappedUpdateIndices() throws IOException {
                ByteArrayOutputStream buf = new ByteArrayOutputStream();
                ReftableWriter writer = new ReftableWriter(buf)
-                               .setMinUpdateIndex(1)
-                               .setMaxUpdateIndex(3)
+                               .setMinUpdateIndex(2)
+                               .setMaxUpdateIndex(4)
                                .begin();
-               writer.writeRef(ref("refs/heads/a", 1), 1);
-               writer.writeRef(ref("refs/heads/b", 2), 3);
+               writer.writeRef(ref("refs/heads/a", 10), 2);
+               writer.writeRef(ref("refs/heads/b", 20), 4);
                writer.finish();
                byte[] base = buf.toByteArray();
 
                buf = new ByteArrayOutputStream();
                writer = new ReftableWriter(buf)
-                               .setMinUpdateIndex(2)
-                               .setMaxUpdateIndex(4)
+                               .setMinUpdateIndex(1)
+                               .setMaxUpdateIndex(3)
                                .begin();
-               writer.writeRef(ref("refs/heads/a", 10), 2);
-               writer.writeRef(ref("refs/heads/b", 20), 4);
+               writer.writeRef(ref("refs/heads/a", 1), 1);
+               writer.writeRef(ref("refs/heads/b", 2), 3);
                writer.finish();
                byte[] delta = buf.toByteArray();
 
@@ -368,21 +368,21 @@ public class MergedReftableTest {
        public void enclosedUpdateIndices() throws IOException {
                ByteArrayOutputStream buf = new ByteArrayOutputStream();
                ReftableWriter writer = new ReftableWriter(buf)
-                               .setMinUpdateIndex(1)
-                               .setMaxUpdateIndex(4)
+                               .setMinUpdateIndex(2)
+                               .setMaxUpdateIndex(3)
                                .begin();
-               writer.writeRef(ref("refs/heads/a", 1), 1);
-               writer.writeRef(ref("refs/heads/b", 20), 4);
+               writer.writeRef(ref("refs/heads/a", 10), 2);
+               writer.writeRef(ref("refs/heads/b", 2), 3);
                writer.finish();
                byte[] base = buf.toByteArray();
 
                buf = new ByteArrayOutputStream();
                writer = new ReftableWriter(buf)
-                               .setMinUpdateIndex(2)
-                               .setMaxUpdateIndex(3)
+                               .setMinUpdateIndex(1)
+                               .setMaxUpdateIndex(4)
                                .begin();
-               writer.writeRef(ref("refs/heads/a", 10), 2);
-               writer.writeRef(ref("refs/heads/b", 2), 3);
+               writer.writeRef(ref("refs/heads/a", 1), 1);
+               writer.writeRef(ref("refs/heads/b", 20), 4);
                writer.finish();
                byte[] delta = buf.toByteArray();
 
index 36335153a13b55bd961925045c3068de43997fbd..a78f4d24da82c5e70f462c13cfb8e0279908ccf1 100644 (file)
@@ -82,7 +82,7 @@ public class MergedReftable extends Reftable {
                        return 0;
                }
                long minUpdateIndex = tables[0].minUpdateIndex();
-               for (int i = 0; i < tables.length - 1; i++) {
+               for (int i = 1; i < tables.length; i++) {
                        if (tables[i].minUpdateIndex() < minUpdateIndex) {
                                minUpdateIndex = tables[i].minUpdateIndex();
                        }