BaseReceivePack: Add hasReceivedPack method

The getPackSize method will throw IllegalStateException if it is
called when the pack size is not set. This is the case for example
when the received commands are all DELETE and there is no pack.

Add a new method hasReceivedPack that can be called prior to calling
getPackSize, to avoid causing the IllegalStateException.

See [1] for context.

[1] https://bugs.chromium.org/p/gerrit/issues/detail?id=11918

Change-Id: I56397256a05e92c8398e65c07a859cee59b46317
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2019-11-13 10:16:25 -08:00
parent 566a46e9ec
commit fd798d326e
1 changed files with 14 additions and 0 deletions

View File

@ -1068,6 +1068,20 @@ public OutputStream getMessageOutputStream() {
return msgOutWrapper;
}
/**
* Get whether or not a pack has been received.
*
* This can be called before calling {@link #getPackSize()} to avoid causing
* {@code IllegalStateException} when the pack size was not set because no
* pack was received.
*
* @return true if a pack has been received.
* @since 5.6
*/
public boolean hasReceivedPack() {
return packSize != null;
}
/**
* Get the size of the received pack file including the index size.
*