Class DfsPackDescription

java.lang.Object
org.eclipse.jgit.internal.storage.dfs.DfsPackDescription
Direct Known Subclasses:
InMemoryRepository.MemPack

public class DfsPackDescription extends Object
Description of a DFS stored pack/index file.

Implementors may extend this class and add additional data members.

Instances of this class are cached with the DfsPackFile, and should not be modified once initialized and presented to the JGit DFS library.

  • Field Details

    • repoDesc

      private final DfsRepositoryDescription repoDesc
    • packName

      private final String packName
    • packSource

      private DfsObjDatabase.PackSource packSource
    • lastModified

      private long lastModified
    • sizeMap

      private long[] sizeMap
    • blockSizeMap

      private int[] blockSizeMap
    • objectCount

      private long objectCount
    • deltaCount

      private long deltaCount
    • minUpdateIndex

      private long minUpdateIndex
    • maxUpdateIndex

      private long maxUpdateIndex
    • packStats

      private PackStatistics packStats
    • refStats

      private ReftableWriter.Stats refStats
    • extensions

      private int extensions
    • indexVersion

      private int indexVersion
    • estimatedPackSize

      private long estimatedPackSize
  • Constructor Details

    • DfsPackDescription

      public DfsPackDescription(DfsRepositoryDescription repoDesc, String name, @NonNull DfsObjDatabase.PackSource packSource)
      Initialize a description by pack name and repository.

      The corresponding index file is assumed to exist. If this is not true implementors must extend the class and override getFileName(PackExt).

      Callers should also try to fill in other fields if they are reasonably free to access at the time this instance is being initialized.

      Parameters:
      name - name of the pack file. Must end with ".pack".
      repoDesc - description of the repo containing the pack file.
      packSource - the source of the pack.
  • Method Details

    • objectLookupComparator

      public static Comparator<DfsPackDescription> objectLookupComparator()
      Comparator for packs when looking up objects in indexes.

      This comparator tries to position packs in the order readers should examine them when looking for objects by SHA-1. The default tries to sort packs with more recent modification dates before older packs, and packs with fewer objects before packs with more objects.

      Uses DfsObjDatabase.PackSource.DEFAULT_COMPARATOR for the portion of comparison where packs are sorted by source.

      Returns:
      comparator.
    • objectLookupComparator

      public static Comparator<DfsPackDescription> objectLookupComparator(Comparator<DfsObjDatabase.PackSource> packSourceComparator)
      Comparator for packs when looking up objects in indexes.

      This comparator tries to position packs in the order readers should examine them when looking for objects by SHA-1. The default tries to sort packs with more recent modification dates before older packs, and packs with fewer objects before packs with more objects.

      Parameters:
      packSourceComparator - comparator for the DfsObjDatabase.PackSource, used as the first step in comparison.
      Returns:
      comparator.
    • reftableComparator

      static Comparator<DfsPackDescription> reftableComparator()
    • reuseComparator

      static Comparator<DfsPackDescription> reuseComparator()
    • getRepositoryDescription

      public DfsRepositoryDescription getRepositoryDescription()
      Get description of the repository.
      Returns:
      description of the repository.
    • addFileExt

      public void addFileExt(PackExt ext)
      Adds the pack file extension to the known list.
      Parameters:
      ext - the file extension
    • hasFileExt

      public boolean hasFileExt(PackExt ext)
      Whether the pack file extension is known to exist.
      Parameters:
      ext - the file extension
      Returns:
      whether the pack file extension is known to exist.
    • getFileName

      public String getFileName(PackExt ext)
      Get file name
      Parameters:
      ext - the file extension
      Returns:
      name of the file.
    • getStreamKey

      public DfsStreamKey getStreamKey(PackExt ext)
      Get cache key for use by the block cache.
      Parameters:
      ext - the file extension.
      Returns:
      cache key for use by the block cache.
    • getPackSource

      @NonNull public DfsObjDatabase.PackSource getPackSource()
      Get the source of the pack.
      Returns:
      the source of the pack.
    • setPackSource

      public DfsPackDescription setPackSource(@NonNull DfsObjDatabase.PackSource source)
      Set the source of the pack.
      Parameters:
      source - the source of the pack.
      Returns:
      this
    • getLastModified

      public long getLastModified()
      Get time the pack was created, in milliseconds.
      Returns:
      time the pack was created, in milliseconds.
    • setLastModified

      public DfsPackDescription setLastModified(long timeMillis)
      Set time the pack was created, in milliseconds.
      Parameters:
      timeMillis - time the pack was created, in milliseconds. 0 if not known.
      Returns:
      this
    • getMinUpdateIndex

      public long getMinUpdateIndex()
      Get minUpdateIndex for the reftable, if present.
      Returns:
      minUpdateIndex for the reftable, if present.
    • setMinUpdateIndex

      public DfsPackDescription setMinUpdateIndex(long min)
      Set minUpdateIndex for the reftable.
      Parameters:
      min - minUpdateIndex for the reftable.
      Returns:
      this
    • getMaxUpdateIndex

      public long getMaxUpdateIndex()
      Get maxUpdateIndex for the reftable, if present.
      Returns:
      maxUpdateIndex for the reftable, if present.
    • setMaxUpdateIndex

      public DfsPackDescription setMaxUpdateIndex(long max)
      Set maxUpdateIndex for the reftable.
      Parameters:
      max - maxUpdateIndex for the reftable.
      Returns:
      this
    • setFileSize

      public DfsPackDescription setFileSize(PackExt ext, long bytes)
      Set size of the file in bytes.
      Parameters:
      ext - the file extension.
      bytes - size of the file in bytes. If 0 the file is not known and will be determined on first read.
      Returns:
      this
    • getFileSize

      public long getFileSize(PackExt ext)
      Get size of the file, in bytes.
      Parameters:
      ext - the file extension.
      Returns:
      size of the file, in bytes. If 0 the file size is not yet known.
    • getBlockSize

      public int getBlockSize(PackExt ext)
      Get blockSize of the file, in bytes.
      Parameters:
      ext - the file extension.
      Returns:
      blockSize of the file, in bytes. If 0 the blockSize size is not yet known and may be discovered when opening the file.
    • setBlockSize

      public DfsPackDescription setBlockSize(PackExt ext, int blockSize)
      Set blockSize of the file, in bytes.
      Parameters:
      ext - the file extension.
      blockSize - blockSize of the file, in bytes. If 0 the blockSize is not known and will be determined on first read.
      Returns:
      this
    • setEstimatedPackSize

      public DfsPackDescription setEstimatedPackSize(long estimatedPackSize)
      Set estimated size of the .pack file in bytes.
      Parameters:
      estimatedPackSize - estimated size of the .pack file in bytes. If 0 the pack file size is unknown.
      Returns:
      this
    • getEstimatedPackSize

      public long getEstimatedPackSize()
      Get estimated size of the .pack file in bytes.
      Returns:
      estimated size of the .pack file in bytes. If 0 the pack file size is unknown.
    • getObjectCount

      public long getObjectCount()
      Get number of objects in the pack.
      Returns:
      number of objects in the pack.
    • setObjectCount

      public DfsPackDescription setObjectCount(long cnt)
      Set number of objects in the pack.
      Parameters:
      cnt - number of objects in the pack.
      Returns:
      this
    • getDeltaCount

      public long getDeltaCount()
      Get number of delta compressed objects in the pack.
      Returns:
      number of delta compressed objects in the pack.
    • setDeltaCount

      public DfsPackDescription setDeltaCount(long cnt)
      Set number of delta compressed objects in the pack.
      Parameters:
      cnt - number of delta compressed objects in the pack.
      Returns:
      this
    • getPackStats

      public PackStatistics getPackStats()
      Get statistics from PackWriter, if the pack was built with it.
      Returns:
      statistics from PackWriter, if the pack was built with it. Generally this is only available for packs created by DfsGarbageCollector or DfsPackCompactor, and only when the pack is being committed to the repository.
    • setPackStats

      DfsPackDescription setPackStats(PackStatistics stats)
    • getReftableStats

      public ReftableWriter.Stats getReftableStats()
      Get stats from the sibling reftable, if created.
      Returns:
      stats from the sibling reftable, if created.
    • setReftableStats

      void setReftableStats(ReftableWriter.Stats stats)
    • clearPackStats

      public DfsPackDescription clearPackStats()
      Discard the pack statistics, if it was populated.
      Returns:
      this
    • getIndexVersion

      public int getIndexVersion()
      Get the version of the index file written.
      Returns:
      the version of the index file written.
    • setIndexVersion

      public DfsPackDescription setIndexVersion(int version)
      Set the version of the index file written.
      Parameters:
      version - the version of the index file written.
      Returns:
      this
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object b)
      Overrides:
      equals in class Object
    • isGC

      static boolean isGC(DfsObjDatabase.PackSource s)
    • toString

      public String toString()
      Overrides:
      toString in class Object