From 9719ca411eed75d30f3199d1d57663c3cb68e29b Mon Sep 17 00:00:00 2001 From: Minh Thai Date: Mon, 22 Jun 2020 16:44:32 -0700 Subject: [PATCH] MergedReftable: Include the last reftable in determining minUpdateIndex 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 --- .../storage/reftable/MergedReftableTest.java | 32 +++++++++---------- .../storage/reftable/MergedReftable.java | 2 +- 2 files changed, 17 insertions(+), 17 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 a246ac9e9c..0a03fc3523 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 @@ -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(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/MergedReftable.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/MergedReftable.java index 36335153a1..a78f4d24da 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/MergedReftable.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/MergedReftable.java @@ -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(); } -- 2.39.5