Class ReceivePack
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
static class
Deprecated.(package private) class
Output stream that wraps the currentmsgOut
.private class
private static class
Configuration for receive operations.(package private) static class
Interface for reporting status messages. -
Field Summary
FieldsModifier and TypeFieldDescriptionAll SHA-1s shown to the client, which can be possible edges.private StringBuilder
private AdvertiseRefsHook
Hook used while advertising the refs to the client.private boolean
Should an incoming transfer permit delete requests?private boolean
private boolean
Should an incoming transfer permit create requests?private boolean
Should an incoming transfer permit non-fast-forward requests?private boolean
private boolean
Should an incoming transfer permit push options?private boolean
private boolean
Should the requested ref updates be performed as a single atomic transaction?private boolean
Is the client connection a bi-directional socket or pipe?private boolean
private List
<ReceiveCommand> protected ConnectivityChecker
Connectivity checker to use.private final Repository
Database we write the stored objects into.Capabilities requested by the client.private SideBandOutputStream
private boolean
Expecting data after the pack footerprivate long
private long
private long
Git object size limitprivate long
Total pack size limitprivate OutputStream
Optional message output stream.private final ReceivePack.MessageOutputWrapper
private ObjectChecker
Should an incoming transfer validate objects?private OutputStream
private PackLock
Lock around the received pack file, while updating refs.private Long
The size of the received pack, including index sizeprivate PackParser
private PacketLineIn
Packet line input stream aroundrawIn
.private PacketLineOut
Packet line output stream aroundrawOut
.private PostReceiveHook
Hook to report on the commands after execution.private PreReceiveHook
Hook to validate the update commands before execution.private PushCertificate
private PushCertificateParser
private boolean
private InputStream
Raw input stream.private OutputStream
Raw output stream.private ReceiveCommandErrorHandler
private RefFilter
Filter used while advertising the refs to the client.private PersonIdent
Identity to record action as within the reflog.The refs we advertised as existing at the start of the connection.private boolean
IfBasePackPushConnection.CAPABILITY_REPORT_STATUS
is enabled.private boolean
IfBasePackPushConnection.CAPABILITY_SIDE_BAND_64K
is enabled.private SignedPushConfig
private ReceivedPackStatistics
private int
Timeout in seconds to wait for client interaction.private TimeoutInputStream
private InterruptTimer
Timer to managetimeout
.private UnpackErrorHandler
private boolean
Whether the client intends to use push options.(package private) String
private final RevWalk
Revision traversal support overdb
. -
Constructor Summary
ConstructorsConstructorDescriptionReceivePack
(Repository into) Create a new pack receive for an open repository. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
Whether any commands have been rejected so far.private void
autoGc()
private void
private void
private void
private void
close()
Close and flush (if necessary) the underlying streams.private void
private void
Enable capabilities based on a previously read capabilities line.protected void
Execute commands to update references.private void
Set the result to fail for any command that was not processed yet.private void
fatalError
(String msg) protected List
<ReceiveCommand> Filter the list of commands according to result.Get objects advertised to the client.Get advertised refs, or the default if not explicitly advertised.Get refs which were advertised to the client.Get the hook used while advertising the refs to the clientGet all of the command received by the current request.Get the commits from the client's shallow file.Get an underlying stream for sending messages to the client.long
Get the size of the received pack file including the index size.Get the user agent of the client.Get the hook invoked after updates occur.Get the hook invoked before updates occur.Get the push certificate used to verify the pusher's identity.private PushCertificateParser
Gets an unmodifiable view of the option strings associated with the push.Returns the statistics on the received pack if available.Get the filter used while advertising the refs to the clientGet identity of the user making the changes in the reflog.Get the repository this receive completes into.Get the RevWalk instance used by this connection.int
Get timeout (in seconds) before aborting an IO operation.Get the current unpack error handler.private boolean
Whether any commands to be executed have been read.private boolean
hasError()
Whether an error occurred that should be advertised.boolean
Get whether or not a pack has been received.protected void
init
(InputStream input, OutputStream output, OutputStream messages) Initialize the instance with the given streams.boolean
Whether the client can delete fromrefs/heads/
.boolean
Whether the client can request refs to be created.boolean
Whether the client can request refs to be deleted.boolean
Whether the client can request non-fast-forward updates of a ref, possibly making objects unreachable.boolean
Whether the server supports receiving push options.boolean
Whether clients may request avoiding noisy progress messages.boolean
isAtomic()
Whether the client's commands should be performed as a single atomic transaction.boolean
Whether this class expects a bi-directional pipe opened between the client and itself.private boolean
isCapabilityEnabled
(String name) Check if the peer requested a capability.boolean
Whether this instance will verify received objects are formatted correctly.boolean
Whether this instance will validate all referenced, but not supplied by the client, objects are reachable from another reference.boolean
Whether there is data expected after the pack footer.boolean
isQuiet()
True if the client wants less verbose output.boolean
Check whether the client expects a side-band stream.private boolean
private boolean
needPack()
Whether a pack is expected based on the list of commands.private InputStream
(package private) static ReceiveCommand
parseCommand
(String line) private void
parseShallow
(String idStr) (package private) void
void
receive
(InputStream input, OutputStream output, OutputStream messages) Execute the receive task on the socket.private void
Receive a pack from the input and store it in the repository.protected void
Receive a pack from the stream and check connectivity if necessary.void
receiveWithExceptionPropagation
(InputStream input, OutputStream output, OutputStream messages) Execute the receive task on the socket.private void
Receive a list of commands from the input.private void
release()
Release any resources used by this object.void
Generate an advertisement of available refs and capabilities.void
Send an error message to the client.void
sendMessage
(String what) Send a message to the client, if it supports receiving them.private void
sendStatusReport
(Throwable unpackError) Send a status report.private void
service()
void
Set the refs advertised by this ReceivePack.void
setAdvertiseRefsHook
(AdvertiseRefsHook advertiseRefsHook) Set the hook used while advertising the refs to the client.void
setAllowBranchDeletes
(boolean canDelete) Configure whether to permit deletion of branches from therefs/heads/
namespace.void
setAllowCreates
(boolean canCreate) Whether to permit create ref commands to be processed.void
setAllowDeletes
(boolean canDelete) Whether to permit delete ref commands to be processed.void
setAllowNonFastForwards
(boolean canRewind) Configure whether to permit the client to ask for non-fast-forward updates of an existing ref.void
setAllowPushOptions
(boolean allow) Configure if the server supports receiving push options.void
setAllowQuiet
(boolean allow) Configure if clients may request the server skip noisy messages.void
setAtomic
(boolean atomic) Configure whether to perform the client's commands as a single atomic transaction.void
setBiDirectionalPipe
(boolean twoWay) Whether this class will assume the socket is a fully bidirectional pipe between the two peers and takes advantage of that by first transmitting the known refs, then waiting to read commands.void
setCheckReceivedObjects
(boolean check) Whether to enable checking received objectsvoid
setCheckReferencedObjectsAreReachable
(boolean b) Validate all referenced but not supplied objects are reachable.void
setEchoCommandFailures
(boolean echo) Deprecated.no widely used Git versions need this any morevoid
setExpectDataAfterPackFooter
(boolean e) Whether there is additional data in InputStream after pack.void
setMaxCommandBytes
(long limit) Set the maximum number of command bytes to read from the client.void
setMaxCommandDiscardBytes
(long limit) Set the maximum number of command bytes to discard from the client.void
setMaxObjectSizeLimit
(long limit) Set the maximum allowed Git object size.void
setMaxPackSizeLimit
(long limit) Set the maximum allowed pack size.void
Set the object checking instance to verify each received object withvoid
Set the hook which is invoked after commands are executed.void
Set the hook which is invoked prior to commands being executed.void
Set the push certificate used to verify the pusher's identity.void
setPushOptions
(List<String> options) Set the push options supplied by the client.void
setReceiveCommandErrorHandler
(ReceiveCommandErrorHandler receiveCommandErrorHandler) Set an error handler forReceiveCommand
.void
setRefFilter
(RefFilter refFilter) Set the filter used while advertising the refs to the client.void
Set the identity of the user appearing in the affected reflogs.void
Set the configuration for push certificate verification.void
setTimeout
(int seconds) Set the timeout before willing to abort an IO call.void
setUnpackErrorHandler
(UnpackErrorHandler unpackErrorHandler) private void
Unlock the pack written by this object.private void
Validate the command list.
-
Field Details
-
db
Database we write the stored objects into. -
walk
Revision traversal support overdb
. -
biDirectionalPipe
private boolean biDirectionalPipeIs the client connection a bi-directional socket or pipe?If true, this class assumes it can perform multiple read and write cycles with the client over the input and output streams. This matches the functionality available with a standard TCP/IP connection, or a local operating system or in-memory pipe.
If false, this class runs in a read everything then output results mode, making it suitable for single round-trip systems RPCs such as HTTP.
-
objectChecker
Should an incoming transfer validate objects? -
allowCreates
private boolean allowCreatesShould an incoming transfer permit create requests? -
allowAnyDeletes
private boolean allowAnyDeletesShould an incoming transfer permit delete requests? -
allowBranchDeletes
private boolean allowBranchDeletes -
allowNonFastForwards
private boolean allowNonFastForwardsShould an incoming transfer permit non-fast-forward requests? -
allowPushOptions
private boolean allowPushOptionsShould an incoming transfer permit push options? -
atomic
private boolean atomicShould the requested ref updates be performed as a single atomic transaction? -
allowOfsDelta
private boolean allowOfsDelta -
allowQuiet
private boolean allowQuiet -
refLogIdent
Identity to record action as within the reflog. -
advertiseRefsHook
Hook used while advertising the refs to the client. -
refFilter
Filter used while advertising the refs to the client. -
timeout
private int timeoutTimeout in seconds to wait for client interaction. -
timer
Timer to managetimeout
. -
timeoutIn
-
origOut
-
rawIn
Raw input stream. -
rawOut
Raw output stream. -
msgOut
Optional message output stream. -
errOut
-
pckIn
Packet line input stream aroundrawIn
. -
pckOut
Packet line output stream aroundrawOut
. -
msgOutWrapper
-
parser
-
refs
The refs we advertised as existing at the start of the connection. -
advertisedHaves
All SHA-1s shown to the client, which can be possible edges. -
enabledCapabilities
Capabilities requested by the client. -
userAgent
String userAgent -
clientShallowCommits
-
commands
-
maxCommandBytes
private long maxCommandBytes -
maxDiscardBytes
private long maxDiscardBytes -
advertiseError
-
sideBand
private boolean sideBandIfBasePackPushConnection.CAPABILITY_SIDE_BAND_64K
is enabled. -
quiet
private boolean quiet -
packLock
Lock around the received pack file, while updating refs. -
checkReferencedAreReachable
private boolean checkReferencedAreReachable -
maxObjectSizeLimit
private long maxObjectSizeLimitGit object size limit -
maxPackSizeLimit
private long maxPackSizeLimitTotal pack size limit -
packSize
The size of the received pack, including index size -
pushCertificateParser
-
signedPushConfig
-
pushCert
-
stats
-
connectivityChecker
Connectivity checker to use.- Since:
- 5.7
-
preReceive
Hook to validate the update commands before execution. -
receiveCommandErrorHandler
-
unpackErrorHandler
-
postReceive
Hook to report on the commands after execution. -
reportStatus
private boolean reportStatusIfBasePackPushConnection.CAPABILITY_REPORT_STATUS
is enabled. -
usePushOptions
private boolean usePushOptionsWhether the client intends to use push options. -
pushOptions
-
-
Constructor Details
-
ReceivePack
Create a new pack receive for an open repository.- Parameters:
into
- the destination repository.
-
-
Method Details
-
getRepository
Get the repository this receive completes into.- Returns:
- the repository this receive completes into.
-
getRevWalk
Get the RevWalk instance used by this connection.- Returns:
- the RevWalk instance used by this connection.
-
getAdvertisedRefs
Get refs which were advertised to the client.- Returns:
- all refs which were advertised to the client, or null if
setAdvertisedRefs(Map, Set)
has not been called yet.
-
setAdvertisedRefs
Set the refs advertised by this ReceivePack.Intended to be called from a
PreReceiveHook
.- Parameters:
allRefs
- explicit set of references to claim as advertised by this ReceivePack instance. This overrides any references that may exist in the source repository. The map is passed to the configuredgetRefFilter()
. If null, assumes all refs were advertised.additionalHaves
- explicit set of additional haves to claim as advertised. If null, assumes the default set of additional haves from the repository.
-
getAdvertisedObjects
Get objects advertised to the client.- Returns:
- the set of objects advertised to the as present in this
repository, or null if
setAdvertisedRefs(Map, Set)
has not been called yet.
-
isCheckReferencedObjectsAreReachable
public boolean isCheckReferencedObjectsAreReachable()Whether this instance will validate all referenced, but not supplied by the client, objects are reachable from another reference.- Returns:
- true if this instance will validate all referenced, but not supplied by the client, objects are reachable from another reference.
-
setCheckReferencedObjectsAreReachable
public void setCheckReferencedObjectsAreReachable(boolean b) Validate all referenced but not supplied objects are reachable.If enabled, this instance will verify that references to objects not contained within the received pack are already reachable through at least one other reference displayed as part of
getAdvertisedRefs()
.This feature is useful when the application doesn't trust the client to not provide a forged SHA-1 reference to an object, in an attempt to access parts of the DAG that they aren't allowed to see and which have been hidden from them via the configured
AdvertiseRefsHook
orRefFilter
.Enabling this feature may imply at least some, if not all, of the same functionality performed by
setCheckReceivedObjects(boolean)
. Applications are encouraged to enable both features, if desired.- Parameters:
b
-true
to enable the additional check.
-
isBiDirectionalPipe
public boolean isBiDirectionalPipe()Whether this class expects a bi-directional pipe opened between the client and itself.- Returns:
- true if this class expects a bi-directional pipe opened between the client and itself. The default is true.
-
setBiDirectionalPipe
public void setBiDirectionalPipe(boolean twoWay) Whether this class will assume the socket is a fully bidirectional pipe between the two peers and takes advantage of that by first transmitting the known refs, then waiting to read commands.- Parameters:
twoWay
- if true, this class will assume the socket is a fully bidirectional pipe between the two peers and takes advantage of that by first transmitting the known refs, then waiting to read commands. If false, this class assumes it must read the commands before writing output and does not perform the initial advertising.
-
isCheckReceivedObjects
public boolean isCheckReceivedObjects()Whether this instance will verify received objects are formatted correctly.- Returns:
true
if this instance will verify received objects are formatted correctly. Validating objects requires more CPU time on this side of the connection.
-
setCheckReceivedObjects
public void setCheckReceivedObjects(boolean check) Whether to enable checking received objects- Parameters:
check
-true
to enable checking received objects; false to assume all received objects are valid.- See Also:
-
setObjectChecker
Set the object checking instance to verify each received object with- Parameters:
impl
- if non-null the object checking instance to verify each received object with; null to disable object checking.- Since:
- 3.4
-
isAllowCreates
public boolean isAllowCreates()Whether the client can request refs to be created.- Returns:
true
if the client can request refs to be created.
-
setAllowCreates
public void setAllowCreates(boolean canCreate) Whether to permit create ref commands to be processed.- Parameters:
canCreate
-true
to permit create ref commands to be processed.
-
isAllowDeletes
public boolean isAllowDeletes()Whether the client can request refs to be deleted.- Returns:
true
if the client can request refs to be deleted.
-
setAllowDeletes
public void setAllowDeletes(boolean canDelete) Whether to permit delete ref commands to be processed.- Parameters:
canDelete
-true
to permit delete ref commands to be processed.
-
isAllowBranchDeletes
public boolean isAllowBranchDeletes()Whether the client can delete fromrefs/heads/
.- Returns:
true
if the client can delete fromrefs/heads/
.- Since:
- 3.6
-
setAllowBranchDeletes
public void setAllowBranchDeletes(boolean canDelete) Configure whether to permit deletion of branches from therefs/heads/
namespace.- Parameters:
canDelete
-true
to permit deletion of branches from therefs/heads/
namespace.- Since:
- 3.6
-
isAllowNonFastForwards
public boolean isAllowNonFastForwards()Whether the client can request non-fast-forward updates of a ref, possibly making objects unreachable.- Returns:
true
if the client can request non-fast-forward updates of a ref, possibly making objects unreachable.
-
setAllowNonFastForwards
public void setAllowNonFastForwards(boolean canRewind) Configure whether to permit the client to ask for non-fast-forward updates of an existing ref.- Parameters:
canRewind
-true
to permit the client to ask for non-fast-forward updates of an existing ref.
-
isAtomic
public boolean isAtomic()Whether the client's commands should be performed as a single atomic transaction.- Returns:
true
if the client's commands should be performed as a single atomic transaction.- Since:
- 4.4
-
setAtomic
public void setAtomic(boolean atomic) Configure whether to perform the client's commands as a single atomic transaction.- Parameters:
atomic
-true
to perform the client's commands as a single atomic transaction.- Since:
- 4.4
-
getRefLogIdent
Get identity of the user making the changes in the reflog.- Returns:
- identity of the user making the changes in the reflog.
-
setRefLogIdent
Set the identity of the user appearing in the affected reflogs.The timestamp portion of the identity is ignored. A new identity with the current timestamp will be created automatically when the updates occur and the log records are written.
- Parameters:
pi
- identity of the user. If null the identity will be automatically determined based on the repository configuration.
-
getAdvertiseRefsHook
Get the hook used while advertising the refs to the client- Returns:
- the hook used while advertising the refs to the client
-
getRefFilter
Get the filter used while advertising the refs to the client- Returns:
- the filter used while advertising the refs to the client
-
setAdvertiseRefsHook
Set the hook used while advertising the refs to the client.If the
AdvertiseRefsHook
chooses to callsetAdvertisedRefs(Map,Set)
, only refs set by this hook and selected by theRefFilter
will be shown to the client. Clients may still attempt to create or update a reference not advertised by the configuredAdvertiseRefsHook
. These attempts should be rejected by a matchingPreReceiveHook
.- Parameters:
advertiseRefsHook
- the hook; may be null to show all refs.
-
setRefFilter
Set the filter used while advertising the refs to the client.Only refs allowed by this filter will be shown to the client. The filter is run against the refs specified by the
AdvertiseRefsHook
(if applicable).- Parameters:
refFilter
- the filter; may be null to show all refs.
-
getTimeout
public int getTimeout()Get timeout (in seconds) before aborting an IO operation.- Returns:
- timeout (in seconds) before aborting an IO operation.
-
setTimeout
public void setTimeout(int seconds) Set the timeout before willing to abort an IO call.- Parameters:
seconds
- number of seconds to wait (with no data transfer occurring) before aborting an IO read or write operation with the connected client.
-
setMaxCommandBytes
public void setMaxCommandBytes(long limit) Set the maximum number of command bytes to read from the client.- Parameters:
limit
- command limit in bytes; if 0 there is no limit.- Since:
- 4.7
-
setMaxCommandDiscardBytes
public void setMaxCommandDiscardBytes(long limit) Set the maximum number of command bytes to discard from the client.Discarding remaining bytes allows this instance to consume the rest of the command block and send a human readable over-limit error via the side-band channel. If the client sends an excessive number of bytes this limit kicks in and the instance disconnects, resulting in a non-specific 'pipe closed', 'end of stream', or similar generic error at the client.
When the limit is set to
-1
the implementation will default to the larger of3 * maxCommandBytes
or3 MiB
.- Parameters:
limit
- discard limit in bytes; if 0 there is no limit; if -1 the implementation tries to set a reasonable default.- Since:
- 4.7
-
setMaxObjectSizeLimit
public void setMaxObjectSizeLimit(long limit) Set the maximum allowed Git object size.If an object is larger than the given size the pack-parsing will throw an exception aborting the receive-pack operation.
- Parameters:
limit
- the Git object size limit. If zero then there is not limit.
-
setMaxPackSizeLimit
public void setMaxPackSizeLimit(long limit) Set the maximum allowed pack size.A pack exceeding this size will be rejected.
- Parameters:
limit
- the pack size limit, in bytes- Since:
- 3.3
-
isSideBand
Check whether the client expects a side-band stream.- Returns:
- true if the client has advertised a side-band capability, false otherwise.
- Throws:
RequestNotYetReadException
- if the client's request has not yet been read from the wire, so we do not know if they expect side-band. Note that the client may have already written the request, it just has not been read.
-
isAllowQuiet
public boolean isAllowQuiet()Whether clients may request avoiding noisy progress messages.- Returns:
- true if clients may request avoiding noisy progress messages.
- Since:
- 4.0
-
setAllowQuiet
public void setAllowQuiet(boolean allow) Configure if clients may request the server skip noisy messages.- Parameters:
allow
- true to allow clients to request quiet behavior; false to refuse quiet behavior and send messages anyway. This may be necessary if processing is slow and the client-server network connection can timeout.- Since:
- 4.0
-
isAllowPushOptions
public boolean isAllowPushOptions()Whether the server supports receiving push options.- Returns:
- true if the server supports receiving push options.
- Since:
- 4.5
-
setAllowPushOptions
public void setAllowPushOptions(boolean allow) Configure if the server supports receiving push options.- Parameters:
allow
- true to optionally accept option strings from the client.- Since:
- 4.5
-
isQuiet
True if the client wants less verbose output.- Returns:
- true if the client has requested the server to be less verbose.
- Throws:
RequestNotYetReadException
- if the client's request has not yet been read from the wire, so we do not know if they expect side-band. Note that the client may have already written the request, it just has not been read.- Since:
- 4.0
-
setSignedPushConfig
Set the configuration for push certificate verification.- Parameters:
cfg
- new configuration; if this object is null or itsSignedPushConfig.getCertNonceSeed()
is null, push certificate verification will be disabled.- Since:
- 4.1
-
getPushCertificateParser
-
getPeerUserAgent
Get the user agent of the client.If the client is new enough to use
agent=
capability that value will be returned. Older HTTP clients may also supply their version using the HTTPUser-Agent
header. The capability overrides the HTTP header if both are available.When an HTTP request has been received this method returns the HTTP
User-Agent
header value until capabilities have been parsed.- Returns:
- user agent supplied by the client. Available only if the client is new enough to advertise its user agent.
- Since:
- 4.0
-
getAllCommands
Get all of the command received by the current request.- Returns:
- all of the command received by the current request.
-
setReceiveCommandErrorHandler
Set an error handler forReceiveCommand
.- Parameters:
receiveCommandErrorHandler
-- Since:
- 5.7
-
sendError
Send an error message to the client.If any error messages are sent before the references are advertised to the client, the errors will be sent instead of the advertisement and the receive operation will be aborted. All clients should receive and display such early stage errors.
If the reference advertisements have already been sent, messages are sent in a side channel. If the client doesn't support receiving messages, the message will be discarded, with no other indication to the caller or to the client.
PreReceiveHook
s should always try to useReceiveCommand.setResult(Result, String)
with a result status ofReceiveCommand.Result.REJECTED_OTHER_REASON
to indicate any reasons for rejecting an update. Messages attached to a command are much more likely to be returned to the client.- Parameters:
what
- string describing the problem identified by the hook. The string must not end with an LF, and must not contain an LF.
-
fatalError
-
sendMessage
Send a message to the client, if it supports receiving them.If the client doesn't support receiving messages, the message will be discarded, with no other indication to the caller or to the client.
- Parameters:
what
- string describing the problem identified by the hook. The string must not end with an LF, and must not contain an LF.
-
getMessageOutputStream
Get an underlying stream for sending messages to the client.- Returns:
- an underlying stream for sending messages to the client.
-
hasReceivedPack
public boolean hasReceivedPack()Get whether or not a pack has been received. This can be called before callinggetPackSize()
to avoid causingIllegalStateException
when the pack size was not set because no pack was received.- Returns:
- true if a pack has been received.
- Since:
- 5.6
-
getPackSize
public long getPackSize()Get the size of the received pack file including the index size. This can only be called if the pack is already received.- Returns:
- the size of the received pack including index size
- Throws:
IllegalStateException
- if called before the pack has been received- Since:
- 3.3
-
getClientShallowCommits
Get the commits from the client's shallow file.- Returns:
- if the client is a shallow repository, the list of edge commits that define the client's shallow boundary. Empty set if the client is earlier than Git 1.9, or is a full clone.
-
hasCommands
private boolean hasCommands()Whether any commands to be executed have been read.- Returns:
true
if any commands to be executed have been read.
-
hasError
private boolean hasError()Whether an error occurred that should be advertised.- Returns:
- true if an error occurred that should be advertised.
-
init
Initialize the instance with the given streams. Visible for out-of-tree subclasses (e.g. tests that need to set the streams without going through theservice()
method).- Parameters:
input
- raw input to read client commands and pack data from. Caller must ensure the input is buffered, otherwise read performance may suffer.output
- response back to the Git network client. Caller must ensure the output is buffered, otherwise write performance may suffer.messages
- secondary "notice" channel to send additional messages out through. When run over SSH this should be tied back to the standard error channel of the command execution. For most other network connections this should be null.
-
getAdvertisedOrDefaultRefs
Get advertised refs, or the default if not explicitly advertised.- Returns:
- advertised refs, or the default if not explicitly advertised.
-
receivePackAndCheckConnectivity
protected void receivePackAndCheckConnectivity() throws IOException, LargeObjectException, SubmoduleValidator.SubmoduleValidationExceptionReceive a pack from the stream and check connectivity if necessary. Visible for out-of-tree subclasses. Subclasses overriding this method should invoke this implementation, as it alters the instance state (e.g. it reads the pack from the input and parses it before running the connectivity checks).- Throws:
IOException
- an error occurred during unpacking or connectivity checking.LargeObjectException
- an large object needs to be opened for the check.SubmoduleValidator.SubmoduleValidationException
- fails to validate the submodule.
-
unlockPack
Unlock the pack written by this object.- Throws:
IOException
- the pack could not be unlocked.
-
sendAdvertisedRefs
public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException Generate an advertisement of available refs and capabilities.- Parameters:
adv
- the advertisement formatter.- Throws:
IOException
- the formatter failed to write an advertisement.ServiceMayNotContinueException
- the hook denied advertisement.
-
getReceivedPackStatistics
Returns the statistics on the received pack if available. This should be called afterreceivePack()
is called.- Returns:
- ReceivedPackStatistics
- Since:
- 4.6
-
recvCommands
Receive a list of commands from the input.- Throws:
IOException
-
discardCommands
private void discardCommands() -
parseShallow
- Throws:
PackProtocolException
-
readPostCommands
- Parameters:
in
- request stream.- Throws:
IOException
- request line cannot be read.
-
enableCapabilities
private void enableCapabilities()Enable capabilities based on a previously read capabilities line. -
isCapabilityEnabled
Check if the peer requested a capability.- Parameters:
name
- protocol name identifying the capability.- Returns:
- true if the peer requested the capability to be enabled.
-
checkRequestWasRead
private void checkRequestWasRead() -
needPack
private boolean needPack()Whether a pack is expected based on the list of commands.- Returns:
true
if a pack is expected based on the list of commands.
-
receivePack
Receive a pack from the input and store it in the repository.- Throws:
IOException
- an error occurred reading or indexing the pack.
-
packInputStream
-
needCheckConnectivity
private boolean needCheckConnectivity() -
checkSubmodules
private void checkSubmodules() throws IOException, LargeObjectException, SubmoduleValidator.SubmoduleValidationException -
checkConnectivity
- Throws:
IOException
-
createConnectivityCheckInfo
-
validateCommands
private void validateCommands()Validate the command list. -
anyRejects
private boolean anyRejects()Whether any commands have been rejected so far.- Returns:
- if any commands have been rejected so far.
-
failPendingCommands
private void failPendingCommands()Set the result to fail for any command that was not processed yet. -
filterCommands
Filter the list of commands according to result.- Parameters:
want
- desired status to filter by.- Returns:
- a copy of the command list containing only those commands with the desired status.
- Since:
- 5.7
-
executeCommands
protected void executeCommands()Execute commands to update references.- Since:
- 5.7
-
sendStatusReport
Send a status report.- Parameters:
unpackError
- an error that occurred during unpacking, ornull
- Throws:
IOException
- an error occurred writing the status report.- Since:
- 5.6
-
close
Close and flush (if necessary) the underlying streams.- Throws:
IOException
-
release
Release any resources used by this object.- Throws:
IOException
- the pack could not be unlocked.
-
getPushCertificate
Get the push certificate used to verify the pusher's identity.Only valid after commands are read from the wire.
- Returns:
- the parsed certificate, or null if push certificates are disabled or no cert was presented by the client.
- Since:
- 4.1
-
setPushCertificate
Set the push certificate used to verify the pusher's identity.Should only be called if reconstructing an instance without going through the normal
recvCommands()
flow.- Parameters:
cert
- the push certificate to set.- Since:
- 4.1
-
getPushOptions
Gets an unmodifiable view of the option strings associated with the push.- Returns:
- an unmodifiable view of pushOptions, or null (if pushOptions is).
- Since:
- 4.5
-
setPushOptions
Set the push options supplied by the client.Should only be called if reconstructing an instance without going through the normal
recvCommands()
flow.- Parameters:
options
- the list of options supplied by the client. TheReceivePack
instance takes ownership of this list. Callers are encouraged to first create a copy if the list may be modified later.- Since:
- 4.5
-
getPreReceiveHook
Get the hook invoked before updates occur.- Returns:
- the hook invoked before updates occur.
-
setPreReceiveHook
Set the hook which is invoked prior to commands being executed.Only valid commands (those which have no obvious errors according to the received input and this instance's configuration) are passed into the hook. The hook may mark a command with a result of any value other than
ReceiveCommand.Result.NOT_ATTEMPTED
to block its execution.The hook may be called with an empty command collection if the current set is completely invalid.
- Parameters:
h
- the hook instance; may be null to disable the hook.
-
getPostReceiveHook
Get the hook invoked after updates occur.- Returns:
- the hook invoked after updates occur.
-
setPostReceiveHook
Set the hook which is invoked after commands are executed.Only successful commands (type is
ReceiveCommand.Result.OK
) are passed into the hook. The hook may be called with an empty command collection if the current set all resulted in an error.- Parameters:
h
- the hook instance; may be null to disable the hook.
-
getUnpackErrorHandler
Get the current unpack error handler.- Returns:
- the current unpack error handler.
- Since:
- 5.8
-
setUnpackErrorHandler
- Parameters:
unpackErrorHandler
- the unpackErrorHandler to set- Since:
- 5.7
-
setEchoCommandFailures
Deprecated.no widely used Git versions need this any moreSet whether this class will report command failures as warning messages before sending the command results.- Parameters:
echo
- if true this class will report command failures as warning messages before sending the command results. This is usually not necessary, but may help buggy Git clients that discard the errors when all branches fail.
-
receive
public void receive(InputStream input, OutputStream output, OutputStream messages) throws IOException Execute the receive task on the socket.- Parameters:
input
- raw input to read client commands and pack data from. Caller must ensure the input is buffered, otherwise read performance may suffer.output
- response back to the Git network client. Caller must ensure the output is buffered, otherwise write performance may suffer.messages
- secondary "notice" channel to send additional messages out through. When run over SSH this should be tied back to the standard error channel of the command execution. For most other network connections this should be null.- Throws:
IOException
-
receiveWithExceptionPropagation
public void receiveWithExceptionPropagation(InputStream input, OutputStream output, OutputStream messages) throws IOException Execute the receive task on the socket.Same as
receive(java.io.InputStream, java.io.OutputStream, java.io.OutputStream)
, but the exceptions are not reported to the client yet.- Parameters:
input
- raw input to read client commands and pack data from. Caller must ensure the input is buffered, otherwise read performance may suffer.output
- response back to the Git network client. Caller must ensure the output is buffered, otherwise write performance may suffer.messages
- secondary "notice" channel to send additional messages out through. When run over SSH this should be tied back to the standard error channel of the command execution. For most other network connections this should be null.- Throws:
IOException
- Since:
- 5.7
-
service
- Throws:
IOException
-
autoGc
private void autoGc() -
parseCommand
- Throws:
PackProtocolException
-
FirstCommand
instead.