LazyPostReceiveHookChain: Simplify check for pack size

The latest JGit includes a method to check if a pack was
received.

Change-Id: I6d8adb3fec41265dbd498d118415d8f9b3da0b08
This commit is contained in:
David Pursehouse
2019-11-13 16:17:37 -08:00
parent d2d5aac1bc
commit 3b863c844a
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;
}
}