Class WalkPushConnection
- java.lang.Object
-
- org.eclipse.jgit.transport.BaseConnection
-
- org.eclipse.jgit.transport.WalkPushConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,Connection
,PushConnection
class WalkPushConnection extends BaseConnection implements PushConnection
Generic push support for dumb transport protocols.Since there are no Git-specific smarts on the remote side of the connection the client side must handle everything on its own. The generic push support requires being able to delete, create and overwrite files on the remote side, as well as create any missing directories (if necessary). Typically this can be handled through an FTP style protocol.
Objects not on the remote side are uploaded as pack files, using one pack file per invocation. This simplifies the implementation as only two data files need to be written to the remote repository.
Push support supplied by this class is not multiuser safe. Concurrent pushes to the same repository may yield an inconsistent reference database which may confuse fetch clients.
A single push is concurrently safe with multiple fetch requests, due to the careful order of operations used to update the repository. Clients fetching may receive transient failures due to short reads on certain files if the protocol does not support atomic file replacement.
- See Also:
WalkRemoteObjectDatabase
-
-
Field Summary
Fields Modifier and Type Field Description (package private) WalkRemoteObjectDatabase
dest
Database connection to the remote repository.private Repository
local
The repository this transport pushes out of.private java.util.Map<java.lang.String,Ref>
newRefs
Complete listing of refs the remote will have after our push.private java.util.Collection<RemoteRefUpdate>
packedRefUpdates
Updates which require altering the packed-refs file to complete.private java.util.LinkedHashMap<java.lang.String,java.lang.String>
packNames
Packs already known to reside in the remote repository.private Transport
transport
The configured transport we were constructed by.private URIish
uri
Location of the remote repository we are writing to.
-
Constructor Summary
Constructors Constructor Description WalkPushConnection(WalkTransport walkTransport, WalkRemoteObjectDatabase w)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
private void
createNewRepository(java.util.List<RemoteRefUpdate> updates)
private void
deleteCommand(RemoteRefUpdate u)
private boolean
isNewRepository()
private static java.lang.String
pickHEAD(java.util.List<RemoteRefUpdate> updates)
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 out)
Pushes to the remote repository basing on provided specification.private void
safeDelete(java.lang.String path)
private void
sendpack(java.util.List<RemoteRefUpdate> updates, ProgressMonitor monitor)
private void
updateCommand(RemoteRefUpdate u)
-
Methods inherited from class org.eclipse.jgit.transport.BaseConnection
available, getMessages, getMessageWriter, getPeerUserAgent, 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
getMessages, getPeerUserAgent, getRef, getRefs, getRefsMap
-
-
-
-
Field Detail
-
local
private final Repository local
The repository this transport pushes out of.
-
uri
private final URIish uri
Location of the remote repository we are writing to.
-
dest
final WalkRemoteObjectDatabase dest
Database connection to the remote repository.
-
transport
private final Transport transport
The configured transport we were constructed by.
-
packNames
private java.util.LinkedHashMap<java.lang.String,java.lang.String> packNames
Packs already known to reside in the remote repository.This is a LinkedHashMap to maintain the original order.
-
newRefs
private java.util.Map<java.lang.String,Ref> newRefs
Complete listing of refs the remote will have after our push.
-
packedRefUpdates
private java.util.Collection<RemoteRefUpdate> packedRefUpdates
Updates which require altering the packed-refs file to complete.If this collection is non-empty then any refs listed in
newRefs
with a storage class ofRef.Storage.PACKED
will be written.
-
-
Constructor Detail
-
WalkPushConnection
WalkPushConnection(WalkTransport walkTransport, WalkRemoteObjectDatabase w)
-
-
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 out) 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.out
- 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.
-
close
public void close()
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 throwsException
. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceConnection
- Specified by:
close
in classBaseConnection
-
sendpack
private void sendpack(java.util.List<RemoteRefUpdate> updates, ProgressMonitor monitor) throws TransportException
- Throws:
TransportException
-
safeDelete
private void safeDelete(java.lang.String path)
-
deleteCommand
private void deleteCommand(RemoteRefUpdate u)
-
updateCommand
private void updateCommand(RemoteRefUpdate u)
-
isNewRepository
private boolean isNewRepository()
-
createNewRepository
private void createNewRepository(java.util.List<RemoteRefUpdate> updates) throws TransportException
- Throws:
TransportException
-
pickHEAD
private static java.lang.String pickHEAD(java.util.List<RemoteRefUpdate> updates)
-
-