Class BasePackPushConnection
- All Implemented Interfaces:
AutoCloseable
,Connection
,PushConnection
- Direct Known Subclasses:
InternalPushConnection
,TransportGitAnon.TcpPushConnection
,TransportGitSsh.SshPushConnection
,TransportHttp.SmartHttpPushConnection
,TransportLocal.ForkLocalPushConnection
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
static final String
The server supports deleting refs.static final String
The server supports packs with OFS deltas.static final String
The server supports the receiving of push options.static final String
The client expects a status report after the server processes the pack.static final String
The client supports using the 64K side-band for progress messages.private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private long
Time in milliseconds spent transferring the pack data.A list of option strings associated with this push.private boolean
private final boolean
private boolean
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
ConstructorsConstructorDescriptionBasePackPushConnection
(PackTransport packTransport) Create a new connection to push using the native git transport. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doPush
(ProgressMonitor monitor, Map<String, RemoteRefUpdate> refUpdates, OutputStream outputStream) Push one or more objects and update the remote repository.private String
enableCapabilities
(ProgressMonitor monitor, OutputStream outputStream) Gets the list of option strings associated with this push.protected TransportException
noRepository
(Throwable cause) 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.void
push
(ProgressMonitor monitor, Map<String, RemoteRefUpdate> refUpdates, OutputStream outputStream) Pushes to the remote repository basing on provided specification.private void
readStatusReport
(Map<String, RemoteRefUpdate> refUpdates) private String
private void
private void
writeCommands
(Collection<RemoteRefUpdate> refUpdates, ProgressMonitor monitor, OutputStream outputStream) private void
writePack
(Map<String, RemoteRefUpdate> refUpdates, ProgressMonitor monitor) Methods inherited from class org.eclipse.jgit.transport.BasePackConnection
addUserAgentCapability, close, endOut, getCapability, getPeerUserAgent, getProtocolVersion, init, isCapableOf, lsRefs, readAdvertisedRefs, setProtocolVersion, 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 Details
-
CAPABILITY_REPORT_STATUS
The client expects a status report after the server processes the pack.- Since:
- 2.0
- See Also:
-
CAPABILITY_DELETE_REFS
The server supports deleting refs.- Since:
- 2.0
- See Also:
-
CAPABILITY_OFS_DELTA
The server supports packs with OFS deltas.- Since:
- 2.0
- See Also:
-
CAPABILITY_SIDE_BAND_64K
The client supports using the 64K side-band for progress messages.- Since:
- 2.0
- See Also:
-
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
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 packTransferTimeTime in milliseconds spent transferring the pack data.
-
-
Constructor Details
-
BasePackPushConnection
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 TransportExceptionPushes 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, Map<String, RemoteRefUpdate> refUpdates, OutputStream outputStream) throws TransportExceptionPushes 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
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
- 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 TransportExceptionPush 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
- Throws:
IOException
-
enableCapabilities
-
writePack
private void writePack(Map<String, RemoteRefUpdate> refUpdates, ProgressMonitor monitor) throws IOException- Throws:
IOException
-
readStatusReport
- Throws:
IOException
-
readStringLongTimeout
- Throws:
IOException
-
getPushOptions
Gets the list of option strings associated with this push.- Returns:
- pushOptions
- Since:
- 4.5
-