aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-04-18 11:00:54 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-04-18 11:00:54 +0200
commitf1a9adf7da3cd130a0233aad3f31e2917317c13a (patch)
treeebbd9f989f126e3f57ad5501235fadb3f04d6562
parent8f8bc703e9e19493b7f85cdae88b6c88a5bbd9a0 (diff)
downloadjgit-f1a9adf7da3cd130a0233aad3f31e2917317c13a.tar.gz
jgit-f1a9adf7da3cd130a0233aad3f31e2917317c13a.zip
PackedBatchRefUpdate#execute: reduce nesting of try-catch blocks
Change-Id: I7ddf20fcbf4971ee908b20d8df9d6328ce9f9f1b
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java39
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java2
2 files changed, 18 insertions, 23 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java
index a9e05c92ae..106313db63 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java
@@ -158,6 +158,7 @@ class PackedBatchRefUpdate extends BatchRefUpdate {
}
Map<String, LockFile> locks = null;
+ LockFile packedRefsLock = null;
refdb.inProcessPackedRefsLock.lock();
try {
// During clone locking isn't needed since no refs exist yet.
@@ -168,35 +169,29 @@ class PackedBatchRefUpdate extends BatchRefUpdate {
if (locks == null) {
return;
}
- try {
- refdb.pack(locks);
- } catch (LockFailedException e) {
- lockFailure(pending.get(0), pending);
- return;
- }
+ refdb.pack(locks);
}
- LockFile packedRefsLock = refdb.lockPackedRefs();
- if (packedRefsLock == null) {
- lockFailure(pending.get(0), pending);
+ packedRefsLock = refdb.lockPackedRefsOrThrow();
+ PackedRefList oldPackedList = refdb.refreshPackedRefs();
+ RefList<Ref> newRefs = applyUpdates(walk, oldPackedList, pending);
+ if (newRefs == null) {
return;
}
- try {
- PackedRefList oldPackedList = refdb.refreshPackedRefs();
- RefList<Ref> newRefs = applyUpdates(walk, oldPackedList, pending);
- if (newRefs == null) {
- return;
- }
- refdb.commitPackedRefs(packedRefsLock, newRefs, oldPackedList,
- true);
- } finally {
- // This will be no-op if commitPackedRefs is successful as it
- // will remove the lock file (by renaming over real file).
- packedRefsLock.unlock();
- }
+ refdb.commitPackedRefs(packedRefsLock, newRefs, oldPackedList,
+ true);
+ } catch (LockFailedException e) {
+ lockFailure(pending.get(0), pending);
+ return;
} finally {
try {
unlockAll(locks);
+ if (packedRefsLock != null) {
+ // This will be no-op if commitPackedRefs is successful as
+ // it will remove the lock file (by renaming over real
+ // file).
+ packedRefsLock.unlock();
+ }
} finally {
refdb.inProcessPackedRefsLock.unlock();
}
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 57dbd389ff..0416a648e5 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
@@ -853,7 +853,7 @@ public class RefDirectory extends RefDatabase {
return null;
}
- private LockFile lockPackedRefsOrThrow() throws IOException {
+ LockFile lockPackedRefsOrThrow() throws IOException {
LockFile lck = lockPackedRefs();
if (lck == null) {
throw new LockFailedException(packedRefsFile);