org.eclipse.jgit.transport
Class ReceivePack

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

public class ReceivePack
extends java.lang.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
 java.util.Map<java.lang.String,Ref> getAdvertisedRefs()
           
 java.util.List<ReceiveCommand> getAllCommands()
           
 PostReceiveHook getPostReceiveHook()
           
 PreReceiveHook getPreReceiveHook()
           
 PersonIdent getRefLogIdent()
           
 Repository getRepository()
           
 RevWalk getRevWalk()
           
 int getTimeout()
           
 boolean isAllowCreates()
           
 boolean isAllowDeletes()
           
 boolean isAllowNonFastForwards()
           
 boolean isCheckReceivedObjects()
           
 void receive(java.io.InputStream input, java.io.OutputStream output, java.io.OutputStream messages)
          Execute the receive task on the socket.
 void sendError(java.lang.String what)
          Send an error message to the client, if it supports receiving them.
 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 setCheckReceivedObjects(boolean check)
           
 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 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 java.util.Map<java.lang.String,Ref> getAdvertisedRefs()
Returns:
all refs which were advertised to the client.

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.

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 java.util.List<ReceiveCommand> getAllCommands()
Returns:
all of the command received by the current request.

sendError

public void sendError(java.lang.String what)
Send an error 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.

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(java.lang.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(java.io.InputStream input,
                    java.io.OutputStream output,
                    java.io.OutputStream messages)
             throws java.io.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:
java.io.IOException