Browse Source

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 <mthai@google.com>
master
Minh Thai 4 years ago
parent
commit
9719ca411e
  1. 32
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
  2. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/MergedReftable.java

32
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 { public void overlappedUpdateIndices() throws IOException {
ByteArrayOutputStream buf = new ByteArrayOutputStream(); ByteArrayOutputStream buf = new ByteArrayOutputStream();
ReftableWriter writer = new ReftableWriter(buf) ReftableWriter writer = new ReftableWriter(buf)
.setMinUpdateIndex(1) .setMinUpdateIndex(2)
.setMaxUpdateIndex(3) .setMaxUpdateIndex(4)
.begin(); .begin();
writer.writeRef(ref("refs/heads/a", 1), 1); writer.writeRef(ref("refs/heads/a", 10), 2);
writer.writeRef(ref("refs/heads/b", 2), 3); writer.writeRef(ref("refs/heads/b", 20), 4);
writer.finish(); writer.finish();
byte[] base = buf.toByteArray(); byte[] base = buf.toByteArray();
buf = new ByteArrayOutputStream(); buf = new ByteArrayOutputStream();
writer = new ReftableWriter(buf) writer = new ReftableWriter(buf)
.setMinUpdateIndex(2) .setMinUpdateIndex(1)
.setMaxUpdateIndex(4) .setMaxUpdateIndex(3)
.begin(); .begin();
writer.writeRef(ref("refs/heads/a", 10), 2); writer.writeRef(ref("refs/heads/a", 1), 1);
writer.writeRef(ref("refs/heads/b", 20), 4); writer.writeRef(ref("refs/heads/b", 2), 3);
writer.finish(); writer.finish();
byte[] delta = buf.toByteArray(); byte[] delta = buf.toByteArray();
@ -368,21 +368,21 @@ public class MergedReftableTest {
public void enclosedUpdateIndices() throws IOException { public void enclosedUpdateIndices() throws IOException {
ByteArrayOutputStream buf = new ByteArrayOutputStream(); ByteArrayOutputStream buf = new ByteArrayOutputStream();
ReftableWriter writer = new ReftableWriter(buf) ReftableWriter writer = new ReftableWriter(buf)
.setMinUpdateIndex(1) .setMinUpdateIndex(2)
.setMaxUpdateIndex(4) .setMaxUpdateIndex(3)
.begin(); .begin();
writer.writeRef(ref("refs/heads/a", 1), 1); writer.writeRef(ref("refs/heads/a", 10), 2);
writer.writeRef(ref("refs/heads/b", 20), 4); writer.writeRef(ref("refs/heads/b", 2), 3);
writer.finish(); writer.finish();
byte[] base = buf.toByteArray(); byte[] base = buf.toByteArray();
buf = new ByteArrayOutputStream(); buf = new ByteArrayOutputStream();
writer = new ReftableWriter(buf) writer = new ReftableWriter(buf)
.setMinUpdateIndex(2) .setMinUpdateIndex(1)
.setMaxUpdateIndex(3) .setMaxUpdateIndex(4)
.begin(); .begin();
writer.writeRef(ref("refs/heads/a", 10), 2); writer.writeRef(ref("refs/heads/a", 1), 1);
writer.writeRef(ref("refs/heads/b", 2), 3); writer.writeRef(ref("refs/heads/b", 20), 4);
writer.finish(); writer.finish();
byte[] delta = buf.toByteArray(); byte[] delta = buf.toByteArray();

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/MergedReftable.java

@ -82,7 +82,7 @@ public class MergedReftable extends Reftable {
return 0; return 0;
} }
long minUpdateIndex = tables[0].minUpdateIndex(); 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) { if (tables[i].minUpdateIndex() < minUpdateIndex) {
minUpdateIndex = tables[i].minUpdateIndex(); minUpdateIndex = tables[i].minUpdateIndex();
} }

Loading…
Cancel
Save