From 0eeed6ad2b93f9f9712803cfec288bb0f094dd17 Mon Sep 17 00:00:00 2001 From: Minh Thai Date: Thu, 19 Mar 2020 23:10:41 -0700 Subject: [PATCH 1/3] Scan through all merged reftables for max/min update indices Since reftables might have update index ranges that are overlapped. Change-Id: I8f8215b99a0a978d4dd0155dbaf33e5e06ea8202 Signed-off-by: Minh Thai (cherry picked from commit 06748c205c44bb4eaf6015387112de97f566c6a2) --- .../storage/reftable/MergedReftableTest.java | 117 ++++++++++++++++++ .../storage/reftable/MergedReftable.java | 24 +++- 2 files changed, 137 insertions(+), 4 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 2a2aeb592..a246ac9e9 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 @@ -286,6 +286,123 @@ public class MergedReftableTest { } } + @Test + public void nonOverlappedUpdateIndices() throws IOException { + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + ReftableWriter writer = new ReftableWriter(buf) + .setMinUpdateIndex(1) + .setMaxUpdateIndex(2) + .begin(); + writer.writeRef(ref("refs/heads/a", 1), 1); + writer.writeRef(ref("refs/heads/b", 2), 2); + writer.finish(); + byte[] base = buf.toByteArray(); + + buf = new ByteArrayOutputStream(); + writer = new ReftableWriter(buf) + .setMinUpdateIndex(3) + .setMaxUpdateIndex(4) + .begin(); + writer.writeRef(ref("refs/heads/a", 10), 3); + writer.writeRef(ref("refs/heads/b", 20), 4); + writer.finish(); + byte[] delta = buf.toByteArray(); + + MergedReftable mr = merge(base, delta); + assertEquals(1, mr.minUpdateIndex()); + assertEquals(4, mr.maxUpdateIndex()); + + try (RefCursor rc = mr.allRefs()) { + assertTrue(rc.next()); + assertEquals("refs/heads/a", rc.getRef().getName()); + assertEquals(id(10), rc.getRef().getObjectId()); + assertEquals(3, rc.getRef().getUpdateIndex()); + + assertTrue(rc.next()); + assertEquals("refs/heads/b", rc.getRef().getName()); + assertEquals(id(20), rc.getRef().getObjectId()); + assertEquals(4, rc.getRef().getUpdateIndex()); + } + } + + @Test + public void overlappedUpdateIndices() throws IOException { + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + ReftableWriter writer = new ReftableWriter(buf) + .setMinUpdateIndex(1) + .setMaxUpdateIndex(3) + .begin(); + writer.writeRef(ref("refs/heads/a", 1), 1); + writer.writeRef(ref("refs/heads/b", 2), 3); + writer.finish(); + byte[] base = buf.toByteArray(); + + buf = new ByteArrayOutputStream(); + writer = new ReftableWriter(buf) + .setMinUpdateIndex(2) + .setMaxUpdateIndex(4) + .begin(); + writer.writeRef(ref("refs/heads/a", 10), 2); + writer.writeRef(ref("refs/heads/b", 20), 4); + writer.finish(); + byte[] delta = buf.toByteArray(); + + MergedReftable mr = merge(base, delta); + assertEquals(1, mr.minUpdateIndex()); + assertEquals(4, mr.maxUpdateIndex()); + + try (RefCursor rc = mr.allRefs()) { + assertTrue(rc.next()); + assertEquals("refs/heads/a", rc.getRef().getName()); + assertEquals(id(10), rc.getRef().getObjectId()); + assertEquals(2, rc.getRef().getUpdateIndex()); + + assertTrue(rc.next()); + assertEquals("refs/heads/b", rc.getRef().getName()); + assertEquals(id(20), rc.getRef().getObjectId()); + assertEquals(4, rc.getRef().getUpdateIndex()); + } + } + + @Test + public void enclosedUpdateIndices() throws IOException { + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + ReftableWriter writer = new ReftableWriter(buf) + .setMinUpdateIndex(1) + .setMaxUpdateIndex(4) + .begin(); + writer.writeRef(ref("refs/heads/a", 1), 1); + writer.writeRef(ref("refs/heads/b", 20), 4); + writer.finish(); + byte[] base = buf.toByteArray(); + + buf = new ByteArrayOutputStream(); + writer = new ReftableWriter(buf) + .setMinUpdateIndex(2) + .setMaxUpdateIndex(3) + .begin(); + writer.writeRef(ref("refs/heads/a", 10), 2); + writer.writeRef(ref("refs/heads/b", 2), 3); + writer.finish(); + byte[] delta = buf.toByteArray(); + + MergedReftable mr = merge(base, delta); + assertEquals(1, mr.minUpdateIndex()); + assertEquals(4, mr.maxUpdateIndex()); + + try (RefCursor rc = mr.allRefs()) { + assertTrue(rc.next()); + assertEquals("refs/heads/a", rc.getRef().getName()); + assertEquals(id(10), rc.getRef().getObjectId()); + assertEquals(2, rc.getRef().getUpdateIndex()); + + assertTrue(rc.next()); + assertEquals("refs/heads/b", rc.getRef().getName()); + assertEquals(id(20), rc.getRef().getObjectId()); + assertEquals(4, rc.getRef().getUpdateIndex()); + } + } + @Test public void compaction() throws IOException { List delta1 = Arrays.asList( 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 18c013fd8..36335153a 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 @@ -61,8 +61,16 @@ public class MergedReftable extends Reftable { */ @Override public long maxUpdateIndex() throws IOException { - return tables.length > 0 ? tables[tables.length - 1].maxUpdateIndex() - : 0; + if (tables.length == 0) { + return 0; + } + long maxUpdateIndex = tables[tables.length - 1].maxUpdateIndex(); + for (int i = tables.length - 2; i >= 0; i--) { + if (maxUpdateIndex < tables[i].maxUpdateIndex()) { + maxUpdateIndex = tables[i].maxUpdateIndex(); + } + } + return maxUpdateIndex; } /** @@ -70,8 +78,16 @@ public class MergedReftable extends Reftable { */ @Override public long minUpdateIndex() throws IOException { - return tables.length > 0 ? tables[0].minUpdateIndex() - : 0; + if (tables.length == 0) { + return 0; + } + long minUpdateIndex = tables[0].minUpdateIndex(); + for (int i = 0; i < tables.length - 1; i++) { + if (tables[i].minUpdateIndex() < minUpdateIndex) { + minUpdateIndex = tables[i].minUpdateIndex(); + } + } + return minUpdateIndex; } /** {@inheritDoc} */ From 3851023e0841b84b33a1a5dc9371687dedf20437 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 7 Apr 2020 16:11:42 +0900 Subject: [PATCH 2/3] Bump Bazel version to 3.0.0 Change-Id: I3866b58d3d288f37b1818be5b56d05e8be6ecb0f Signed-off-by: David Pursehouse --- .bazelversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelversion b/.bazelversion index ccbccc3dc..4a36342fc 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -2.2.0 +3.0.0 From a79c5b1f1046f4b41928bc40ab433155168dacc6 Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Tue, 14 Apr 2020 09:31:50 +0200 Subject: [PATCH 3/3] Remove double blank from sentence start Multiple whitespaces are not normalized when reading properties files, therefore leading to unwanted space/indentation in console or UI output. Change-Id: I1f5224fe359e0cac493e0237872afc75dc8b9fbe Signed-off-by: Michael Keppler Signed-off-by: David Pursehouse (cherry picked from commit ebbc3efce73278d6e0dbb1acd099db2446b1bed9) --- .../resources/org/eclipse/jgit/internal/JGitText.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index dd9ee3d23..8ee6e4736 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -301,7 +301,7 @@ flagNotFromThis={0} not from this. flagsAlreadyCreated={0} flags already created. funnyRefname=funny refname gcFailed=Garbage collection failed. -gcTooManyUnpruned=Too many loose, unpruneable objects after garbage collection. Consider adjusting gc.auto or gc.pruneExpire. +gcTooManyUnpruned=Too many loose, unpruneable objects after garbage collection. Consider adjusting gc.auto or gc.pruneExpire. gpgFailedToParseSecretKey=Failed to parse secret key file in directory: {0}. Is the entered passphrase correct? gpgNoCredentialsProvider=missing credentials provider gpgNoKeyring=neither pubring.kbx nor secring.gpg files found