diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index de7e4b3f2..36adcd6ae 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -319,16 +319,14 @@ public class RefDirectory extends RefDatabase { return loose; } - /** {@inheritDoc} */ - @Override - public Ref exactRef(String name) throws IOException { - RefList packed = getPackedRefs(); - Ref ref; + @Nullable + private Ref readAndResolve(String name, RefList packed) throws IOException { try { - ref = readRef(name, packed); + Ref ref = readRef(name, packed); if (ref != null) { ref = resolve(ref, 0, null, null, packed); } + return ref; } catch (IOException e) { if (name.contains("/") //$NON-NLS-1$ || !(e.getCause() instanceof InvalidObjectIdException)) { @@ -338,8 +336,14 @@ public class RefDirectory extends RefDatabase { // While looking for a ref outside of refs/ (e.g., 'config'), we // found a non-ref file (e.g., a config file) instead. Treat this // as a ref-not-found condition. - ref = null; + return null; } + } + + /** {@inheritDoc} */ + @Override + public Ref exactRef(String name) throws IOException { + Ref ref = readAndResolve(name, getPackedRefs()); fireRefsChanged(); return ref; } @@ -350,19 +354,9 @@ public class RefDirectory extends RefDatabase { final RefList packed = getPackedRefs(); Ref ref = null; for (String prefix : SEARCH_PATH) { - try { - ref = readRef(prefix + needle, packed); - if (ref != null) { - ref = resolve(ref, 0, null, null, packed); - } - if (ref != null) { - break; - } - } catch (IOException e) { - if (!(!needle.contains("/") && "".equals(prefix) && e //$NON-NLS-1$ //$NON-NLS-2$ - .getCause() instanceof InvalidObjectIdException)) { - throw e; - } + ref = readAndResolve(prefix + needle, packed); + if (ref != null) { + break; } } fireRefsChanged();