summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Nieder <jrn@google.com>2015-11-10 17:03:06 -0800
committerJonathan Nieder <jrn@google.com>2018-12-26 14:30:42 -0800
commitf46e223187387f50f5e09702fc033e4845bb3bf1 (patch)
tree54b6c84276a904446d67b8955343c05dc32de904
parent32da5ac3c3591ddcaf8d3169248b03c163dc3097 (diff)
downloadjgit-f46e223187387f50f5e09702fc033e4845bb3bf1.tar.gz
jgit-f46e223187387f50f5e09702fc033e4845bb3bf1.zip
RefDirectory: Fire RefsChangedEvent on error, too
getRef and exactRef can produce recoverable exceptions --- for example, a corrupt loose ref that cannot be parsed. If readRef was called and updated looseRefs in the process, RefsChangedEvent should still be fired. Noticed while improving the implementation of getRef. This commit only affects exactRef and getRef. Other methods might be similarly skipping firing RefsChangedEvent in their error handling code, and this change does not fix them. Change-Id: I0f460f6c8d9a585ad8453a4a47c1c77e24a1fb83 Signed-off-by: Jonathan Nieder <jrn@google.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java26
1 files changed, 15 insertions, 11 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 36adcd6ae2..71f2e9e23f 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
@@ -343,24 +343,28 @@ public class RefDirectory extends RefDatabase {
/** {@inheritDoc} */
@Override
public Ref exactRef(String name) throws IOException {
- Ref ref = readAndResolve(name, getPackedRefs());
- fireRefsChanged();
- return ref;
+ try {
+ return readAndResolve(name, getPackedRefs());
+ } finally {
+ fireRefsChanged();
+ }
}
/** {@inheritDoc} */
@Override
public Ref getRef(String needle) throws IOException {
- final RefList<Ref> packed = getPackedRefs();
- Ref ref = null;
- for (String prefix : SEARCH_PATH) {
- ref = readAndResolve(prefix + needle, packed);
- if (ref != null) {
- break;
+ try {
+ RefList<Ref> packed = getPackedRefs();
+ for (String prefix : SEARCH_PATH) {
+ Ref ref = readAndResolve(prefix + needle, packed);
+ if (ref != null) {
+ return ref;
+ }
}
+ return null;
+ } finally {
+ fireRefsChanged();
}
- fireRefsChanged();
- return ref;
}
/** {@inheritDoc} */