public class ReceivePack extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ReceivePack.FirstLine
Deprecated.
Use
FirstCommand instead. |
Modifier and Type | Field and Description |
---|---|
protected ConnectivityChecker |
connectivityChecker
Connectivity checker to use.
|
Constructor and Description |
---|
ReceivePack(Repository into)
Create a new pack receive for an open repository.
|
Modifier and Type | Method and Description |
---|---|
protected void |
executeCommands()
Execute commands to update references.
|
protected List<ReceiveCommand> |
filterCommands(ReceiveCommand.Result want)
Filter the list of commands according to result.
|
Set<ObjectId> |
getAdvertisedObjects()
Get objects advertised to the client.
|
Map<String,Ref> |
getAdvertisedRefs()
Get refs which were advertised to the client.
|
AdvertiseRefsHook |
getAdvertiseRefsHook()
Get the hook used while advertising the refs to the client
|
List<ReceiveCommand> |
getAllCommands()
Get all of the command received by the current request.
|
OutputStream |
getMessageOutputStream()
Get an underlying stream for sending messages to the client.
|
long |
getPackSize()
Get the size of the received pack file including the index size.
|
String |
getPeerUserAgent()
Get the user agent of the client.
|
PostReceiveHook |
getPostReceiveHook()
Get the hook invoked after updates occur.
|
PreReceiveHook |
getPreReceiveHook()
Get the hook invoked before updates occur.
|
PushCertificate |
getPushCertificate()
Get the push certificate used to verify the pusher's identity.
|
List<String> |
getPushOptions()
Gets an unmodifiable view of the option strings associated with the push.
|
ReceivedPackStatistics |
getReceivedPackStatistics()
Returns the statistics on the received pack if available.
|
RefFilter |
getRefFilter()
Get the filter used while advertising the refs to the client
|
PersonIdent |
getRefLogIdent()
Get identity of the user making the changes in the reflog.
|
Repository |
getRepository()
Get the repository this receive completes into.
|
RevWalk |
getRevWalk()
Get the RevWalk instance used by this connection.
|
int |
getTimeout()
Get timeout (in seconds) before aborting an IO operation.
|
UnpackErrorHandler |
getUnpackErrorHandler()
Get the current unpack error handler.
|
boolean |
hasReceivedPack()
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 |
isAllowBranchDeletes()
Whether the client can delete from
refs/heads/ . |
boolean |
isAllowCreates()
Whether the client can request refs to be created.
|
boolean |
isAllowDeletes()
Whether the client can request refs to be deleted.
|
boolean |
isAllowNonFastForwards()
Whether the client can request non-fast-forward updates of a ref,
possibly making objects unreachable.
|
boolean |
isAllowPushOptions()
Whether the server supports receiving push options.
|
boolean |
isAllowQuiet()
Whether clients may request avoiding noisy progress messages.
|
boolean |
isAtomic()
Whether the client's commands should be performed as a single atomic
transaction.
|
boolean |
isBiDirectionalPipe()
Whether this class expects a bi-directional pipe opened between the
client and itself.
|
boolean |
isCheckReceivedObjects()
Whether this instance will verify received objects are formatted
correctly.
|
boolean |
isCheckReferencedObjectsAreReachable()
Whether this instance will validate all referenced, but not supplied by
the client, objects are reachable from another reference.
|
boolean |
isExpectDataAfterPackFooter()
Whether there is data expected after the pack footer.
|
boolean |
isQuiet()
True if the client wants less verbose output.
|
boolean |
isSideBand()
Check whether the client expects a side-band stream.
|
void |
receive(InputStream input,
OutputStream output,
OutputStream messages)
Execute the receive task on the socket.
|
protected void |
receivePackAndCheckConnectivity()
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.
|
void |
sendAdvertisedRefs(RefAdvertiser adv)
Generate an advertisement of available refs and capabilities.
|
void |
sendError(String what)
Send an error message to the client.
|
void |
sendMessage(String what)
Send a message to the client, if it supports receiving them.
|
void |
setAdvertisedRefs(Map<String,Ref> allRefs,
Set<ObjectId> additionalHaves)
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 the
refs/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 objects
|
void |
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 more
|
void |
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 |
setObjectChecker(ObjectChecker impl)
Set the object checking instance to verify each received object with
|
void |
setPostReceiveHook(PostReceiveHook h)
Set the hook which is invoked after commands are executed.
|
void |
setPreReceiveHook(PreReceiveHook h)
Set the hook which is invoked prior to commands being executed.
|
void |
setPushCertificate(PushCertificate cert)
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 for
ReceiveCommand . |
void |
setRefFilter(RefFilter refFilter)
Set the filter used while advertising the refs to the client.
|
void |
setRefLogIdent(PersonIdent pi)
Set the identity of the user appearing in the affected reflogs.
|
void |
setSignedPushConfig(SignedPushConfig cfg)
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) |
protected ConnectivityChecker connectivityChecker
public ReceivePack(Repository into)
into
- the destination repository.public Repository getRepository()
public RevWalk getRevWalk()
public Map<String,Ref> getAdvertisedRefs()
setAdvertisedRefs(Map, Set)
has not been called yet.public void setAdvertisedRefs(Map<String,Ref> allRefs, Set<ObjectId> additionalHaves)
Intended to be called from a
PreReceiveHook
.
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
configured getRefFilter()
. 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.public final Set<ObjectId> getAdvertisedObjects()
setAdvertisedRefs(Map, Set)
has
not been called yet.public boolean isCheckReferencedObjectsAreReachable()
public void setCheckReferencedObjectsAreReachable(boolean b)
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
or
RefFilter
.
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.
b
- true
to enable the additional check.public boolean isBiDirectionalPipe()
public void setBiDirectionalPipe(boolean twoWay)
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.public boolean isExpectDataAfterPackFooter()
true
if there is data expected after the pack footer.public void setExpectDataAfterPackFooter(boolean e)
e
- true
if there is additional data in InputStream after
pack.public boolean isCheckReceivedObjects()
true
if this instance will verify received objects are
formatted correctly. Validating objects requires more CPU time on
this side of the connection.public void setCheckReceivedObjects(boolean check)
check
- true
to enable checking received objects; false to
assume all received objects are valid.setObjectChecker(ObjectChecker)
public void setObjectChecker(ObjectChecker impl)
impl
- if non-null the object checking instance to verify each
received object with; null to disable object checking.public boolean isAllowCreates()
true
if the client can request refs to be created.public void setAllowCreates(boolean canCreate)
canCreate
- true
to permit create ref commands to be processed.public boolean isAllowDeletes()
true
if the client can request refs to be deleted.public void setAllowDeletes(boolean canDelete)
canDelete
- true
to permit delete ref commands to be processed.public boolean isAllowBranchDeletes()
refs/heads/
.true
if the client can delete from refs/heads/
.public void setAllowBranchDeletes(boolean canDelete)
refs/heads/
namespace.canDelete
- true
to permit deletion of branches from the
refs/heads/
namespace.public boolean isAllowNonFastForwards()
true
if the client can request non-fast-forward updates
of a ref, possibly making objects unreachable.public void setAllowNonFastForwards(boolean canRewind)
canRewind
- true
to permit the client to ask for non-fast-forward
updates of an existing ref.public boolean isAtomic()
true
if the client's commands should be performed as a
single atomic transaction.public void setAtomic(boolean atomic)
atomic
- true
to perform the client's commands as a single
atomic transaction.public PersonIdent getRefLogIdent()
public void setRefLogIdent(PersonIdent pi)
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.
pi
- identity of the user. If null the identity will be
automatically determined based on the repository
configuration.public AdvertiseRefsHook getAdvertiseRefsHook()
public RefFilter getRefFilter()
public void setAdvertiseRefsHook(AdvertiseRefsHook advertiseRefsHook)
If the AdvertiseRefsHook
chooses to
call setAdvertisedRefs(Map,Set)
, only refs set by this hook
and selected by the RefFilter
will be shown to the client. Clients may still attempt to create or
update a reference not advertised by the configured
AdvertiseRefsHook
. These attempts
should be rejected by a matching
PreReceiveHook
.
advertiseRefsHook
- the hook; may be null to show all refs.public void setRefFilter(RefFilter refFilter)
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).
refFilter
- the filter; may be null to show all refs.public int getTimeout()
public void setTimeout(int seconds)
seconds
- number of seconds to wait (with no data transfer occurring)
before aborting an IO read or write operation with the
connected client.public void setMaxCommandBytes(long limit)
limit
- command limit in bytes; if 0 there is no limit.public void setMaxCommandDiscardBytes(long limit)
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 of 3 * maxCommandBytes
or 3 MiB
.
limit
- discard limit in bytes; if 0 there is no limit; if -1 the
implementation tries to set a reasonable default.public void setMaxObjectSizeLimit(long limit)
If an object is larger than the given size the pack-parsing will throw an exception aborting the receive-pack operation.
limit
- the Git object size limit. If zero then there is not limit.public void setMaxPackSizeLimit(long limit)
A pack exceeding this size will be rejected.
limit
- the pack size limit, in bytespublic boolean isSideBand() throws RequestNotYetReadException
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.public boolean isAllowQuiet()
public void setAllowQuiet(boolean allow)
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.public boolean isAllowPushOptions()
public void setAllowPushOptions(boolean allow)
allow
- true to optionally accept option strings from the client.public boolean isQuiet() throws RequestNotYetReadException
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.public void setSignedPushConfig(SignedPushConfig cfg)
cfg
- new configuration; if this object is null or its
SignedPushConfig.getCertNonceSeed()
is null, push
certificate verification will be disabled.public String getPeerUserAgent()
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 HTTP User-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.
public List<ReceiveCommand> getAllCommands()
public void setReceiveCommandErrorHandler(ReceiveCommandErrorHandler receiveCommandErrorHandler)
ReceiveCommand
.receiveCommandErrorHandler
- public void sendError(String what)
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
use
ReceiveCommand.setResult(Result, String)
with a result status of
ReceiveCommand.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.
what
- string describing the problem identified by the hook. The
string must not end with an LF, and must not contain an LF.public void sendMessage(String what)
If the client doesn't support receiving messages, the message will be discarded, with no other indication to the caller or to the client.
what
- string describing the problem identified by the hook. The
string must not end with an LF, and must not contain an LF.public OutputStream getMessageOutputStream()
public boolean hasReceivedPack()
getPackSize()
to avoid causing
IllegalStateException
when the pack size was not set because no
pack was received.public long getPackSize()
IllegalStateException
- if called before the pack has been receivedprotected void init(InputStream input, OutputStream output, OutputStream messages)
service()
method).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.protected void receivePackAndCheckConnectivity() throws IOException, LargeObjectException, SubmoduleValidator.SubmoduleValidationException
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.public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException
adv
- the advertisement formatter.IOException
- the formatter failed to write an advertisement.ServiceMayNotContinueException
- the hook denied advertisement.@Nullable public ReceivedPackStatistics getReceivedPackStatistics()
receivePack()
is called.protected List<ReceiveCommand> filterCommands(ReceiveCommand.Result want)
want
- desired status to filter by.protected void executeCommands()
public PushCertificate getPushCertificate()
Only valid after commands are read from the wire.
public void setPushCertificate(PushCertificate cert)
Should only be called if reconstructing an instance without going through
the normal recvCommands()
flow.
cert
- the push certificate to set.@Nullable public List<String> getPushOptions()
public void setPushOptions(@Nullable List<String> options)
Should only be called if reconstructing an instance without going through
the normal recvCommands()
flow.
options
- the list of options supplied by the client. The
ReceivePack
instance takes ownership of this list.
Callers are encouraged to first create a copy if the list may
be modified later.public PreReceiveHook getPreReceiveHook()
public void setPreReceiveHook(PreReceiveHook h)
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.
h
- the hook instance; may be null to disable the hook.public PostReceiveHook getPostReceiveHook()
public void setPostReceiveHook(PostReceiveHook h)
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.
h
- the hook instance; may be null to disable the hook.public UnpackErrorHandler getUnpackErrorHandler()
public void setUnpackErrorHandler(UnpackErrorHandler unpackErrorHandler)
unpackErrorHandler
- the unpackErrorHandler to set@Deprecated public void setEchoCommandFailures(boolean echo)
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.public void receive(InputStream input, OutputStream output, OutputStream messages) throws IOException
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.IOException
public void receiveWithExceptionPropagation(InputStream input, OutputStream output, OutputStream messages) throws IOException
Same as receive(java.io.InputStream, java.io.OutputStream, java.io.OutputStream)
, but the exceptions are not reported to the
client yet.
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.IOException
Copyright © 2020 Eclipse JGit Project. All rights reserved.