Class WalkRemoteObjectDatabase

  • Direct Known Subclasses:
    TransportAmazonS3.DatabaseS3, TransportHttp.HttpObjectDB, TransportSftp.SftpObjectDB

    abstract class WalkRemoteObjectDatabase
    extends java.lang.Object
    Transfers object data through a dumb transport.

    Implementations are responsible for resolving path names relative to the objects/ subdirectory of a single remote Git repository or naked object database and make the content available as a Java input stream for reading during fetch. The actual object traversal logic to determine the names of files to retrieve is handled through the generic, protocol independent WalkFetchConnection.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.lang.String INFO_PACKS  
      (package private) static java.lang.String INFO_REFS  
      (package private) static java.lang.String ROOT_DIR  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) abstract void close()
      Close any resources used by this connection.
      (package private) void deleteFile​(java.lang.String path)
      Delete a file from the object database.
      (package private) void deleteRef​(java.lang.String name)
      Delete a loose ref from the remote repository.
      (package private) void deleteRefLog​(java.lang.String name)
      Delete a reflog from the remote repository.
      (package private) abstract java.util.Collection<WalkRemoteObjectDatabase> getAlternates()
      Obtain alternate connections to alternate object databases (if any).
      (package private) abstract java.util.Collection<java.lang.String> getPackNames()
      Obtain the list of available packs (if any).
      (package private) abstract URIish getURI()  
      (package private) abstract WalkRemoteObjectDatabase.FileStream open​(java.lang.String path)
      Open a single file for reading.
      (package private) abstract WalkRemoteObjectDatabase openAlternate​(java.lang.String location)
      Create a new connection for a discovered alternate object database
      (package private) java.io.BufferedReader openReader​(java.lang.String path)
      Open a buffered reader around a file.
      (package private) java.util.Collection<WalkRemoteObjectDatabase> readAlternates​(java.lang.String listPath)
      Read a standard Git alternates file to discover other object databases.
      protected void readPackedRefs​(java.util.Map<java.lang.String,​Ref> avail)
      Read a standard Git packed-refs file to discover known references.
      private void readPackedRefsImpl​(java.util.Map<java.lang.String,​Ref> avail, java.io.BufferedReader br)  
      (package private) void writeFile​(java.lang.String path, byte[] data)
      Atomically write a remote file.
      (package private) java.io.OutputStream writeFile​(java.lang.String path, ProgressMonitor monitor, java.lang.String monitorTask)
      Open a remote file for writing.
      (package private) void writeInfoPacks​(java.util.Collection<java.lang.String> packNames)
      Rebuild the INFO_PACKS for dumb transport clients.
      (package private) void writeRef​(java.lang.String name, ObjectId value)
      Overwrite (or create) a loose ref in the remote repository.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WalkRemoteObjectDatabase

        WalkRemoteObjectDatabase()
    • Method Detail

      • getURI

        abstract URIish getURI()
      • getPackNames

        abstract java.util.Collection<java.lang.String> getPackNames()
                                                              throws java.io.IOException
        Obtain the list of available packs (if any).

        Pack names should be the file name in the packs directory, that is pack-035760ab452d6eebd123add421f253ce7682355a.pack. Index names should not be included in the returned collection.

        Returns:
        list of pack names; null or empty list if none are available.
        Throws:
        java.io.IOException - The connection is unable to read the remote repository's list of available pack files.
      • getAlternates

        abstract java.util.Collection<WalkRemoteObjectDatabase> getAlternates()
                                                                       throws java.io.IOException
        Obtain alternate connections to alternate object databases (if any).

        Alternates are typically read from the file Constants.INFO_ALTERNATES or Constants.INFO_HTTP_ALTERNATES. The content of each line must be resolved by the implementation and a new database reference should be returned to represent the additional location.

        Alternates may reuse the same network connection handle, however the fetch connection will close() each created alternate.

        Returns:
        list of additional object databases the caller could fetch from; null or empty list if none are configured.
        Throws:
        java.io.IOException - The connection is unable to read the remote repository's list of configured alternates.
      • open

        abstract WalkRemoteObjectDatabase.FileStream open​(java.lang.String path)
                                                   throws java.io.FileNotFoundException,
                                                          java.io.IOException
        Open a single file for reading.

        Implementors should make every attempt possible to ensure FileNotFoundException is used when the remote object does not exist. However when fetching over HTTP some misconfigured servers may generate a 200 OK status message (rather than a 404 Not Found) with an HTML formatted message explaining the requested resource does not exist. Callers such as WalkFetchConnection are prepared to handle this by validating the content received, and assuming content that fails to match its hash is an incorrectly phrased FileNotFoundException.

        This method is recommended for already compressed files like loose objects and pack files. For text files, see openReader(String).

        Parameters:
        path - location of the file to read, relative to this objects directory (e.g. cb/95df6ab7ae9e57571511ef451cf33767c26dd2 or pack/pack-035760ab452d6eebd123add421f253ce7682355a.pack).
        Returns:
        a stream to read from the file. Never null.
        Throws:
        java.io.FileNotFoundException - the requested file does not exist at the given location.
        java.io.IOException - The connection is unable to read the remote's file, and the failure occurred prior to being able to determine if the file exists, or after it was determined to exist but before the stream could be created.
      • openAlternate

        abstract WalkRemoteObjectDatabase openAlternate​(java.lang.String location)
                                                 throws java.io.IOException
        Create a new connection for a discovered alternate object database

        This method is typically called by readAlternates(String) when subclasses us the generic alternate parsing logic for their implementation of getAlternates().

        Parameters:
        location - the location of the new alternate, relative to the current object database.
        Returns:
        a new database connection that can read from the specified alternate.
        Throws:
        java.io.IOException - The database connection cannot be established with the alternate, such as if the alternate location does not actually exist and the connection's constructor attempts to verify that.
      • close

        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.

      • deleteFile

        void deleteFile​(java.lang.String path)
                 throws java.io.IOException
        Delete a file from the object database.

        Path may start with ../ to request deletion of a file that resides in the repository itself.

        When possible empty directories must be removed, up to but not including the current object database directory itself.

        This method does not support deletion of directories.

        Parameters:
        path - name of the item to be removed, relative to the current object database.
        Throws:
        java.io.IOException - deletion is not supported, or deletion failed.
      • writeFile

        java.io.OutputStream writeFile​(java.lang.String path,
                                       ProgressMonitor monitor,
                                       java.lang.String monitorTask)
                                throws java.io.IOException
        Open a remote file for writing.

        Path may start with ../ to request writing of a file that resides in the repository itself.

        The requested path may or may not exist. If the path already exists as a file the file should be truncated and completely replaced.

        This method creates any missing parent directories, if necessary.

        Parameters:
        path - name of the file to write, relative to the current object database.
        monitor - (optional) progress monitor to post write completion to during the stream's close method.
        monitorTask - (optional) task name to display during the close method.
        Returns:
        stream to write into this file. Caller must close the stream to complete the write request. The stream is not buffered and each write may cause a network request/response so callers should buffer to smooth out small writes.
        Throws:
        java.io.IOException - writing is not supported, or attempting to write the file failed, possibly due to permissions or remote disk full, etc.
      • writeFile

        void writeFile​(java.lang.String path,
                       byte[] data)
                throws java.io.IOException
        Atomically write a remote file.

        This method attempts to perform as atomic of an update as it can, reducing (or eliminating) the time that clients might be able to see partial file content. This method is not suitable for very large transfers as the complete content must be passed as an argument.

        Path may start with ../ to request writing of a file that resides in the repository itself.

        The requested path may or may not exist. If the path already exists as a file the file should be truncated and completely replaced.

        This method creates any missing parent directories, if necessary.

        Parameters:
        path - name of the file to write, relative to the current object database.
        data - complete new content of the file.
        Throws:
        java.io.IOException - writing is not supported, or attempting to write the file failed, possibly due to permissions or remote disk full, etc.
      • deleteRef

        void deleteRef​(java.lang.String name)
                throws java.io.IOException
        Delete a loose ref from the remote repository.
        Parameters:
        name - name of the ref within the ref space, for example refs/heads/pu.
        Throws:
        java.io.IOException - deletion is not supported, or deletion failed.
      • deleteRefLog

        void deleteRefLog​(java.lang.String name)
                   throws java.io.IOException
        Delete a reflog from the remote repository.
        Parameters:
        name - name of the ref within the ref space, for example refs/heads/pu.
        Throws:
        java.io.IOException - deletion is not supported, or deletion failed.
      • writeRef

        void writeRef​(java.lang.String name,
                      ObjectId value)
               throws java.io.IOException
        Overwrite (or create) a loose ref in the remote repository.

        This method creates any missing parent directories, if necessary.

        Parameters:
        name - name of the ref within the ref space, for example refs/heads/pu.
        value - new value to store in this ref. Must not be null.
        Throws:
        java.io.IOException - writing is not supported, or attempting to write the file failed, possibly due to permissions or remote disk full, etc.
      • writeInfoPacks

        void writeInfoPacks​(java.util.Collection<java.lang.String> packNames)
                     throws java.io.IOException
        Rebuild the INFO_PACKS for dumb transport clients.

        This method rebuilds the contents of the INFO_PACKS file to match the passed list of pack names.

        Parameters:
        packNames - names of available pack files, in the order they should appear in the file. Valid pack name strings are of the form pack-035760ab452d6eebd123add421f253ce7682355a.pack.
        Throws:
        java.io.IOException - writing is not supported, or attempting to write the file failed, possibly due to permissions or remote disk full, etc.
      • openReader

        java.io.BufferedReader openReader​(java.lang.String path)
                                   throws java.io.IOException
        Open a buffered reader around a file.

        This method is suitable for reading line-oriented resources like info/packs, info/refs, and the alternates list.

        Parameters:
        path - location of the file to read, relative to this objects directory (e.g. info/packs).
        Returns:
        a stream to read from the file. Never null.
        Throws:
        java.io.FileNotFoundException - the requested file does not exist at the given location.
        java.io.IOException - The connection is unable to read the remote's file, and the failure occurred prior to being able to determine if the file exists, or after it was determined to exist but before the stream could be created.
      • readAlternates

        java.util.Collection<WalkRemoteObjectDatabase> readAlternates​(java.lang.String listPath)
                                                               throws java.io.IOException
        Read a standard Git alternates file to discover other object databases.

        This method is suitable for reading the standard formats of the alternates file, such as found in objects/info/alternates or objects/info/http-alternates within a Git repository.

        Alternates appear one per line, with paths expressed relative to this object database.

        Parameters:
        listPath - location of the alternate file to read, relative to this object database (e.g. info/alternates).
        Returns:
        the list of discovered alternates. Empty list if the file exists, but no entries were discovered.
        Throws:
        java.io.FileNotFoundException - the requested file does not exist at the given location.
        java.io.IOException - The connection is unable to read the remote's file, and the failure occurred prior to being able to determine if the file exists, or after it was determined to exist but before the stream could be created.
      • readPackedRefs

        protected void readPackedRefs​(java.util.Map<java.lang.String,​Ref> avail)
                               throws TransportException
        Read a standard Git packed-refs file to discover known references.
        Parameters:
        avail - return collection of references. Any existing entries will be replaced if they are found in the packed-refs file.
        Throws:
        TransportException - an error occurred reading from the packed refs file.
      • readPackedRefsImpl

        private void readPackedRefsImpl​(java.util.Map<java.lang.String,​Ref> avail,
                                        java.io.BufferedReader br)
                                 throws java.io.IOException
        Throws:
        java.io.IOException