When asked to read a symref pointing to a branch-yet-to-be-born (such as HEAD in a newly initialized repository), getRef and getRefs provide different results. getRef: SymbolicRef[HEAD -> refs/heads/master=00000000] getRefs and getAdditionalRefs: nothing exactRef should match the getRef behavior: it is meant to be a simpler, faster version of getRef that lets you search for a ref without resolving it using the search path without other semantic changes. But the fallback implementation of exactRef relies on getRefs and produces null for this case. Luckily the in-tree RefDatabase implementations override exactRef and get the correct behavior. But any out-of-tree storage backend that doesn't inherit from DfsRefDatabase or RefDirectory would still return null when it shouldn't. Let the fallback implementation use getRef instead to avoid this. This means that exactRef would waste some effort traversing the ref search path when the named ref is not found --- but subclasses tend to override exactRef for performance already, so in the default implementation correctness is more important. Bug: 478865 Change-Id: I60f04e3ce3bf4731640ffd2433d329e621330029tags/v4.1.1.201511131810-r
@@ -239,20 +239,11 @@ public abstract class RefDatabase { | |||
* @since 4.1 | |||
*/ | |||
public Ref exactRef(String name) throws IOException { | |||
int slash = name.lastIndexOf('/'); | |||
String prefix = name.substring(0, slash + 1); | |||
String rest = name.substring(slash + 1); | |||
Ref result = getRefs(prefix).get(rest); | |||
if (result != null || slash != -1) { | |||
return result; | |||
Ref ref = getRef(name); | |||
if (ref == null || !name.equals(ref.getName())) { | |||
return null; | |||
} | |||
for (Ref ref : getAdditionalRefs()) { | |||
if (name.equals(ref.getName())) { | |||
return ref; | |||
} | |||
} | |||
return null; | |||
return ref; | |||
} | |||
/** |