Merge branch 'stable-3.4' into stable-3.5
* origin/stable-3.4:
Avoid using Repository.resolve() when accessing exact ref-names
Change-Id: Iee05df296b2183db87a3b5db4b9cf7e49fbba76f
diff --git a/owners-common/src/main/java/com/googlesource/gerrit/owners/common/JgitWrapper.java b/owners-common/src/main/java/com/googlesource/gerrit/owners/common/JgitWrapper.java
index 0f0db10..17b8af9 100644
--- a/owners-common/src/main/java/com/googlesource/gerrit/owners/common/JgitWrapper.java
+++ b/owners-common/src/main/java/com/googlesource/gerrit/owners/common/JgitWrapper.java
@@ -19,9 +19,11 @@
import static org.eclipse.jgit.lib.FileMode.TYPE_FILE;
import static org.eclipse.jgit.lib.FileMode.TYPE_MASK;
+import com.google.gerrit.entities.RefNames;
import java.io.IOException;
import java.util.Optional;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -34,13 +36,14 @@
public static Optional<byte[]> getBlobAsBytes(Repository repository, String revision, String path)
throws IOException {
- ObjectId objectId = repository.resolve(revision);
- if (objectId == null) {
+ Ref ref = repository.getRefDatabase().exactRef(RefNames.fullName(revision));
+ if (ref == null) {
return Optional.empty();
}
try (final TreeWalk w =
- TreeWalk.forPath(repository, path, parseCommit(repository, objectId).getTree())) {
+ TreeWalk.forPath(
+ repository, path, parseCommit(repository, ref.getLeaf().getObjectId()).getTree())) {
return Optional.ofNullable(w)
.filter(walk -> (walk.getRawMode(0) & TYPE_MASK) == TYPE_FILE)