org.eclipse.jgit.transport
Class ReceivePack

java.lang.Object
  extended by org.eclipse.jgit.transport.ReceivePack

public class ReceivePack
extends Object

Implements the server side of a push connection, receiving objects.


Constructor Summary
ReceivePack(Repository into)
          Create a new pack receive for an open repository.
 
Method Summary
 Set<ObjectId> getAdvertisedObjects()
           
 Map<String,Ref> getAdvertisedRefs()
           
 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(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 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReceivePack

public ReceivePack(Repository into)
Create a new pack receive for an open repository.

Parameters:
into - the destination repository.
Method Detail

getRepository

public final Repository getRepository()
Returns:
the repository this receive completes into.

getRevWalk

public final RevWalk getRevWalk()
Returns:
the RevWalk instance used by this connection.

getAdvertisedRefs

public final Map<String,Ref> getAdvertisedRefs()
Returns:
all refs which were advertised to the client.

getAdvertisedObjects

public final Set<ObjectId> getAdvertisedObjects()
Returns:
the set of objects advertised as present in this repository.

isCheckReferencedObjectsAreReachable

public boolean isCheckReferencedObjectsAreReachable()
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 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.

Parameters:
b - true to enable the additional check.

isBiDirectionalPipe

public boolean isBiDirectionalPipe()
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)
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()
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)
Parameters:
check - true to enable checking received objects; false to assume all received objects are valid.

isAllowCreates

public boolean isAllowCreates()
Returns:
true if the client can request refs to be created.

setAllowCreates

public void setAllowCreates(boolean canCreate)
Parameters:
canCreate - true to permit create ref commands to be processed.

isAllowDeletes

public boolean isAllowDeletes()
Returns:
true if the client can request refs to be deleted.

setAllowDeletes

public void setAllowDeletes(boolean canDelete)
Parameters:
canDelete - true to permit delete ref commands to be processed.

isAllowNonFastForwards

public boolean isAllowNonFastForwards()
Returns:
true if the client can request non-fast-forward updates of a ref, possibly making objects unreachable.

setAllowNonFastForwards

public void setAllowNonFastForwards(boolean canRewind)
Parameters:
canRewind - true to permit the client to ask for non-fast-forward updates of an existing ref.

getRefLogIdent

public PersonIdent getRefLogIdent()
Returns:
identity of the user making the changes in the reflog.

setRefLogIdent

public void setRefLogIdent(PersonIdent pi)
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.

getRefFilter

public RefFilter getRefFilter()
Returns:
the filter used while advertising the refs to the client

setRefFilter

public void setRefFilter(RefFilter refFilter)
Set the filter used while advertising the refs to the client.

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.

Parameters:
refFilter - the filter; may be null to show all refs.

getPreReceiveHook

public PreReceiveHook getPreReceiveHook()
Returns:
get the hook invoked before updates occur.

setPreReceiveHook

public void setPreReceiveHook(PreReceiveHook h)
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

public PostReceiveHook getPostReceiveHook()
Returns:
get the hook invoked after updates occur.

setPostReceiveHook

public void setPostReceiveHook(PostReceiveHook h)
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.

getTimeout

public int getTimeout()
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.

getAllCommands

public List<ReceiveCommand> getAllCommands()
Returns:
all of the command received by the current request.

sendError

public void sendError(String what)
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.

PreReceiveHooks 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.

Parameters:
what - string describing the problem identified by the hook. The string must not end with an LF, and must not contain an LF.

sendMessage

public void sendMessage(String what)
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.

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

sendAdvertisedRefs

public void sendAdvertisedRefs(RefAdvertiser adv)
                        throws IOException
Generate an advertisement of available refs and capabilities.

Parameters:
adv - the advertisement formatter.
Throws:
IOException - the formatter failed to write an advertisement.


Copyright © 2011. All Rights Reserved.