Class BasePackConnection
- All Implemented Interfaces:
AutoCloseable,Connection
- Direct Known Subclasses:
BasePackFetchConnection,BasePackPushConnection
-
Field Summary
FieldsModifier and TypeFieldDescriptionExtra objects the remote has, but which aren't offered as refs.protected static final Stringprotected InputStreamInput stream reading from the remote.protected final RepositoryThe repository this transport fetches into, or pushes out of.private InterruptTimerTimer to managetimeoutInandtimeoutOut.protected OutputStreamOutput stream sending to the remote.protected booleanSendPacketLineOut.end()before closingout?protected PacketLineInPacket line decoder aroundin.protected PacketLineOutPacket line encoder aroundout.private TransferConfig.ProtocolVersionCapability tokens advertised by the remote side.protected booleanTrue if this is a stateless RPC connection.protected TimeoutInputStreamLow-level input stream, if a timeout was configured.protected TimeoutOutputStreamLow-level output stream, if a timeout was configured.protected final TransportA transport connected touri.protected final URIishRemote repository location. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddCapability(String capability) protected voidAdd user agent capabilityvoidclose()private PackProtocolExceptionduplicateAdvertisement(String name) protected voidendOut()Tell the peer we are disconnecting, if it cares to know.protected StringgetCapability(String option) Return a capability value.User agent advertised by the remote server.(package private) TransferConfig.ProtocolVersionprivate Collection<String>getRefPrefixes(Collection<RefSpec> refSpecs, String... additionalPatterns) protected final voidinit(InputStream myIn, OutputStream myOut) Configure this connection with the directional pipes.private PackProtocolExceptionprotected booleanisCapableOf(String option) Whether this option is supportedprotected voidlsRefs(Collection<RefSpec> refSpecs, String... additionalPatterns) Issue a protocol V2 ls-refs command and read its response.private voidlsRefsImpl(Collection<RefSpec> refSpecs, String... additionalPatterns) protected TransportExceptionnoRepository(Throwable cause) Create an exception to indicate problems finding a remote repository.private voidprivate voidprocessLineV2(String line, ObjectId id, String rest, Map<String, Ref> avail, Map<String, String> symRefs) protected booleanReads the advertised references through the initialized stream.private booleanprivate voidprivate StringreadLine()(package private) voidprivate ObjectId(package private) static voidUpdates the given refMap withSymbolicRefs defined by the given symRefs.protected booleanwantCapability(StringBuilder b, String option) Request capabilityMethods inherited from class org.eclipse.jgit.transport.BaseConnection
available, getMessages, getMessageWriter, getRef, getRefs, getRefsMap, markStartedOperation, setMessageWriter, setPeerUserAgent
-
Field Details
-
CAPABILITY_SYMREF_PREFIX
- See Also:
-
local
The repository this transport fetches into, or pushes out of. -
uri
Remote repository location. -
transport
A transport connected touri. -
timeoutIn
Low-level input stream, if a timeout was configured. -
timeoutOut
Low-level output stream, if a timeout was configured. -
myTimer
Timer to managetimeoutInandtimeoutOut. -
in
Input stream reading from the remote. -
out
Output stream sending to the remote. -
pckIn
Packet line decoder aroundin. -
pckOut
Packet line encoder aroundout. -
outNeedsEnd
protected boolean outNeedsEndSendPacketLineOut.end()before closingout? -
statelessRPC
protected boolean statelessRPCTrue if this is a stateless RPC connection. -
remoteCapabilities
Capability tokens advertised by the remote side. -
additionalHaves
Extra objects the remote has, but which aren't offered as refs. -
protocol
-
-
Constructor Details
-
BasePackConnection
BasePackConnection(PackTransport packTransport)
-
-
Method Details
-
getProtocolVersion
TransferConfig.ProtocolVersion getProtocolVersion() -
setProtocolVersion
-
init
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
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
close()and the exception is wrapped (if necessary) and thrown as aTransportException.- Returns:
trueif the refs were read;falseotherwise indicating thatlsRefs(java.util.Collection<org.eclipse.jgit.transport.RefSpec>, java.lang.String...)must be called- Throws:
TransportException- the reference list could not be scanned.
-
readLine
- Throws:
IOException
-
readAdvertisedRefsImpl
- Throws:
IOException
-
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 V2additionalPatterns- 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
-
lsRefsImpl
private void lsRefsImpl(Collection<RefSpec> refSpecs, String... additionalPatterns) throws IOException - Throws:
IOException
-
getRefPrefixes
private Collection<String> getRefPrefixes(Collection<RefSpec> refSpecs, String... additionalPatterns) -
readCapabilitiesV2
- Throws:
IOException
-
addCapability
-
toId
- Throws:
PackProtocolException
-
processLineV1
- Throws:
IOException
-
processLineV2
private void processLineV2(String line, ObjectId id, String rest, Map<String, Ref> avail, Map<String, throws IOExceptionString> symRefs) - Throws:
IOException
-
updateWithSymRefs
Updates the given refMap withSymbolicRefs defined by the given symRefs.For each entry, symRef, in symRefs, whose value is a key in refMap, adds a new entry to refMap with that same key and value of a new
SymbolicRefwith source=symRef.key and target=refMap.get(symRef.value), then removes that entry from symRefs.If refMap already contains an entry for symRef.key, it is replaced.
For example, given:
refMap.put("refs/heads/main", ref); symRefs.put("HEAD", "refs/heads/main");then:updateWithSymRefs(refMap, symRefs);
has the effect of:refMap.put("HEAD", new SymbolicRef("HEAD", refMap.get(symRefs.remove("HEAD"))))Any entry in symRefs whose value is not a key in refMap is ignored. Any circular symRefs are ignored.
Upon completion, symRefs will contain only any unresolvable entries.
- Parameters:
refMap- a non-null, modifiable, Map to update, and the provider of symref targets.symRefs- a non-null, modifiable, Map of symrefs.- Throws:
NullPointerException- if refMap or symRefs is null
-
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.- Parameters:
cause- root cause exception- Returns:
- a TransportException saying a repository cannot be found and possibly why.
-
isCapableOf
Whether this option is supported- Parameters:
option- option string- Returns:
- whether this option is supported
-
wantCapability
Request capability- Parameters:
b- bufferoption- option we want- Returns:
trueif the requested option is supported
-
getCapability
Return a capability value.- Parameters:
option- to get- Returns:
- the value stored, if any.
-
addUserAgentCapability
Add user agent capability- Parameters:
b- aStringBuilderobject.
-
getPeerUserAgent
User agent advertised by the remote server. User agent advertised by the remote server.- Specified by:
getPeerUserAgentin interfaceConnection- Overrides:
getPeerUserAgentin classBaseConnection- Returns:
- agent (version of Git) running on the remote server. Null if the server does not advertise this version.
-
duplicateAdvertisement
-
invalidRefAdvertisementLine
-
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Specified by:
closein classBaseConnection
-
endOut
protected void endOut()Tell the peer we are disconnecting, if it cares to know.
-