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:
@@ -342,7 +342,7 @@ class InProcessProtocol extends TestProtocol<Context> {
|
|||||||
ImmutableList.<PostReceiveHook>builder()
|
ImmutableList.<PostReceiveHook>builder()
|
||||||
.add(
|
.add(
|
||||||
(pack, commands) -> {
|
(pack, commands) -> {
|
||||||
if (affectsSize(pack, commands)) {
|
if (affectsSize(pack)) {
|
||||||
try {
|
try {
|
||||||
quotaBackend
|
quotaBackend
|
||||||
.user(identifiedUser)
|
.user(identifiedUser)
|
||||||
|
@@ -61,7 +61,7 @@ public class LazyPostReceiveHookChain implements PostReceiveHook {
|
|||||||
@Override
|
@Override
|
||||||
public void onPostReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
|
public void onPostReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
|
||||||
hooks.runEach(h -> h.onPostReceive(rp, commands));
|
hooks.runEach(h -> h.onPostReceive(rp, commands));
|
||||||
if (affectsSize(rp, commands)) {
|
if (affectsSize(rp)) {
|
||||||
QuotaResponse.Aggregated a =
|
QuotaResponse.Aggregated a =
|
||||||
quotaBackend
|
quotaBackend
|
||||||
.user(user)
|
.user(user)
|
||||||
@@ -78,21 +78,7 @@ public class LazyPostReceiveHookChain implements PostReceiveHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean affectsSize(ReceivePack rp, Collection<ReceiveCommand> commands) {
|
public static boolean affectsSize(ReceivePack rp) {
|
||||||
long packSize;
|
return rp.hasReceivedPack() && rp.getPackSize() > 0L;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user