Class TransportLocal

  • All Implemented Interfaces:
    java.lang.AutoCloseable, PackTransport

    class TransportLocal
    extends Transport
    implements PackTransport
    Transport to access a local directory as though it were a remote peer.

    This transport is suitable for use on the local system, where the caller has direct read or write access to the "remote" repository.

    By default this transport works by spawning a helper thread within the same JVM, and processes the data transfer using a shared memory buffer between the calling thread and the helper thread. This is a pure-Java implementation which does not require forking an external process.

    However, during openFetch(), if the Transport has configured Transport.getOptionUploadPack() to be anything other than "git-upload-pack" or "git upload-pack", this implementation will fork and execute the external process, using an operating system pipe to transfer data.

    Similarly, during openPush(), if the Transport has configured Transport.getOptionReceivePack() to be anything other than "git-receive-pack" or "git receive-pack", this implementation will fork and execute the external process, using an operating system pipe to transfer data.

    • Field Detail

      • remoteGitDir

        private final java.io.File remoteGitDir
    • Constructor Detail

      • TransportLocal

        TransportLocal​(Repository local,
                       URIish uri,
                       java.io.File gitDir)
      • TransportLocal

        TransportLocal​(URIish uri,
                       java.io.File gitDir)
    • Method Detail

      • openFetch

        public FetchConnection openFetch()
                                  throws TransportException
        Begins a new connection for fetching from the remote repository.

        If the transport has no local repository, the fetch connection can only be used for reading remote refs.

        Specified by:
        openFetch in class Transport
        Returns:
        a fresh connection to fetch from the remote repository.
        Throws:
        TransportException - the remote connection could not be established.
      • close

        public void close()

        Close any resources used by this transport.

        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.

        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 class Transport
      • spawn

        protected java.lang.Process spawn​(java.lang.String cmd)
                                   throws TransportException
        Spawn process
        Parameters:
        cmd - command
        Returns:
        a Process object.
        Throws:
        TransportException - if any.