Class FileReftableDatabase


  • public class FileReftableDatabase
    extends RefDatabase
    Implements RefDatabase using reftable for storage. This class is threadsafe.
    • Constructor Detail

      • FileReftableDatabase

        FileReftableDatabase​(FileRepository repo)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • FileReftableDatabase

        FileReftableDatabase​(FileRepository repo,
                             java.io.File refstackName)
                      throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getReflogReader

        ReflogReader getReflogReader​(java.lang.String refname)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • isReftable

        public static boolean isReftable​(java.io.File repoDir)
        Parameters:
        repoDir -
        Returns:
        whether the given repo uses reftable for refdb storage.
      • hasFastTipsWithSha1

        public boolean hasFastTipsWithSha1()
                                    throws java.io.IOException
        If the ref database does not support fast inverse queries, it may be advantageous to build a complete SHA1 to ref map in advance for multiple uses. To let applications decide on this decision, this function indicates whether the inverse map is available.
        Overrides:
        hasFastTipsWithSha1 in class RefDatabase
        Returns:
        whether this RefDatabase supports fast inverse ref queries.
        Throws:
        java.io.IOException - on I/O problems.
      • compactFully

        public void compactFully()
                          throws java.io.IOException
        Runs a full compaction for GC purposes.
        Throws:
        java.io.IOException - on I/O errors
      • getLock

        private java.util.concurrent.locks.ReentrantLock getLock()
      • performsAtomicTransactions

        public boolean performsAtomicTransactions()
        Whether the database is capable of performing batch updates as atomic transactions.

        If true, by default BatchRefUpdate instances will perform updates atomically, meaning either all updates will succeed, or all updates will fail. It is still possible to turn off this behavior on a per-batch basis by calling update.setAtomic(false).

        If false, BatchRefUpdate instances will never perform updates atomically, and calling update.setAtomic(true) will cause the entire batch to fail with REJECTED_OTHER_REASON.

        This definition of atomicity is stronger than what is provided by ReceivePack. ReceivePack will attempt to reject all commands if it knows in advance some commands may fail, even if the storage layer does not support atomic transactions. Here, atomicity applies even in the case of unforeseeable errors.

        Overrides:
        performsAtomicTransactions in class RefDatabase
        Returns:
        whether transactions are atomic by default.
      • newBatchUpdate

        @NonNull
        public BatchRefUpdate newBatchUpdate()
        Create a new batch update to attempt on this database.

        The default implementation performs a sequential update of each command.

        Overrides:
        newBatchUpdate in class RefDatabase
        Returns:
        a new batch update object.
      • newUpdate

        public RefUpdate newUpdate​(java.lang.String refName,
                                   boolean detach)
                            throws java.io.IOException
        Create a new update command to create, modify or delete a reference.
        Specified by:
        newUpdate in class RefDatabase
        Parameters:
        refName - the name of the reference.
        detach - if true and name is currently a SymbolicRef, the update will replace it with an ObjectIdRef. Otherwise, the update will recursively traverse SymbolicRefs and operate on the leaf ObjectIdRef.
        Returns:
        a new update for the requested name; never null.
        Throws:
        java.io.IOException - the reference space cannot be accessed.
      • exactRef

        public Ref exactRef​(java.lang.String name)
                     throws java.io.IOException
        Read a single reference.

        Unlike RefDatabase.findRef(java.lang.String), this method expects an unshortened reference name and does not search using the standard RefDatabase.SEARCH_PATH.

        Specified by:
        exactRef in class RefDatabase
        Parameters:
        name - the unabbreviated name of the reference.
        Returns:
        the reference (if it exists); else null.
        Throws:
        java.io.IOException - the reference space cannot be accessed.
      • getRefs

        public java.util.List<Ref> getRefs()
                                    throws java.io.IOException
        Returns all refs.

        This includes HEAD, branches under ref/heads/, tags under refs/tags/, etc. It does not include pseudo-refs like FETCH_HEAD; for those, see RefDatabase.getAdditionalRefs().

        Symbolic references to a non-existent ref (for example, HEAD pointing to a branch yet to be born) are not included.

        Callers interested in only a portion of the ref hierarchy can call RefDatabase.getRefsByPrefix(java.lang.String) instead.

        Overrides:
        getRefs in class RefDatabase
        Returns:
        immutable list of all refs.
        Throws:
        java.io.IOException - the reference space cannot be accessed.
      • getRefs

        public java.util.Map<java.lang.String,​Ref> getRefs​(java.lang.String prefix)
                                                          throws java.io.IOException
        Get a section of the reference namespace.
        Specified by:
        getRefs in class RefDatabase
        Parameters:
        prefix - prefix to search the namespace with; must end with /. If the empty string (RefDatabase.ALL), obtain a complete snapshot of all references.
        Returns:
        modifiable map that is a complete snapshot of the current reference namespace, with prefix removed from the start of each key. The map can be an unsorted map.
        Throws:
        java.io.IOException - the reference space cannot be accessed.
      • getAdditionalRefs

        public java.util.List<Ref> getAdditionalRefs()
                                              throws java.io.IOException
        Get the additional reference-like entities from the repository.

        The result list includes non-ref items such as MERGE_HEAD and FETCH_RESULT cast to be refs. The names of these refs are not returned by getRefs() but are accepted by RefDatabase.findRef(String) and RefDatabase.exactRef(String).

        Specified by:
        getAdditionalRefs in class RefDatabase
        Returns:
        a list of additional refs
        Throws:
        java.io.IOException - the reference space cannot be accessed.
      • peel

        public Ref peel​(Ref ref)
                 throws java.io.IOException
        Peel a possibly unpeeled reference by traversing the annotated tags.

        If the reference cannot be peeled (as it does not refer to an annotated tag) the peeled id stays null, but Ref.isPeeled() will be true.

        Implementors should check Ref.isPeeled() before performing any additional work effort.

        Specified by:
        peel in class RefDatabase
        Parameters:
        ref - The reference to peel
        Returns:
        ref if ref.isPeeled() is true; otherwise a new Ref object representing the same data as Ref, but isPeeled() will be true and getPeeledObjectId() will contain the peeled object (or null).
        Throws:
        java.io.IOException - the reference space or object space cannot be accessed.
      • doPeel

        private Ref doPeel​(Ref leaf)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • recreate

        private static Ref recreate​(Ref old,
                                    Ref leaf,
                                    boolean hasVersioning)
      • newRename

        public RefRename newRename​(java.lang.String fromName,
                                   java.lang.String toName)
                            throws java.io.IOException
        Create a new update command to rename a reference.
        Specified by:
        newRename in class RefDatabase
        Parameters:
        fromName - name of reference to rename from
        toName - name of reference to rename to
        Returns:
        an update command that knows how to rename a branch to another.
        Throws:
        java.io.IOException - the reference space cannot be accessed.
      • isNameConflicting

        public boolean isNameConflicting​(java.lang.String name)
                                  throws java.io.IOException
        Determine if a proposed reference name overlaps with an existing one.

        Reference names use '/' as a component separator, and may be stored in a hierarchical storage such as a directory on the local filesystem.

        If the reference "refs/heads/foo" exists then "refs/heads/foo/bar" must not exist, as a reference cannot have a value and also be a container for other references at the same time.

        If the reference "refs/heads/foo/bar" exists than the reference "refs/heads/foo" cannot exist, for the same reason.

        Specified by:
        isNameConflicting in class RefDatabase
        Parameters:
        name - proposed name.
        Returns:
        true if the name overlaps with an existing reference; false if using this name right now would be safe.
        Throws:
        java.io.IOException - the database could not be read to check for conflicts.
        See Also:
        RefDatabase.getConflictingNames(String)
      • close

        public void close()
        Close any resources held by this database.
        Specified by:
        close in class RefDatabase
      • create

        public void create()
                    throws java.io.IOException
        Initialize a new reference database at this location.
        Specified by:
        create in class RefDatabase
        Throws:
        java.io.IOException - the database could not be created.
      • addReftable

        private boolean addReftable​(FileReftableStack.Writer w)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeConvertTable

        private static void writeConvertTable​(Repository repo,
                                              ReftableWriter w,
                                              boolean writeLogs)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • refForWrite

        private static Ref refForWrite​(RevWalk rw,
                                       Ref r)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • convertFrom

        public static FileReftableDatabase convertFrom​(FileRepository repo,
                                                       boolean writeLogs)
                                                throws java.io.IOException
        Parameters:
        repo - the repository
        writeLogs - whether to write reflogs
        Returns:
        a reftable based RefDB from an existing repository.
        Throws:
        java.io.IOException - on IO error