Class BaseConnection

    • Constructor Detail

      • BaseConnection

        public BaseConnection()
    • Method Detail

      • getRefsMap

        public Map<String,​Ref> getRefsMap()
        Get the complete map of refs advertised as available for fetching or pushing.
        Specified by:
        getRefsMap in interface Connection
        Returns:
        available/advertised refs: map of refname to ref. Never null. Not modifiable. The collection can be empty if the remote side has no refs (it is an empty/newly created repository).
      • getRefs

        public final Collection<Ref> getRefs()
        Get the complete list of refs advertised as available for fetching or pushing.

        The returned refs may appear in any order. If the caller needs these to be sorted, they should be copied into a new array or List and then sorted by the caller as necessary.

        Specified by:
        getRefs in interface Connection
        Returns:
        available/advertised refs. Never null. Not modifiable. The collection can be empty if the remote side has no refs (it is an empty/newly created repository).
      • getRef

        public final Ref getRef​(String name)
        Get a single advertised ref by name.

        The name supplied should be valid ref name. To get a peeled value for a ref (aka refs/tags/v1.0^{}) use the base name (without the ^{} suffix) and look at the peeled object id.

        Specified by:
        getRef in interface Connection
        Parameters:
        name - name of the ref to obtain.
        Returns:
        the requested ref; null if the remote did not advertise this ref.
      • getMessages

        public String getMessages()
        Get the additional messages, if any, returned by the remote process.

        These messages are most likely informational or error messages, sent by the remote peer, to help the end-user correct any problems that may have prevented the operation from completing successfully. Application UIs should try to show these in an appropriate context.

        The message buffer is available after Connection.close() has been called. Prior to closing the connection, the message buffer may be empty.

        Specified by:
        getMessages in interface Connection
        Returns:
        the messages returned by the remote, most likely terminated by a newline (LF) character. The empty string is returned if the remote produced no additional messages.
      • getPeerUserAgent

        public String getPeerUserAgent()
        User agent advertised by the remote server. User agent advertised by the remote server.
        Specified by:
        getPeerUserAgent in interface Connection
        Returns:
        agent (version of Git) running on the remote server. Null if the server does not advertise this version.
        Since:
        4.0
      • setPeerUserAgent

        protected void setPeerUserAgent​(String agent)
        Remember the remote peer's agent.
        Parameters:
        agent - remote peer agent string.
        Since:
        4.0
      • close

        public abstract 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 AutoCloseable
        Specified by:
        close in interface Connection
      • available

        protected void available​(Map<String,​Ref> all)
        Denote the list of refs available on the remote repository.

        Implementors should invoke this method once they have obtained the refs that are available from the remote repository.

        Parameters:
        all - the complete list of refs the remote has to offer. This map will be wrapped in an unmodifiable way to protect it, but it does not get copied.
      • markStartedOperation

        protected void markStartedOperation()
                                     throws TransportException
        Helper method for ensuring one-operation per connection. Check whether operation was already marked as started, and mark it as started.
        Throws:
        TransportException - if operation was already marked as started.
      • getMessageWriter

        protected Writer getMessageWriter()
        Get the writer that buffers messages from the remote side.
        Returns:
        writer to store messages from the remote.
      • setMessageWriter

        protected void setMessageWriter​(Writer writer)
        Set the writer that buffers messages from the remote side.
        Parameters:
        writer - the writer that messages will be delivered to. The writer's toString() method should be overridden to return the complete contents.