Class BasePackPushConnection
- java.lang.Object
-
- org.eclipse.jgit.transport.BaseConnection
-
- org.eclipse.jgit.transport.BasePackConnection
-
- org.eclipse.jgit.transport.BasePackPushConnection
-
- All Implemented Interfaces:
java.lang.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)
andBasePackConnection.readAdvertisedRefs()
methods in constructor or before any use. They should also handle resources releasing inBasePackConnection.close()
method if needed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BasePackPushConnection.CheckingSideBandOutputStream
-
Field Summary
Fields Modifier and Type Field Description private boolean
atomic
static java.lang.String
CAPABILITY_DELETE_REFS
The server supports deleting refs.static java.lang.String
CAPABILITY_OFS_DELTA
The server supports packs with OFS deltas.static java.lang.String
CAPABILITY_PUSH_OPTIONS
The server supports the receiving of push options.static java.lang.String
CAPABILITY_REPORT_STATUS
The client expects a status report after the server processes the pack.static java.lang.String
CAPABILITY_SIDE_BAND_64K
The client supports using the 64K side-band for progress messages.private boolean
capableAtomic
private boolean
capableDeleteRefs
private boolean
capableOfsDelta
private boolean
capablePushOptions
private boolean
capableReport
private boolean
capableSideBand
private long
packTransferTime
Time in milliseconds spent transferring the pack data.private java.util.List<java.lang.String>
pushOptions
A list of option strings associated with this push.private boolean
sentCommand
private boolean
thinPack
private boolean
writePack
-
Fields inherited from class org.eclipse.jgit.transport.BasePackConnection
additionalHaves, CAPABILITY_SYMREF_PREFIX, in, local, out, outNeedsEnd, pckIn, pckOut, statelessRPC, timeoutIn, timeoutOut, transport, uri
-
-
Constructor Summary
Constructors Constructor Description BasePackPushConnection(PackTransport packTransport)
Create a new connection to push using the native git transport.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doPush(ProgressMonitor monitor, java.util.Map<java.lang.String,RemoteRefUpdate> refUpdates, java.io.OutputStream outputStream)
Push one or more objects and update the remote repository.private java.lang.String
enableCapabilities(ProgressMonitor monitor, java.io.OutputStream outputStream)
java.util.List<java.lang.String>
getPushOptions()
Gets the list of option strings associated with this push.protected TransportException
noRepository()
Create an exception to indicate problems finding a remote repository.void
push(ProgressMonitor monitor, java.util.Map<java.lang.String,RemoteRefUpdate> refUpdates)
Pushes to the remote repository basing on provided specification.void
push(ProgressMonitor monitor, java.util.Map<java.lang.String,RemoteRefUpdate> refUpdates, java.io.OutputStream outputStream)
Pushes to the remote repository basing on provided specification.private void
readStatusReport(java.util.Map<java.lang.String,RemoteRefUpdate> refUpdates)
private java.lang.String
readStringLongTimeout()
private void
transmitOptions()
private void
writeCommands(java.util.Collection<RemoteRefUpdate> refUpdates, ProgressMonitor monitor, java.io.OutputStream outputStream)
private void
writePack(java.util.Map<java.lang.String,RemoteRefUpdate> refUpdates, ProgressMonitor monitor)
-
Methods inherited from class org.eclipse.jgit.transport.BasePackConnection
addUserAgentCapability, close, endOut, extractSymRefsFromCapabilities, getPeerUserAgent, init, isCapableOf, readAdvertisedRefs, updateWithSymRefs, wantCapability
-
Methods inherited from class org.eclipse.jgit.transport.BaseConnection
available, getMessages, getMessageWriter, getRef, getRefs, getRefsMap, markStartedOperation, setMessageWriter, setPeerUserAgent
-
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, getPeerUserAgent, getRef, getRefs, getRefsMap
-
-
-
-
Field Detail
-
CAPABILITY_REPORT_STATUS
public static final java.lang.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 java.lang.String CAPABILITY_DELETE_REFS
The server supports deleting refs.- Since:
- 2.0
- See Also:
- Constant Field Values
-
CAPABILITY_OFS_DELTA
public static final java.lang.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 java.lang.String CAPABILITY_SIDE_BAND_64K
The client supports using the 64K side-band for progress messages.- Since:
- 2.0
- See Also:
- Constant Field Values
-
CAPABILITY_PUSH_OPTIONS
public static final java.lang.String CAPABILITY_PUSH_OPTIONS
The server supports the receiving of push options.- Since:
- 4.5
- See Also:
- Constant Field Values
-
thinPack
private final boolean thinPack
-
atomic
private final boolean atomic
-
pushOptions
private java.util.List<java.lang.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 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, java.util.Map<java.lang.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 interfacePushConnection
- 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 withRemoteRefUpdate.Status.NOT_ATTEMPTED
should passed. Implementation must ensure that and appropriate status with optional message should be set during call. No refUpdate withRemoteRefUpdate.Status.AWAITING_REPORT
orRemoteRefUpdate.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, java.util.Map<java.lang.String,RemoteRefUpdate> refUpdates, java.io.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 interfacePushConnection
- 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 withRemoteRefUpdate.Status.NOT_ATTEMPTED
should passed. Implementation must ensure that and appropriate status with optional message should be set during call. No refUpdate withRemoteRefUpdate.Status.AWAITING_REPORT
orRemoteRefUpdate.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 classBasePackConnection
- Returns:
- a TransportException saying a repository cannot be found and possibly why.
-
doPush
protected void doPush(ProgressMonitor monitor, java.util.Map<java.lang.String,RemoteRefUpdate> refUpdates, java.io.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(java.util.Collection<RemoteRefUpdate> refUpdates, ProgressMonitor monitor, java.io.OutputStream outputStream) throws java.io.IOException
- Throws:
java.io.IOException
-
transmitOptions
private void transmitOptions() throws java.io.IOException
- Throws:
java.io.IOException
-
enableCapabilities
private java.lang.String enableCapabilities(ProgressMonitor monitor, java.io.OutputStream outputStream)
-
writePack
private void writePack(java.util.Map<java.lang.String,RemoteRefUpdate> refUpdates, ProgressMonitor monitor) throws java.io.IOException
- Throws:
java.io.IOException
-
readStatusReport
private void readStatusReport(java.util.Map<java.lang.String,RemoteRefUpdate> refUpdates) throws java.io.IOException
- Throws:
java.io.IOException
-
readStringLongTimeout
private java.lang.String readStringLongTimeout() throws java.io.IOException
- Throws:
java.io.IOException
-
getPushOptions
public java.util.List<java.lang.String> getPushOptions()
Gets the list of option strings associated with this push.- Returns:
- pushOptions
- Since:
- 4.5
-
-