Merge "LazyPostReceiveHookChain: Simplify check for pack size" into stable-3.1

This commit is contained in:
David Pursehouse
2019-11-14 21:41:48 +00:00
committed by Gerrit Code Review
2 changed files with 4 additions and 18 deletions

View File

@@ -342,7 +342,7 @@ class InProcessProtocol extends TestProtocol<Context> {
ImmutableList.<PostReceiveHook>builder()
.add(
(pack, commands) -> {
if (affectsSize(pack, commands)) {
if (affectsSize(pack)) {
try {
quotaBackend
.user(identifiedUser)

View File

@@ -61,7 +61,7 @@ public class LazyPostReceiveHookChain implements PostReceiveHook {
@Override
public void onPostReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
hooks.runEach(h -> h.onPostReceive(rp, commands));
if (affectsSize(rp, commands)) {
if (affectsSize(rp)) {
QuotaResponse.Aggregated a =
quotaBackend
.user(user)
@@ -78,21 +78,7 @@ public class LazyPostReceiveHookChain implements PostReceiveHook {
}
}
public static boolean affectsSize(ReceivePack rp, Collection<ReceiveCommand> commands) {
long packSize;
try {
packSize = rp.getPackSize();
} catch (IllegalStateException e) {
// No pack was received, i.e. ref deletion or wind back
return false;
}
if (packSize > 0L) {
for (ReceiveCommand cmd : commands) {
if (cmd.getType() != ReceiveCommand.Type.DELETE) {
return true;
}
}
}
return false;
public static boolean affectsSize(ReceivePack rp) {
return rp.hasReceivedPack() && rp.getPackSize() > 0L;
}
}