Avoid using Repository.resolve() when accessing exact ref-names

The Repository.resolve() method is quite complex and expensive
because of the logic of navigating the repository history refs
using arbitrary expressions.

The reading of blobs from the repository for the OWNERS file
does not need any complex navigation logic and is always using
exact refs: use the RefDatabase.exactRef() which uses a direct
lookup which works in this case and is a lot faster.

Change-Id: I6a7ec1ad99f8f549dcbb06599b984c311d6760c0
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)