ReceivePack: Use try-with-resources for PostReceiveHook
Instead of dropping a second exception, use try-with-resources so that exception thrown by a hook is attached as a suppressed exception. This removes a need of holding an exception that is thrown while unpacking an incoming packfile. Change-Id: I74d8b944931abbf53d9d1ae5db2e889639fba027 Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
This commit is contained in:
parent
4fcc43a1de
commit
224746e0f2
|
@ -2213,18 +2213,19 @@ private void service() throws IOException {
|
|||
}
|
||||
|
||||
if (hasCommands()) {
|
||||
Throwable unpackError = null;
|
||||
try (PostReceiveExecutor e = new PostReceiveExecutor()) {
|
||||
if (needPack()) {
|
||||
try {
|
||||
receivePackAndCheckConnectivity();
|
||||
} catch (IOException | RuntimeException
|
||||
| SubmoduleValidationException | Error err) {
|
||||
unpackError = err;
|
||||
unlockPack();
|
||||
sendStatusReport(err);
|
||||
throw new UnpackException(err);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (unpackError == null) {
|
||||
setAtomic(isCapabilityEnabled(CAPABILITY_ATOMIC));
|
||||
|
||||
validateCommands();
|
||||
|
@ -2238,24 +2239,12 @@ private void service() throws IOException {
|
|||
failPendingCommands();
|
||||
}
|
||||
executeCommands();
|
||||
}
|
||||
} finally {
|
||||
unlockPack();
|
||||
}
|
||||
|
||||
sendStatusReport(unpackError);
|
||||
|
||||
if (unpackError != null) {
|
||||
// we already know which exception to throw. Ignore
|
||||
// potential additional exceptions raised in postReceiveHooks
|
||||
try {
|
||||
postReceive.onPostReceive(this, filterCommands(Result.OK));
|
||||
} catch (Throwable e) {
|
||||
// empty
|
||||
sendStatusReport(null);
|
||||
}
|
||||
throw new UnpackException(unpackError);
|
||||
}
|
||||
postReceive.onPostReceive(this, filterCommands(Result.OK));
|
||||
autoGc();
|
||||
}
|
||||
}
|
||||
|
@ -2292,4 +2281,12 @@ static ReceiveCommand parseCommand(String line)
|
|||
}
|
||||
return new ReceiveCommand(oldId, newId, name);
|
||||
}
|
||||
|
||||
private class PostReceiveExecutor implements AutoCloseable {
|
||||
@Override
|
||||
public void close() {
|
||||
postReceive.onPostReceive(ReceivePack.this,
|
||||
filterCommands(Result.OK));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue