}
if (hasCommands()) {
- Throwable unpackError = null;
- if (needPack()) {
- try {
- receivePackAndCheckConnectivity();
- } catch (IOException | RuntimeException
- | SubmoduleValidationException | Error err) {
- unpackError = err;
+ try (PostReceiveExecutor e = new PostReceiveExecutor()) {
+ if (needPack()) {
+ try {
+ receivePackAndCheckConnectivity();
+ } catch (IOException | RuntimeException
+ | SubmoduleValidationException | Error err) {
+ unlockPack();
+ sendStatusReport(err);
+ throw new UnpackException(err);
+ }
}
- }
- try {
- if (unpackError == null) {
+ try {
setAtomic(isCapabilityEnabled(CAPABILITY_ATOMIC));
validateCommands();
failPendingCommands();
}
executeCommands();
+ } finally {
+ unlockPack();
}
- } 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
- }
- throw new UnpackException(unpackError);
+ sendStatusReport(null);
}
- postReceive.onPostReceive(this, filterCommands(Result.OK));
autoGc();
}
}
}
return new ReceiveCommand(oldId, newId, name);
}
+
+ private class PostReceiveExecutor implements AutoCloseable {
+ @Override
+ public void close() {
+ postReceive.onPostReceive(ReceivePack.this,
+ filterCommands(Result.OK));
+ }
+ }
}