org.eclipse.jgit.transport
Class BasePackPushConnection

java.lang.Object
  extended by org.eclipse.jgit.transport.BaseConnection
      extended by org.eclipse.jgit.transport.BasePackPushConnection
All Implemented Interfaces:
Connection, PushConnection

public abstract class BasePackPushConnection
extends BaseConnection
implements PushConnection

Push implementation using the native Git pack transfer service.

This is the canonical implementation for transferring objects to the remote repository from the local repository by talking to the 'git-receive-pack' service. Objects are packed on the local side into a pack file and then sent to the remote repository.

This connection requires only a bi-directional pipe or socket, and thus is easily wrapped up into a local process pipe, anonymous TCP socket, or a command executed through an SSH tunnel.

This implementation honors Transport.isPushThin() option.

Concrete implementations should just call init(java.io.InputStream, java.io.OutputStream) and readAdvertisedRefs() methods in constructor or before any use. They should also handle resources releasing in close() method if needed.


Field Summary
protected  Set<ObjectId> additionalHaves
          Extra objects the remote has, but which aren't offered as refs.
static String CAPABILITY_DELETE_REFS
          The server supports deleting refs.
static String CAPABILITY_OFS_DELTA
          The server supports packs with OFS deltas.
static String CAPABILITY_REPORT_STATUS
          The client expects a status report after the server processes the pack.
static String CAPABILITY_SIDE_BAND_64K
          The client supports using the 64K side-band for progress messages.
protected  InputStream in
          Input stream reading from the remote.
protected  Repository local
          The repository this transport fetches into, or pushes out of.
protected  OutputStream out
          Output stream sending to the remote.
protected  boolean outNeedsEnd
          Send PacketLineOut.end() before closing out?
protected  PacketLineIn pckIn
          Packet line decoder around in.
protected  PacketLineOut pckOut
          Packet line encoder around out.
protected  boolean statelessRPC
          True if this is a stateless RPC connection.
protected  TimeoutInputStream timeoutIn
          Low-level input stream, if a timeout was configured.
protected  TimeoutOutputStream timeoutOut
          Low-level output stream, if a timeout was configured.
protected  Transport transport
          A transport connected to uri.
protected  URIish uri
          Remote repository location.
 
Constructor Summary
BasePackPushConnection(PackTransport packTransport)
          Create a new connection to push using the native git transport.
 
Method Summary
 void close()
          Close any resources used by this connection.
protected  void doPush(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates)
          Push one or more objects and update the remote repository.
protected  void endOut()
          Tell the peer we are disconnecting, if it cares to know.
protected  void init(InputStream myIn, OutputStream myOut)
          Configure this connection with the directional pipes.
protected  boolean isCapableOf(String option)
           
protected  TransportException noRepository()
          Create an exception to indicate problems finding a remote repository.
 void push(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates)
          Pushes to the remote repository basing on provided specification.
protected  void readAdvertisedRefs()
          Reads the advertised references through the initialized stream.
protected  boolean wantCapability(StringBuilder b, String option)
           
 
Methods inherited from class org.eclipse.jgit.transport.BaseConnection
available, getMessages, getMessageWriter, getRef, getRefs, getRefsMap, markStartedOperation, setMessageWriter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jgit.transport.Connection
close, getMessages, getRef, getRefs, getRefsMap
 

Field Detail

CAPABILITY_REPORT_STATUS

public static final String CAPABILITY_REPORT_STATUS
The client expects a status report after the server processes the pack.

Since:
2.0
See Also:
Constant Field Values

CAPABILITY_DELETE_REFS

public static final String CAPABILITY_DELETE_REFS
The server supports deleting refs.

Since:
2.0
See Also:
Constant Field Values

CAPABILITY_OFS_DELTA

public static final String CAPABILITY_OFS_DELTA
The server supports packs with OFS deltas.

Since:
2.0
See Also:
Constant Field Values

CAPABILITY_SIDE_BAND_64K

public static final String CAPABILITY_SIDE_BAND_64K
The client supports using the 64K side-band for progress messages.

Since:
2.0
See Also:
Constant Field Values

local

protected final Repository local
The repository this transport fetches into, or pushes out of.


uri

protected final URIish uri
Remote repository location.


transport

protected final Transport transport
A transport connected to uri.


timeoutIn

protected TimeoutInputStream timeoutIn
Low-level input stream, if a timeout was configured.


timeoutOut

protected TimeoutOutputStream timeoutOut
Low-level output stream, if a timeout was configured.


in

protected InputStream in
Input stream reading from the remote.


out

protected OutputStream out
Output stream sending to the remote.


pckIn

protected PacketLineIn pckIn
Packet line decoder around in.


pckOut

protected PacketLineOut pckOut
Packet line encoder around out.


outNeedsEnd

protected boolean outNeedsEnd
Send PacketLineOut.end() before closing out?


statelessRPC

protected boolean statelessRPC
True if this is a stateless RPC connection.


additionalHaves

protected final Set<ObjectId> additionalHaves
Extra objects the remote has, but which aren't offered as refs.

Constructor Detail

BasePackPushConnection

public BasePackPushConnection(PackTransport packTransport)
Create a new connection to push using the native git transport.

Parameters:
packTransport - the transport.
Method Detail

push

public void push(ProgressMonitor monitor,
                 Map<String,RemoteRefUpdate> refUpdates)
          throws TransportException
Description copied from interface: PushConnection
Pushes to the remote repository basing on provided specification. This possibly result in update/creation/deletion of refs on remote repository and sending objects that remote repository need to have a consistent objects graph from new refs.

Only one call per connection is allowed. Subsequent calls will result in TransportException.

Implementation may use local repository to send a minimum set of objects needed by remote repository in efficient way. Transport.isPushThin() should be honored if applicable. refUpdates should be filled with information about status of each update.

Specified by:
push in interface PushConnection
Parameters:
monitor - progress monitor to update the end-user about the amount of work completed, or to indicate cancellation. Implementors should poll the monitor at regular intervals to look for cancellation requests from the user.
refUpdates - map of remote refnames to remote refs update specifications/statuses. Can't be empty. This indicate what refs caller want to update on remote side. Only refs updates with RemoteRefUpdate.Status.NOT_ATTEMPTED should passed. Implementation must ensure that and appropriate status with optional message should be set during call. No refUpdate with RemoteRefUpdate.Status.AWAITING_REPORT or RemoteRefUpdate.Status.NOT_ATTEMPTED can be leaved by implementation after return from this call.
Throws:
TransportException - objects could not be copied due to a network failure, critical protocol error, or error on remote side, or connection was already used for push - new connection must be created. Non-critical errors concerning only isolated refs should be placed in refUpdates.

noRepository

protected TransportException noRepository()
Create an exception to indicate problems finding a remote repository. The caller is expected to throw the returned exception. Subclasses may override this method to provide better diagnostics.

Returns:
a TransportException saying a repository cannot be found and possibly why.

doPush

protected void doPush(ProgressMonitor monitor,
                      Map<String,RemoteRefUpdate> refUpdates)
               throws TransportException
Push one or more objects and update the remote repository.

Parameters:
monitor - progress monitor to receive status updates.
refUpdates - update commands to be applied to the remote repository.
Throws:
TransportException - if any exception occurs.

init

protected final void init(InputStream myIn,
                          OutputStream myOut)
Configure this connection with the directional pipes.

Parameters:
myIn - input stream to receive data from the peer. Caller must ensure the input is buffered, otherwise read performance may suffer.
myOut - output stream to transmit data to the peer. Caller must ensure the output is buffered, otherwise write performance may suffer.

readAdvertisedRefs

protected void readAdvertisedRefs()
                           throws TransportException
Reads the advertised references through the initialized stream.

Subclass implementations may call this method only after setting up the input and output streams with init(InputStream, OutputStream).

If any errors occur, this connection is automatically closed by invoking close() and the exception is wrapped (if necessary) and thrown as a TransportException.

Throws:
TransportException - the reference list could not be scanned.

isCapableOf

protected boolean isCapableOf(String option)

wantCapability

protected boolean wantCapability(StringBuilder b,
                                 String option)

close

public void close()
Description copied from interface: Connection
Close any resources used by this connection.

If the remote repository is contacted by a network socket this method must close that network socket, disconnecting the two peers. If the remote repository is actually local (same system) this method must close any open file handles used to read the "remote" repository.

If additional messages were produced by the remote peer, these should still be retained in the connection instance for Connection.getMessages().

Specified by:
close in interface Connection
Specified by:
close in class BaseConnection

endOut

protected void endOut()
Tell the peer we are disconnecting, if it cares to know.



Copyright © 2012. All Rights Reserved.