PackedBatchRefUpdate#execute: reduce nesting of try-catch blocks
Change-Id: I7ddf20fcbf4971ee908b20d8df9d6328ce9f9f1b
This commit is contained in:
parent
8f8bc703e9
commit
f1a9adf7da
|
@ -158,6 +158,7 @@ public void execute(RevWalk walk, ProgressMonitor monitor,
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, LockFile> locks = null;
|
Map<String, LockFile> locks = null;
|
||||||
|
LockFile packedRefsLock = null;
|
||||||
refdb.inProcessPackedRefsLock.lock();
|
refdb.inProcessPackedRefsLock.lock();
|
||||||
try {
|
try {
|
||||||
// During clone locking isn't needed since no refs exist yet.
|
// During clone locking isn't needed since no refs exist yet.
|
||||||
|
@ -168,20 +169,10 @@ public void execute(RevWalk walk, ProgressMonitor monitor,
|
||||||
if (locks == null) {
|
if (locks == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
refdb.pack(locks);
|
refdb.pack(locks);
|
||||||
} catch (LockFailedException e) {
|
|
||||||
lockFailure(pending.get(0), pending);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LockFile packedRefsLock = refdb.lockPackedRefs();
|
packedRefsLock = refdb.lockPackedRefsOrThrow();
|
||||||
if (packedRefsLock == null) {
|
|
||||||
lockFailure(pending.get(0), pending);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
PackedRefList oldPackedList = refdb.refreshPackedRefs();
|
PackedRefList oldPackedList = refdb.refreshPackedRefs();
|
||||||
RefList<Ref> newRefs = applyUpdates(walk, oldPackedList, pending);
|
RefList<Ref> newRefs = applyUpdates(walk, oldPackedList, pending);
|
||||||
if (newRefs == null) {
|
if (newRefs == null) {
|
||||||
|
@ -189,14 +180,18 @@ public void execute(RevWalk walk, ProgressMonitor monitor,
|
||||||
}
|
}
|
||||||
refdb.commitPackedRefs(packedRefsLock, newRefs, oldPackedList,
|
refdb.commitPackedRefs(packedRefsLock, newRefs, oldPackedList,
|
||||||
true);
|
true);
|
||||||
} finally {
|
} catch (LockFailedException e) {
|
||||||
// This will be no-op if commitPackedRefs is successful as it
|
lockFailure(pending.get(0), pending);
|
||||||
// will remove the lock file (by renaming over real file).
|
return;
|
||||||
packedRefsLock.unlock();
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
unlockAll(locks);
|
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 {
|
} finally {
|
||||||
refdb.inProcessPackedRefsLock.unlock();
|
refdb.inProcessPackedRefsLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -853,7 +853,7 @@ LockFile lockPackedRefs() throws IOException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LockFile lockPackedRefsOrThrow() throws IOException {
|
LockFile lockPackedRefsOrThrow() throws IOException {
|
||||||
LockFile lck = lockPackedRefs();
|
LockFile lck = lockPackedRefs();
|
||||||
if (lck == null) {
|
if (lck == null) {
|
||||||
throw new LockFailedException(packedRefsFile);
|
throw new LockFailedException(packedRefsFile);
|
||||||
|
|
Loading…
Reference in New Issue