aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorJonathan Nieder <jrn@google.com>2015-11-10 16:56:41 -0800
committerJonathan Nieder <jrn@google.com>2018-12-26 14:25:11 -0800
commit32da5ac3c3591ddcaf8d3169248b03c163dc3097 (patch)
tree508639e03b94f12b566a8f12ebcab7181c5cbaa1 /org.eclipse.jgit/src
parentf5bdb9745fb5f1d7122166a0ef71333baacbd96b (diff)
downloadjgit-32da5ac3c3591ddcaf8d3169248b03c163dc3097.tar.gz
jgit-32da5ac3c3591ddcaf8d3169248b03c163dc3097.zip
RefDirectory: Refactor getRef and exactRef to share code
Both getRef and exactRef look for a ref or pseudoref in the $GIT_DIR directory, with careful error handling to handle non-refs like .git/config. Avoid the duplication by factoring out a helper that takes care of this. This should make the code easier to understand and manipulate. Change-Id: I2ea67816d2385e84e2d3394b897e23df5826ba50 Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java34
1 files changed, 14 insertions, 20 deletions
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 de7e4b3f25..36adcd6ae2 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<Ref> packed = getPackedRefs();
- Ref ref;
+ @Nullable
+ private Ref readAndResolve(String name, RefList<Ref> 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<Ref> 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();