summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorJonathan Nieder <jrn@google.com>2015-11-11 10:42:46 -0800
committerJonathan Nieder <jrn@google.com>2015-11-12 14:59:51 -0500
commit7dcb50a04a03a96e7514a8598eaf9bb052af867e (patch)
tree5eb6d9979045c2eff11fe94cfa066f3cb8c1e5e3 /org.eclipse.jgit
parent797f94d3319a6bea2cacce707a6a5ee67f00ea17 (diff)
downloadjgit-7dcb50a04a03a96e7514a8598eaf9bb052af867e.tar.gz
jgit-7dcb50a04a03a96e7514a8598eaf9bb052af867e.zip
Fallback exactRef: Do not ignore symrefs to unborn branch
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: I60f04e3ce3bf4731640ffd2433d329e621330029
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java17
1 files changed, 4 insertions, 13 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
index ef22fb90fe..b62033cbd2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
@@ -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;
}
/**