summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2023-05-23 18:26:47 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2023-05-23 18:26:47 -0400
commit44461b215ea3e307837c7124300d86ac6abe11cb (patch)
treefa7762c0cddf28e1424c443df99360fd5c81c9f5
parent5a00dd873d56a440814f12dc9a86091ad3284780 (diff)
parent6b3b2b33a528458aa23428db7d43655aa0d883d5 (diff)
downloadjgit-44461b215ea3e307837c7124300d86ac6abe11cb.tar.gz
jgit-44461b215ea3e307837c7124300d86ac6abe11cb.zip
Merge "GraphObjectIndex: fix search in findGraphPosition"
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndexTest.java28
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndex.java4
2 files changed, 30 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndexTest.java
new file mode 100644
index 0000000000..b533d5c985
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndexTest.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2023, Google LLC
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.eclipse.jgit.internal.storage.commitgraph;
+
+import org.eclipse.jgit.lib.ObjectId;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class GraphObjectIndexTest {
+
+ @Test
+ public void findGraphPosition_noObjInBucket() throws CommitGraphFormatException {
+ GraphObjectIndex idx = new GraphObjectIndex(100,
+ new byte[256 * 4], new byte[] {});
+ int graphPosition = idx.findGraphPosition(
+ ObjectId.fromString("731dfd4c5eb6f88b98e983b9b0551b3562a0c46c"));
+ assertEquals(-1, graphPosition);
+ }
+
+}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndex.java
index b0df46732e..22b4011f9f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndex.java
@@ -80,7 +80,7 @@ class GraphObjectIndex {
if (levelOne > 0) {
low = fanoutTable[levelOne - 1];
}
- do {
+ while (low < high) {
int mid = (low + high) >>> 1;
int pos = objIdOffset(mid);
int cmp = id.compareTo(oidLookup, pos);
@@ -91,7 +91,7 @@ class GraphObjectIndex {
} else {
low = mid + 1;
}
- } while (low < high);
+ }
return -1;
}