Class WalkFetchConnection
- java.lang.Object
-
- org.eclipse.jgit.transport.BaseConnection
-
- org.eclipse.jgit.transport.BaseFetchConnection
-
- org.eclipse.jgit.transport.WalkFetchConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,Connection
,FetchConnection
class WalkFetchConnection extends BaseFetchConnection
Generic fetch support for dumb transport protocols.Since there are no Git-specific smarts on the remote side of the connection the client side must determine which objects it needs to copy in order to completely fetch the requested refs and their history. The generic walk support in this class parses each individual object (once it has been copied to the local repository) and examines the list of objects that must also be copied to create a complete history. Objects which are already available locally are retained (and not copied), saving bandwidth for incremental fetches. Pack files are copied from the remote repository only as a last resort, as the entire pack must be copied locally in order to access any single object.
This fetch connection does not actually perform the object data transfer. Instead it delegates the transfer to a
WalkRemoteObjectDatabase
, which knows how to read individual files from the remote repository and supply the data as a standard Java InputStream.- See Also:
WalkRemoteObjectDatabase
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
WalkFetchConnection.RemotePack
-
Field Summary
Fields Modifier and Type Field Description private RevFlag
COMPLETE
Objects whose direct dependents we know we have (or will have).private java.util.HashMap<ObjectId,java.util.List<java.lang.Throwable>>
fetchErrors
Errors received while trying to obtain an object.private MutableObjectId
idBuffer
private RevFlag
IN_WORK_QUEUE
Objects that have already enteredworkQueue
.(package private) ObjectInserter
inserter
Inserter to write objects ontolocal
.private int
lastRemoteIdx
Most recently used item inremotes
.(package private) Repository
local
The repository this transport fetches into, or pushes out of.private DateRevQueue
localCommitQueue
Commits already reachable from all local refs.private RevFlag
LOCALLY_SEEN
Commits that have already enteredlocalCommitQueue
.(package private) java.lang.String
lockMessage
private java.util.LinkedList<WalkRemoteObjectDatabase>
noAlternatesYet
Databases we have not yet obtained the alternates from.private java.util.LinkedList<WalkRemoteObjectDatabase>
noPacksYet
Databases we have not yet obtained the list of packs from.(package private) ObjectChecker
objCheck
If not null the validator for received objects.(package private) java.util.List<PackLock>
packLocks
private java.util.Set<java.lang.String>
packsConsidered
Packs whose indexes we have looked at inunfetchedPacks
.private ObjectReader
reader
Inserter to read objects fromlocal
.private java.util.List<WalkRemoteObjectDatabase>
remotes
List of all remote repositories we may need to get objects out of.private RevWalk
revWalk
private TreeWalk
treeWalk
private java.util.LinkedList<WalkFetchConnection.RemotePack>
unfetchedPacks
Packs we have discovered, but have not yet fetched locally.private java.util.LinkedList<ObjectId>
workQueue
Objects we need to copy from the remote repository.
-
Constructor Summary
Constructors Constructor Description WalkFetchConnection(WalkTransport t, WalkRemoteObjectDatabase w)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
alreadyHave(AnyObjectId id)
void
close()
boolean
didFetchTestConnectivity()
Did the lastFetchConnection.fetch(ProgressMonitor, Collection, Set)
validate graph?protected void
doFetch(ProgressMonitor monitor, java.util.Collection<Ref> want, java.util.Set<ObjectId> have)
Implementation ofBaseFetchConnection.fetch(ProgressMonitor, Collection, Set)
without checking for multiple fetch.private boolean
downloadLooseObject(AnyObjectId id, java.lang.String looseName, WalkRemoteObjectDatabase remote)
private void
downloadObject(ProgressMonitor pm, AnyObjectId id)
private boolean
downloadPackedObject(ProgressMonitor monitor, AnyObjectId id)
private java.util.Collection<WalkRemoteObjectDatabase>
expandOneAlternate(AnyObjectId id, ProgressMonitor pm)
java.util.Collection<PackLock>
getPackLocks()
All locks created by the lastFetchConnection.fetch(ProgressMonitor, Collection, Set)
call.private void
markLocalCommitsComplete(int until)
private void
markLocalObjComplete(RevObject obj)
private void
markLocalRefsComplete(java.util.Set<ObjectId> have)
private void
markTreeComplete(RevTree tree)
private void
needs(RevObject obj)
private void
process(ObjectId id)
private void
processBlob(RevObject obj)
private void
processCommit(RevObject obj)
private void
processTag(RevObject obj)
private void
processTree(RevObject obj)
private void
pushLocalCommit(RevCommit p)
private void
queueWants(java.util.Collection<Ref> want)
private void
recordError(AnyObjectId id, java.lang.Throwable what)
void
setPackLockMessage(java.lang.String message)
Set the lock message used when holding a pack out of garbage collection.private java.util.Iterator<ObjectId>
swapFetchQueue()
private void
verifyAndInsertLooseObject(AnyObjectId id, byte[] compressed)
-
Methods inherited from class org.eclipse.jgit.transport.BaseFetchConnection
didFetchIncludeTags, fetch, fetch
-
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
final Repository local
The repository this transport fetches into, or pushes out of.
-
objCheck
final ObjectChecker objCheck
If not null the validator for received objects.
-
remotes
private final java.util.List<WalkRemoteObjectDatabase> remotes
List of all remote repositories we may need to get objects out of.The first repository in the list is the one we were asked to fetch from; the remaining repositories point to the alternate locations we can fetch objects through.
-
lastRemoteIdx
private int lastRemoteIdx
Most recently used item inremotes
.
-
revWalk
private final RevWalk revWalk
-
treeWalk
private final TreeWalk treeWalk
-
COMPLETE
private final RevFlag COMPLETE
Objects whose direct dependents we know we have (or will have).
-
LOCALLY_SEEN
private final RevFlag LOCALLY_SEEN
Commits that have already enteredlocalCommitQueue
.
-
localCommitQueue
private final DateRevQueue localCommitQueue
Commits already reachable from all local refs.
-
workQueue
private java.util.LinkedList<ObjectId> workQueue
Objects we need to copy from the remote repository.
-
noPacksYet
private final java.util.LinkedList<WalkRemoteObjectDatabase> noPacksYet
Databases we have not yet obtained the list of packs from.
-
noAlternatesYet
private final java.util.LinkedList<WalkRemoteObjectDatabase> noAlternatesYet
Databases we have not yet obtained the alternates from.
-
unfetchedPacks
private final java.util.LinkedList<WalkFetchConnection.RemotePack> unfetchedPacks
Packs we have discovered, but have not yet fetched locally.
-
packsConsidered
private final java.util.Set<java.lang.String> packsConsidered
Packs whose indexes we have looked at inunfetchedPacks
.We try to avoid getting duplicate copies of the same pack through multiple alternates by only looking at packs whose names are not yet in this collection.
-
idBuffer
private final MutableObjectId idBuffer
-
fetchErrors
private final java.util.HashMap<ObjectId,java.util.List<java.lang.Throwable>> fetchErrors
Errors received while trying to obtain an object.If the fetch winds up failing because we cannot locate a specific object then we need to report all errors related to that object back to the caller as there may be cascading failures.
-
lockMessage
java.lang.String lockMessage
-
packLocks
final java.util.List<PackLock> packLocks
-
inserter
final ObjectInserter inserter
Inserter to write objects ontolocal
.
-
reader
private final ObjectReader reader
Inserter to read objects fromlocal
.
-
-
Constructor Detail
-
WalkFetchConnection
WalkFetchConnection(WalkTransport t, WalkRemoteObjectDatabase w)
-
-
Method Detail
-
didFetchTestConnectivity
public boolean didFetchTestConnectivity()
Did the lastFetchConnection.fetch(ProgressMonitor, Collection, Set)
validate graph?Some transports walk the object graph on the client side, with the client looking for what objects it is missing and requesting them individually from the remote peer. By virtue of completing the fetch call the client implicitly tested the object connectivity, as every object in the graph was either already local or was requested successfully from the peer. In such transports this method returns true.
Some transports assume the remote peer knows the Git object graph and is able to supply a fully connected graph to the client (although it may only be transferring the parts the client does not yet have). Its faster to assume such remote peers are well behaved and send the correct response to the client. In such transports this method returns false.
- Returns:
- true if the last fetch had to perform a connectivity check on the client side in order to succeed; false if the last fetch assumed the remote peer supplied a complete graph.
-
doFetch
protected void doFetch(ProgressMonitor monitor, java.util.Collection<Ref> want, java.util.Set<ObjectId> have) throws TransportException
Implementation ofBaseFetchConnection.fetch(ProgressMonitor, Collection, Set)
without checking for multiple fetch.- Specified by:
doFetch
in classBaseFetchConnection
- Parameters:
monitor
- as inBaseFetchConnection.fetch(ProgressMonitor, Collection, Set)
want
- as inBaseFetchConnection.fetch(ProgressMonitor, Collection, Set)
have
- as inBaseFetchConnection.fetch(ProgressMonitor, Collection, Set)
- Throws:
TransportException
- as inBaseFetchConnection.fetch(ProgressMonitor, Collection, Set)
, but implementation doesn't have to care about multipleBaseFetchConnection.fetch(ProgressMonitor, Collection, Set)
calls, as it is checked in this class.
-
getPackLocks
public java.util.Collection<PackLock> getPackLocks()
All locks created by the lastFetchConnection.fetch(ProgressMonitor, Collection, Set)
call.- Returns:
- collection (possibly empty) of locks created by the last call to fetch. The caller must release these after refs are updated in order to safely permit garbage collection.
-
setPackLockMessage
public void setPackLockMessage(java.lang.String message)
Set the lock message used when holding a pack out of garbage collection.Callers that set a lock message must ensure they call
FetchConnection.getPackLocks()
afterFetchConnection.fetch(ProgressMonitor, Collection, Set)
, even if an exception was thrown, and release the locks that are held.- Parameters:
message
- message to use when holding a pack in place.
-
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
-
queueWants
private void queueWants(java.util.Collection<Ref> want) throws TransportException
- Throws:
TransportException
-
process
private void process(ObjectId id) throws TransportException
- Throws:
TransportException
-
processBlob
private void processBlob(RevObject obj) throws TransportException
- Throws:
TransportException
-
processTree
private void processTree(RevObject obj) throws TransportException
- Throws:
TransportException
-
processCommit
private void processCommit(RevObject obj) throws TransportException
- Throws:
TransportException
-
processTag
private void processTag(RevObject obj)
-
needs
private void needs(RevObject obj)
-
downloadObject
private void downloadObject(ProgressMonitor pm, AnyObjectId id) throws TransportException
- Throws:
TransportException
-
alreadyHave
private boolean alreadyHave(AnyObjectId id) throws TransportException
- Throws:
TransportException
-
downloadPackedObject
private boolean downloadPackedObject(ProgressMonitor monitor, AnyObjectId id) throws TransportException
- Throws:
TransportException
-
swapFetchQueue
private java.util.Iterator<ObjectId> swapFetchQueue()
-
downloadLooseObject
private boolean downloadLooseObject(AnyObjectId id, java.lang.String looseName, WalkRemoteObjectDatabase remote) throws TransportException
- Throws:
TransportException
-
verifyAndInsertLooseObject
private void verifyAndInsertLooseObject(AnyObjectId id, byte[] compressed) throws java.io.IOException
- Throws:
java.io.IOException
-
expandOneAlternate
private java.util.Collection<WalkRemoteObjectDatabase> expandOneAlternate(AnyObjectId id, ProgressMonitor pm)
-
markLocalRefsComplete
private void markLocalRefsComplete(java.util.Set<ObjectId> have) throws TransportException
- Throws:
TransportException
-
markLocalObjComplete
private void markLocalObjComplete(RevObject obj) throws java.io.IOException
- Throws:
java.io.IOException
-
markLocalCommitsComplete
private void markLocalCommitsComplete(int until) throws TransportException
- Throws:
TransportException
-
pushLocalCommit
private void pushLocalCommit(RevCommit p) throws MissingObjectException, java.io.IOException
- Throws:
MissingObjectException
java.io.IOException
-
markTreeComplete
private void markTreeComplete(RevTree tree) throws java.io.IOException
- Throws:
java.io.IOException
-
recordError
private void recordError(AnyObjectId id, java.lang.Throwable what)
-
-