public class ReceivePack
extends java.lang.Object
Constructor and Description |
---|
ReceivePack(Repository into)
Create a new pack receive for an open repository.
|
Modifier and Type | Method and Description |
---|---|
java.util.Set<ObjectId> |
getAdvertisedObjects() |
java.util.Map<java.lang.String,Ref> |
getAdvertisedRefs() |
java.util.List<ReceiveCommand> |
getAllCommands() |
PostReceiveHook |
getPostReceiveHook() |
PreReceiveHook |
getPreReceiveHook() |
RefFilter |
getRefFilter() |
PersonIdent |
getRefLogIdent() |
Repository |
getRepository() |
RevWalk |
getRevWalk() |
int |
getTimeout() |
boolean |
isAllowCreates() |
boolean |
isAllowDeletes() |
boolean |
isAllowNonFastForwards() |
boolean |
isBiDirectionalPipe() |
boolean |
isCheckReceivedObjects() |
boolean |
isCheckReferencedObjectsAreReachable() |
void |
receive(java.io.InputStream input,
java.io.OutputStream output,
java.io.OutputStream messages)
Execute the receive task on the socket.
|
void |
sendAdvertisedRefs(RefAdvertiser adv)
Generate an advertisement of available refs and capabilities.
|
void |
sendError(java.lang.String what)
Send an error message to the client.
|
void |
sendMessage(java.lang.String what)
Send a message to the client, if it supports receiving them.
|
void |
setAllowCreates(boolean canCreate) |
void |
setAllowDeletes(boolean canDelete) |
void |
setAllowNonFastForwards(boolean canRewind) |
void |
setBiDirectionalPipe(boolean twoWay) |
void |
setCheckReceivedObjects(boolean check) |
void |
setCheckReferencedObjectsAreReachable(boolean b)
Validate all referenced but not supplied objects are reachable.
|
void |
setMaxObjectSizeLimit(long limit)
Set the maximum allowed Git object size.
|
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 |
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 |
setTimeout(int seconds)
Set the timeout before willing to abort an IO call.
|
public ReceivePack(Repository into)
into
- the destination repository.public final Repository getRepository()
public final RevWalk getRevWalk()
public final java.util.Map<java.lang.String,Ref> getAdvertisedRefs()
public final java.util.Set<ObjectId> getAdvertisedObjects()
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 selected by the getRefFilter()
and 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 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 isCheckReceivedObjects()
public void setCheckReceivedObjects(boolean check)
check
- true to enable checking received objects; false to assume all
received objects are valid.public boolean isAllowCreates()
public void setAllowCreates(boolean canCreate)
canCreate
- true to permit create ref commands to be processed.public boolean isAllowDeletes()
public void setAllowDeletes(boolean canDelete)
canDelete
- true to permit delete ref commands to be processed.public boolean isAllowNonFastForwards()
public void setAllowNonFastForwards(boolean canRewind)
canRewind
- true to permit the client to ask for non-fast-forward updates
of an existing ref.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 RefFilter getRefFilter()
public void setRefFilter(RefFilter refFilter)
Only refs allowed by this filter will be shown to the client.
Clients may still attempt to create or update a reference hidden
by the configured RefFilter
. These attempts should be
rejected by a matching PreReceiveHook
.
refFilter
- the filter; may be null to show all refs.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 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 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 java.util.List<ReceiveCommand> getAllCommands()
public void sendError(java.lang.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(java.lang.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 void receive(java.io.InputStream input, java.io.OutputStream output, java.io.OutputStream messages) throws java.io.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.java.io.IOException
public void sendAdvertisedRefs(RefAdvertiser adv) throws java.io.IOException
adv
- the advertisement formatter.java.io.IOException
- the formatter failed to write an advertisement.Copyright © 2012. All Rights Reserved.