Top Description Fields Constructors Methods
org.eclipse.jgit.transport

pack-priv abstract Class BasePackConnection

extends BaseConnection
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.transport.BasePackFetchConnection, org.eclipse.jgit.transport.BasePackPushConnection
Static Imports
org.eclipse.jgit.transport.GitProtocolConstants.COMMAND_LS_REFS, .GitProtocolConstants.OPTION_AGENT, .GitProtocolConstants.REF_ATTR_PEELED, .GitProtocolConstants.REF_ATTR_SYMREF_TARGET, .GitProtocolConstants.VERSION_1, .GitProtocolConstants.VERSION_2

Base helper class for pack-based operations implementations. Provides partial implementation of pack-protocol - refs advertising and capabilities support, and some other helper methods.
See Also
BasePackFetchConnection, BasePackPushConnection

Field Summary

Modifier and TypeField and Description
protected final Set<ObjectId>
additionalHaves

Extra objects the remote has, but which aren't offered as refs.

protected static final String
CAPABILITY_SYMREF_PREFIX

The capability prefix for a symlink

protected InputStream
in

Input stream reading from the remote.

protected final Repository
local

The repository this transport fetches into, or pushes out of.

private InterruptTimer
protected OutputStream
out

Output stream sending to the remote.

protected boolean
protected PacketLineIn
pckIn

Packet line decoder around BasePackConnection#in.

protected PacketLineOut
pckOut

Packet line encoder around BasePackConnection#out.

private TransferConfig.ProtocolVersion
private final Map<String, String>
remoteCapabilities

Capability tokens advertised by the remote side.

protected boolean
statelessRPC

True if this is a stateless RPC connection.

protected TimeoutInputStream
timeoutIn

Low-level input stream, if a timeout was configured.

protected TimeoutOutputStream
timeoutOut

Low-level output stream, if a timeout was configured.

protected final Transport
transport

A transport connected to BasePackConnection#uri.

protected final URIish
uri

Remote repository location.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
addCapability(String capability)

protected void
addUserAgentCapability(StringBuilder b)

Add user agent capability

public void
close()

Implements abstract org.eclipse.jgit.transport.BaseConnection.close.

Implements org.eclipse.jgit.transport.Connection.close.

Closes this resource, relinquishing any underlying resources.

private PackProtocolException
protected void
endOut()

Tell the peer we are disconnecting, if it cares to know.

protected String

Returns:

the value stored, if any.
getCapability
(String
to get
option
)

Return a capability value.

public String
pack-priv TransferConfig.ProtocolVersion
private Collection<String>
getRefPrefixes(Collection<RefSpec> refSpecs, String... additionalPatterns)

protected final void
init(InputStream
input stream to receive data from the peer. Caller must ensure the input is buffered, otherwise read performance may suffer.
myIn
,
OutputStream
output stream to transmit data to the peer. Caller must ensure the output is buffered, otherwise write performance may suffer.
myOut
)

Configure this connection with the directional pipes.

private PackProtocolException
protected boolean

Returns:

whether this option is supported
isCapableOf
(String
option string
option
)

Whether this option is supported

protected void
lsRefs(Collection<RefSpec>
to produce ref prefixes from if the server supports git protocol V2
refSpecs
,
String...
to use for ref prefixes if the server supports git protocol V2
additionalPatterns
)

Issue a protocol V2 ls-refs command and read its response.

private void
lsRefsImpl(Collection<RefSpec> refSpecs, String... additionalPatterns)

protected TransportException

Returns:

a TransportException saying a repository cannot be found and possibly why.
noRepository
(Throwable
root cause exception
cause
)

Create an exception to indicate problems finding a remote repository.

private void
private void
processLineV2(String line, ObjectId id, String rest, Map<String, Ref> avail, Map<String, String> symRefs)

protected boolean

Returns:

true if the refs were read; false otherwise indicating that lsRefs must be called
readAdvertisedRefs
()

Reads the advertised references through the initialized stream.

private boolean
private void
private String
pack-priv void
private ObjectId
toId(String line, String value)

pack-priv static void
updateWithSymRefs(Map<String, Ref>
a non-null, modifiable, Map to update, and the provider of symref targets.
refMap
,
Map<String, String>
a non-null, modifiable, Map of symrefs.
symRefs
)

Updates the given refMap with SymbolicRefs defined by the given symRefs.

protected boolean

Returns:

true if the requested option is supported
wantCapability
(StringBuilder
buffer
b
,
String
option we want
option
)

Request capability

Inherited from org.eclipse.jgit.transport.BaseConnection:
availablegetMessagesgetMessageWritergetRefgetRefsgetRefsMapmarkStartedOperationsetMessageWritersetPeerUserAgent

Field Detail

additionalHavesback to summary
protected final Set<ObjectId> additionalHaves

Extra objects the remote has, but which aren't offered as refs.

CAPABILITY_SYMREF_PREFIXback to summary
protected static final String CAPABILITY_SYMREF_PREFIX

The capability prefix for a symlink

inback to summary
protected InputStream in

Input stream reading from the remote.

localback to summary
protected final Repository local

The repository this transport fetches into, or pushes out of.

myTimerback to summary
private InterruptTimer myTimer

Timer to manage timeoutIn and BasePackConnection#timeoutOut.

outback to summary
protected OutputStream out

Output stream sending to the remote.

outNeedsEndback to summary
protected boolean outNeedsEnd

Send PacketLineOut#end() before closing BasePackConnection#out?

pckInback to summary
protected PacketLineIn pckIn

Packet line decoder around BasePackConnection#in.

pckOutback to summary
protected PacketLineOut pckOut

Packet line encoder around BasePackConnection#out.

protocolback to summary
private TransferConfig.ProtocolVersion protocol
remoteCapabilitiesback to summary
private final Map<String, String> remoteCapabilities

Capability tokens advertised by the remote side.

statelessRPCback to summary
protected boolean statelessRPC

True if this is a stateless RPC connection.

timeoutInback to summary
protected TimeoutInputStream timeoutIn

Low-level input stream, if a timeout was configured.

timeoutOutback to summary
protected TimeoutOutputStream timeoutOut

Low-level output stream, if a timeout was configured.

transportback to summary
protected final Transport transport

A transport connected to BasePackConnection#uri.

uriback to summary
protected final URIish uri

Remote repository location.

Constructor Detail

BasePackConnectionback to summary
pack-priv BasePackConnection(PackTransport packTransport)

Method Detail

addCapabilityback to summary
private void addCapability(String capability)
addUserAgentCapabilityback to summary
protected void addUserAgentCapability(StringBuilder b)

Add user agent capability

Parameters
b:StringBuilder

a java.lang.StringBuilder object.

closeback to summary
public void close()

Implements abstract org.eclipse.jgit.transport.BaseConnection.close.

Implements org.eclipse.jgit.transport.Connection.close.

Doc from org.eclipse.jgit.transport.Connection.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

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 getMessages().

AutoClosable.close() declares that it throws Exception. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.

Annotations
@Override
duplicateAdvertisementback to summary
private PackProtocolException duplicateAdvertisement(String name)
endOutback to summary
protected void endOut()

Tell the peer we are disconnecting, if it cares to know.

getCapabilityback to summary
protected String getCapability(String option)

Return a capability value.

Parameters
option:String

to get

Returns:String

the value stored, if any.

getPeerUserAgentback to summary
public String getPeerUserAgent()

Overrides org.eclipse.jgit.transport.BaseConnection.getPeerUserAgent.

Implements org.eclipse.jgit.transport.Connection.getPeerUserAgent.

Doc from org.eclipse.jgit.transport.BaseConnection.getPeerUserAgent.

User agent advertised by the remote server. User agent advertised by the remote server.

Returns:String

Doc from org.eclipse.jgit.transport.Connection.getPeerUserAgent.

agent (version of Git) running on the remote server. Null if the server does not advertise this version.

Annotations
@Override
getProtocolVersionback to summary
pack-priv TransferConfig.ProtocolVersion getProtocolVersion()
getRefPrefixesback to summary
private Collection<String> getRefPrefixes(Collection<RefSpec> refSpecs, String... additionalPatterns)
initback to summary
protected final void init(InputStream myIn, OutputStream myOut)

Configure this connection with the directional pipes.

Parameters
myIn:InputStream

input stream to receive data from the peer. Caller must ensure the input is buffered, otherwise read performance may suffer.

myOut:OutputStream

output stream to transmit data to the peer. Caller must ensure the output is buffered, otherwise write performance may suffer.

invalidRefAdvertisementLineback to summary
private PackProtocolException invalidRefAdvertisementLine(String line)
isCapableOfback to summary
protected boolean isCapableOf(String option)

Whether this option is supported

Parameters
option:String

option string

Returns:boolean

whether this option is supported

lsRefsback to summary
protected void lsRefs(Collection<RefSpec> refSpecs, String... additionalPatterns) throws TransportException

Issue a protocol V2 ls-refs command and read its response.

Parameters
refSpecs:Collection<RefSpec>

to produce ref prefixes from if the server supports git protocol V2

additionalPatterns:String[]

to use for ref prefixes if the server supports git protocol V2

Exceptions
TransportException:
if the command could not be run or its output not be read
lsRefsImplback to summary
private void lsRefsImpl(Collection<RefSpec> refSpecs, String... additionalPatterns) throws IOException
noRepositoryback to summary
protected TransportException noRepository(Throwable cause)

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:Throwable

root cause exception

Returns:TransportException

a TransportException saying a repository cannot be found and possibly why.

processLineV1back to summary
private void processLineV1(String name, ObjectId id, Map<String, Ref> avail) throws IOException
processLineV2back to summary
private void processLineV2(String line, ObjectId id, String rest, Map<String, Ref> avail, Map<String, String> symRefs) throws IOException
readAdvertisedRefsback to summary
protected boolean readAdvertisedRefs() throws TransportException

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 a org.eclipse.jgit.errors.TransportException.

Returns:boolean

true if the refs were read; false otherwise indicating that lsRefs must be called

Exceptions
TransportException:
the reference list could not be scanned.
readAdvertisedRefsImplback to summary
private boolean readAdvertisedRefsImpl() throws IOException
readCapabilitiesV2back to summary
private void readCapabilitiesV2() throws IOException
readLineback to summary
private String readLine() throws IOException
setProtocolVersionback to summary
pack-priv void setProtocolVersion(TransferConfig.ProtocolVersion protocol)
toIdback to summary
private ObjectId toId(String line, String value) throws PackProtocolException
updateWithSymRefsback to summary
pack-priv static void updateWithSymRefs(Map<String, Ref> refMap, Map<String, String> symRefs)

Updates the given refMap with SymbolicRefs 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 SymbolicRef with 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:Map<String, Ref>

a non-null, modifiable, Map to update, and the provider of symref targets.

symRefs:Map<String, String>

a non-null, modifiable, Map of symrefs.

Exceptions
NullPointerException:
if refMap or symRefs is null
wantCapabilityback to summary
protected boolean wantCapability(StringBuilder b, String option)

Request capability

Parameters
b:StringBuilder

buffer

option:String

option we want

Returns:boolean

true if the requested option is supported