Class ReftableWriter


  • public class ReftableWriter
    extends Object
    Writes a reftable formatted file.

    A reftable can be written in a streaming fashion, provided the caller sorts all references. A ReftableWriter is single-use, and not thread-safe.

    • Constructor Detail

      • ReftableWriter

        public ReftableWriter​(OutputStream os)
        Initialize a writer with a default configuration.
        Parameters:
        os - output stream.
      • ReftableWriter

        public ReftableWriter​(ReftableConfig cfg,
                              OutputStream os)
        Initialize a writer with a configuration.
        Parameters:
        cfg - configuration for the writer
        os - output stream.
    • Method Detail

      • setConfig

        public ReftableWriter setConfig​(ReftableConfig cfg)
        Set configuration for the writer.
        Parameters:
        cfg - configuration for the writer.
        Returns:
        this
      • setMinUpdateIndex

        public ReftableWriter setMinUpdateIndex​(long min)
        Set the minimum update index for log entries that appear in this reftable.
        Parameters:
        min - the minimum update index for log entries that appear in this reftable. This should be 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.
        Returns:
        this
      • setMaxUpdateIndex

        public ReftableWriter setMaxUpdateIndex​(long max)
        Set the maximum update index for log entries that appear in this reftable.
        Parameters:
        max - the maximum update index for log entries that appear in this reftable. This should be at least 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.
        Returns:
        this
      • begin

        public ReftableWriter begin()
        Begin writing the reftable. Should be called only once. Call this if a stream was passed to the constructor.
        Returns:
        this
      • sortAndWriteRefs

        public ReftableWriter sortAndWriteRefs​(Collection<Ref> refsToPack)
                                        throws IOException
        Sort a collection of references and write them to the reftable. The input refs may not have duplicate names.
        Parameters:
        refsToPack - references to sort and write.
        Returns:
        this
        Throws:
        IOException - if reftable cannot be written.
      • writeRef

        public void writeRef​(Ref ref)
                      throws IOException
        Write one reference to the reftable.

        References must be passed in sorted order.

        Parameters:
        ref - the reference to store.
        Throws:
        IOException - if reftable cannot be written.
      • writeRef

        public void writeRef​(Ref ref,
                             long updateIndex)
                      throws IOException
        Write one reference to the reftable.

        References must be passed in sorted order.

        Parameters:
        ref - the reference to store.
        updateIndex - the updateIndex that modified this reference. Must be >= minUpdateIndex for this file.
        Throws:
        IOException - if reftable cannot be written.
      • writeLog

        public void writeLog​(String ref,
                             long updateIndex,
                             PersonIdent who,
                             ObjectId oldId,
                             ObjectId newId,
                             @Nullable
                             String message)
                      throws IOException
        Write one reflog entry to the reftable.

        Reflog entries must be written in reference name and descending updateIndex (highest first) order.

        Parameters:
        ref - name of the reference.
        updateIndex - identifier of the transaction that created the log record. The updateIndex must be unique within the scope of ref, and must be within the bounds defined by minUpdateIndex <= updateIndex <= maxUpdateIndex.
        who - committer of the reflog entry.
        oldId - prior id; pass ObjectId.zeroId() for creations.
        newId - new id; pass ObjectId.zeroId() for deletions.
        message - optional message (may be null).
        Throws:
        IOException - if reftable cannot be written.
      • deleteLog

        public void deleteLog​(String ref,
                              long updateIndex)
                       throws IOException
        Record deletion of one reflog entry in this reftable.

        The deletion can shadow an entry stored in a lower table in the stack. This is useful for refs/stash and dropping an entry from its reflog.

        Deletion must be properly interleaved in sorted updateIndex order with any other logs written by writeLog(String, long, PersonIdent, ObjectId, ObjectId, String).

        Parameters:
        ref - the ref to delete (hide) a reflog entry from.
        updateIndex - the update index that must be hidden.
        Throws:
        IOException - if reftable cannot be written.
      • getStats

        public ReftableWriter.Stats getStats()
        Get statistics of the last written reftable.
        Returns:
        statistics of the last written reftable.