Class BasePackPushConnection

All Implemented Interfaces:
AutoCloseable, Connection, PushConnection
Direct Known Subclasses:
InternalPushConnection, TransportGitAnon.TcpPushConnection, TransportGitSsh.SshPushConnection, TransportHttp.SmartHttpPushConnection, TransportLocal.ForkLocalPushConnection

public abstract class BasePackPushConnection extends BasePackConnection 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 BasePackConnection.init(java.io.InputStream, java.io.OutputStream) and BasePackConnection.readAdvertisedRefs() methods in constructor or before any use. They should also handle resources releasing in BasePackConnection.close() method if needed.

  • Field Details

    • 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:
    • CAPABILITY_DELETE_REFS

      public static final String CAPABILITY_DELETE_REFS
      The server supports deleting refs.
      Since:
      2.0
      See Also:
    • CAPABILITY_OFS_DELTA

      public static final String CAPABILITY_OFS_DELTA
      The server supports packs with OFS deltas.
      Since:
      2.0
      See Also:
    • 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:
    • CAPABILITY_PUSH_OPTIONS

      public static final String CAPABILITY_PUSH_OPTIONS
      The server supports the receiving of push options.
      Since:
      4.5
      See Also:
    • thinPack

      private final boolean thinPack
    • atomic

      private final boolean atomic
    • pushOptions

      private List<String> pushOptions
      A list of option strings associated with this push.
    • capableAtomic

      private boolean capableAtomic
    • capableDeleteRefs

      private boolean capableDeleteRefs
    • capableReport

      private boolean capableReport
    • capableSideBand

      private boolean capableSideBand
    • capableOfsDelta

      private boolean capableOfsDelta
    • capablePushOptions

      private boolean capablePushOptions
    • sentCommand

      private boolean sentCommand
    • writePack

      private boolean writePack
    • packTransferTime

      private long packTransferTime
      Time in milliseconds spent transferring the pack data.
  • Constructor Details

    • BasePackPushConnection

      public BasePackPushConnection(PackTransport packTransport)
      Create a new connection to push using the native git transport.
      Parameters:
      packTransport - the transport.
  • Method Details

    • push

      public void push(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates) throws TransportException
      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.
    • push

      public void push(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates, OutputStream outputStream) throws TransportException
      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.
      outputStream - output stream to write sideband messages to
      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.
      Overrides:
      noRepository in class BasePackConnection
      Returns:
      a TransportException saying a repository cannot be found and possibly why.
    • doPush

      protected void doPush(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates, OutputStream outputStream) 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.
      outputStream - output stream to write sideband messages to
      Throws:
      TransportException - if any exception occurs.
      Since:
      3.0
    • writeCommands

      private void writeCommands(Collection<RemoteRefUpdate> refUpdates, ProgressMonitor monitor, OutputStream outputStream) throws IOException
      Throws:
      IOException
    • transmitOptions

      private void transmitOptions() throws IOException
      Throws:
      IOException
    • enableCapabilities

      private String enableCapabilities(ProgressMonitor monitor, OutputStream outputStream)
    • writePack

      private void writePack(Map<String,RemoteRefUpdate> refUpdates, ProgressMonitor monitor) throws IOException
      Throws:
      IOException
    • readStatusReport

      private void readStatusReport(Map<String,RemoteRefUpdate> refUpdates) throws IOException
      Throws:
      IOException
    • readStringLongTimeout

      private String readStringLongTimeout() throws IOException
      Throws:
      IOException
    • getPushOptions

      public List<String> getPushOptions()
      Gets the list of option strings associated with this push.
      Returns:
      pushOptions
      Since:
      4.5