Class BasePackPushConnection

java.lang.Object
org.eclipse.jgit.transport.BaseConnection
org.eclipse.jgit.transport.BasePackPushConnection
All Implemented Interfaces:
AutoCloseable, 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 BaseConnection.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:
    • CAPABILITY_SYMREF_PREFIX

      protected static final String CAPABILITY_SYMREF_PREFIX
      The capability prefix for a symlink
      See Also:
    • 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 BasePackConnection.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 BasePackConnection.in.
    • pckOut

      protected PacketLineOut pckOut
      Packet line encoder around BasePackConnection.out.
    • outNeedsEnd

      protected boolean outNeedsEnd
      Send PacketLineOut.end() before closing BasePackConnection.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 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
      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.
    • push

      public void push(ProgressMonitor monitor, Map<String,RemoteRefUpdate> refUpdates, OutputStream outputStream) 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.
      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(Throwable cause)
      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.
      Parameters:
      cause - root cause exception
      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
    • getPushOptions

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

      public boolean isUseBitmaps()
      Whether to use bitmaps for push.
      Returns:
      true if push use bitmaps.
      Since:
      6.4
    • 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 boolean 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 BaseConnection.close() and the exception is wrapped (if necessary) and thrown as a TransportException.

      Returns:
      true if the refs were read; false otherwise indicating that lsRefs(java.util.Collection<org.eclipse.jgit.transport.RefSpec>, java.lang.String...) must be called
      Throws:
      TransportException - the reference list could not be scanned.
    • lsRefs

      protected void lsRefs(Collection<RefSpec> refSpecs, String... additionalPatterns) throws TransportException
      Issue a protocol V2 ls-refs command and read its response.
      Parameters:
      refSpecs - to produce ref prefixes from if the server supports git protocol V2
      additionalPatterns - to use for ref prefixes if the server supports git protocol V2
      Throws:
      TransportException - if the command could not be run or its output not be read
    • isCapableOf

      protected boolean isCapableOf(String option)
      Whether this option is supported
      Parameters:
      option - option string
      Returns:
      whether this option is supported
    • wantCapability

      protected boolean wantCapability(StringBuilder b, String option)
      Request capability
      Parameters:
      b - buffer
      option - option we want
      Returns:
      true if the requested option is supported
    • getCapability

      protected String getCapability(String option)
      Return a capability value.
      Parameters:
      option - to get
      Returns:
      the value stored, if any.
    • addUserAgentCapability

      protected void addUserAgentCapability(StringBuilder b)
      Add user agent capability
      Parameters:
      b - a StringBuilder object.
    • getPeerUserAgent

      public String getPeerUserAgent()
      Description copied from class: BaseConnection
      User agent advertised by the remote server. User agent advertised by the remote server.
      Specified by:
      getPeerUserAgent in interface Connection
      Overrides:
      getPeerUserAgent in class BaseConnection
      Returns:
      agent (version of Git) running on the remote server. Null if the server does not advertise this version.
    • 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().

      AutoClosable.close() declares that it throws Exception. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.

      Specified by:
      close in interface AutoCloseable
      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.