Class BasePackConnection

    • Field Detail

      • CAPABILITY_SYMREF_PREFIX

        protected static final java.lang.String CAPABILITY_SYMREF_PREFIX
        See Also:
        Constant Field Values
      • local

        protected final Repository local
        The repository this transport fetches into, or pushes out of.
      • uri

        protected final URIish uri
        Remote repository location.
      • transport

        protected final Transport transport
        A transport connected to uri.
      • timeoutIn

        protected TimeoutInputStream timeoutIn
        Low-level input stream, if a timeout was configured.
      • timeoutOut

        protected TimeoutOutputStream timeoutOut
        Low-level output stream, if a timeout was configured.
      • in

        protected java.io.InputStream in
        Input stream reading from the remote.
      • out

        protected java.io.OutputStream out
        Output stream sending to the remote.
      • statelessRPC

        protected boolean statelessRPC
        True if this is a stateless RPC connection.
      • remoteCapabilities

        private final java.util.Map<java.lang.String,​java.lang.String> remoteCapabilities
        Capability tokens advertised by the remote side.
      • additionalHaves

        protected final java.util.Set<ObjectId> additionalHaves
        Extra objects the remote has, but which aren't offered as refs.
    • Constructor Detail

      • BasePackConnection

        BasePackConnection​(PackTransport packTransport)
    • Method Detail

      • init

        protected final void init​(java.io.InputStream myIn,
                                  java.io.OutputStream myOut)
        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.
      • readLine

        private java.lang.String readLine()
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readAdvertisedRefsImpl

        private boolean readAdvertisedRefsImpl()
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • lsRefs

        protected void lsRefs​(java.util.Collection<RefSpec> refSpecs,
                              java.lang.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 V2
        additionalPatterns - 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​(java.util.Collection<RefSpec> refSpecs,
                                java.lang.String... additionalPatterns)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getRefPrefixes

        private java.util.Collection<java.lang.String> getRefPrefixes​(java.util.Collection<RefSpec> refSpecs,
                                                                      java.lang.String... additionalPatterns)
      • readCapabilitiesV2

        private void readCapabilitiesV2()
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • addCapability

        private void addCapability​(java.lang.String capability)
      • processLineV1

        private void processLineV1​(java.lang.String name,
                                   ObjectId id,
                                   java.util.Map<java.lang.String,​Ref> avail)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • processLineV2

        private void processLineV2​(java.lang.String line,
                                   ObjectId id,
                                   java.lang.String rest,
                                   java.util.Map<java.lang.String,​Ref> avail,
                                   java.util.Map<java.lang.String,​java.lang.String> symRefs)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • updateWithSymRefs

        static void updateWithSymRefs​(java.util.Map<java.lang.String,​Ref> refMap,
                                      java.util.Map<java.lang.String,​java.lang.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 - a non-null, modifiable, Map to update, and the provider of symref targets.
        symRefs - a non-null, modifiable, Map of symrefs.
        Throws:
        java.lang.NullPointerException - if refMap or symRefs is null
      • noRepository

        protected TransportException noRepository​(java.lang.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 - root cause exception
        Returns:
        a TransportException saying a repository cannot be found and possibly why.
      • isCapableOf

        protected boolean isCapableOf​(java.lang.String option)
        Whether this option is supported
        Parameters:
        option - option string
        Returns:
        whether this option is supported
      • wantCapability

        protected boolean wantCapability​(java.lang.StringBuilder b,
                                         java.lang.String option)
        Request capability
        Parameters:
        b - buffer
        option - option we want
        Returns:
        true if the requested option is supported
      • getCapability

        protected java.lang.String getCapability​(java.lang.String option)
        Return a capability value.
        Parameters:
        option - to get
        Returns:
        the value stored, if any.
      • addUserAgentCapability

        protected void addUserAgentCapability​(java.lang.StringBuilder b)
        Add user agent capability
        Parameters:
        b - a StringBuilder object.
      • getPeerUserAgent

        public java.lang.String getPeerUserAgent()
        User agent advertised by the remote server. User agent advertised by the remote server.
        Specified by:
        getPeerUserAgent in interface Connection
        Overrides:
        getPeerUserAgent in class BaseConnection
        Returns:
        agent (version of Git) running on the remote server. Null if the server does not advertise this version.
      • duplicateAdvertisement

        private PackProtocolException duplicateAdvertisement​(java.lang.String name)
      • invalidRefAdvertisementLine

        private PackProtocolException invalidRefAdvertisementLine​(java.lang.String line)
      • 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 throws Exception. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface Connection
        Specified by:
        close in class BaseConnection
      • endOut

        protected void endOut()
        Tell the peer we are disconnecting, if it cares to know.