Class DfsPackFile
- java.lang.Object
-
- org.eclipse.jgit.internal.storage.dfs.BlockBasedFile
-
- org.eclipse.jgit.internal.storage.dfs.DfsPackFile
-
public final class DfsPackFile extends BlockBasedFile
A Git version 2 pack file representation. A pack file contains Git objects in delta packed format yielding high compression of lots of object where some objects are similar.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DfsPackFile.Delta
-
Field Summary
Fields Modifier and Type Field Description private PackBitmapIndex
bitmapIndex
Index of compressed bitmap mapping entire object graph.private LongList
corruptObjects
Objects we have tried to read, and discovered to be corrupt.private PackIndex
index
Index mappingObjectId
to position within the pack stream.private java.lang.Object
initLock
Lock for initialization ofindex
andcorruptObjects
.private static int
REC_SIZE
private static long
REF_POSITION
private PackReverseIndex
reverseIndex
-
Fields inherited from class org.eclipse.jgit.internal.storage.dfs.BlockBasedFile
blockSize, cache, desc, ext, invalid, invalidatingCause, key, length
-
-
Constructor Summary
Constructors Constructor Description DfsPackFile(DfsBlockCache cache, DfsPackDescription desc)
Construct a reader for an existing, packfile.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
copyAsIs(PackOutputStream out, DfsObjectToPack src, boolean validate, DfsReader ctx)
(package private) void
copyPackAsIs(PackOutputStream out, DfsReader ctx)
private long
copyPackBypassCache(PackOutputStream out, ReadableChannel rc)
private void
copyPackThroughCache(PackOutputStream out, DfsReader ctx, ReadableChannel rc)
private byte[]
decompress(long position, int sz, DfsReader ctx)
private long
findDeltaBase(DfsReader ctx, ObjectId baseId)
(package private) long
findOffset(DfsReader ctx, AnyObjectId id)
(package private) ObjectLoader
get(DfsReader ctx, AnyObjectId id)
Get an object from this pack.(package private) PackBitmapIndex
getBitmapIndex(DfsReader ctx)
(package private) byte[]
getDeltaHeader(DfsReader wc, long pos)
(package private) long
getObjectCount(DfsReader ctx)
Obtain the total number of objects available in this pack.(package private) long
getObjectSize(DfsReader ctx, long pos)
(package private) long
getObjectSize(DfsReader ctx, AnyObjectId id)
(package private) int
getObjectType(DfsReader ctx, long pos)
DfsPackDescription
getPackDescription()
Get description that was originally used to configure this pack file.PackIndex
getPackIndex(DfsReader ctx)
Get the PackIndex for this PackFile.(package private) PackReverseIndex
getReverseIdx(DfsReader ctx)
boolean
hasObject(DfsReader ctx, AnyObjectId id)
Check if an object is stored within this pack.private PackIndex
idx(DfsReader ctx)
(package private) boolean
isCorrupt(long offset)
(package private) boolean
isGarbage()
boolean
isIndexLoaded()
Whether the pack index file is loaded and cached in memory.(package private) ObjectLoader
load(DfsReader ctx, long pos)
private DfsBlockCache.Ref<PackBitmapIndex>
loadBitmapIndex(DfsReader ctx, DfsStreamKey bitmapKey, PackIndex idx, PackReverseIndex revidx)
private DfsBlockCache.Ref<PackIndex>
loadPackIndex(DfsReader ctx, DfsStreamKey idxKey)
private DfsBlockCache.Ref<PackReverseIndex>
loadReverseIdx(DfsStreamKey revKey, PackIndex idx)
private java.nio.ByteBuffer
newCopyBuffer(PackOutputStream out, ReadableChannel rc)
private java.io.IOException
packfileIsTruncated()
private void
readFully(long position, byte[] dstbuf, int dstoff, int cnt, DfsReader ctx)
(package private) void
representation(DfsObjectRepresentation r, long pos, DfsReader ctx, PackReverseIndex rev)
(package private) void
resolve(DfsReader ctx, java.util.Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit)
private void
setCorrupt(long offset)
(package private) void
setPackIndex(PackIndex idx)
-
Methods inherited from class org.eclipse.jgit.internal.storage.dfs.BlockBasedFile
alignToBlock, blockSize, elapsedMicros, getFileName, getOrLoadBlock, invalid, read, readOneBlock, setBlockSize, setInvalid
-
-
-
-
Field Detail
-
REC_SIZE
private static final int REC_SIZE
- See Also:
- Constant Field Values
-
REF_POSITION
private static final long REF_POSITION
- See Also:
- Constant Field Values
-
initLock
private final java.lang.Object initLock
Lock for initialization ofindex
andcorruptObjects
.This lock ensures only one thread can perform the initialization work.
-
reverseIndex
private volatile PackReverseIndex reverseIndex
-
bitmapIndex
private volatile PackBitmapIndex bitmapIndex
Index of compressed bitmap mapping entire object graph.
-
corruptObjects
private volatile LongList corruptObjects
Objects we have tried to read, and discovered to be corrupt.The list is allocated after the first corruption is found, and filled in as more entries are discovered. Typically this list is never used, as pack files do not usually contain corrupt objects.
-
-
Constructor Detail
-
DfsPackFile
DfsPackFile(DfsBlockCache cache, DfsPackDescription desc)
Construct a reader for an existing, packfile.- Parameters:
cache
- cache that owns the pack data.desc
- description of the pack within the DFS.
-
-
Method Detail
-
getPackDescription
public DfsPackDescription getPackDescription()
Get description that was originally used to configure this pack file.- Returns:
- description that was originally used to configure this pack file.
-
isIndexLoaded
public boolean isIndexLoaded()
Whether the pack index file is loaded and cached in memory.- Returns:
- whether the pack index file is loaded and cached in memory.
-
setPackIndex
void setPackIndex(PackIndex idx)
-
getPackIndex
public PackIndex getPackIndex(DfsReader ctx) throws java.io.IOException
Get the PackIndex for this PackFile.- Parameters:
ctx
- reader context to support reading from the backing store if the index is not already loaded in memory.- Returns:
- the PackIndex.
- Throws:
java.io.IOException
- the pack index is not available, or is corrupt.
-
isGarbage
final boolean isGarbage()
-
getBitmapIndex
PackBitmapIndex getBitmapIndex(DfsReader ctx) throws java.io.IOException
- Throws:
java.io.IOException
-
getReverseIdx
PackReverseIndex getReverseIdx(DfsReader ctx) throws java.io.IOException
- Throws:
java.io.IOException
-
hasObject
public boolean hasObject(DfsReader ctx, AnyObjectId id) throws java.io.IOException
Check if an object is stored within this pack.- Parameters:
ctx
- reader context to support reading from the backing store if the index is not already loaded in memory.id
- object to be located.- Returns:
- true if the object exists in this pack; false if it does not.
- Throws:
java.io.IOException
- the pack index is not available, or is corrupt.
-
get
ObjectLoader get(DfsReader ctx, AnyObjectId id) throws java.io.IOException
Get an object from this pack.- Parameters:
ctx
- temporary working space associated with the calling thread.id
- the object to obtain from the pack. Must not be null.- Returns:
- the object loader for the requested object if it is contained in this pack; null if the object was not found.
- Throws:
java.io.IOException
- the pack file or the index could not be read.
-
findOffset
long findOffset(DfsReader ctx, AnyObjectId id) throws java.io.IOException
- Throws:
java.io.IOException
-
resolve
void resolve(DfsReader ctx, java.util.Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit) throws java.io.IOException
- Throws:
java.io.IOException
-
getObjectCount
long getObjectCount(DfsReader ctx) throws java.io.IOException
Obtain the total number of objects available in this pack. This method relies on pack index, giving number of effectively available objects.- Parameters:
ctx
- current reader for the calling thread.- Returns:
- number of objects in index of this pack, likewise in this pack
- Throws:
java.io.IOException
- the index file cannot be loaded into memory.
-
decompress
private byte[] decompress(long position, int sz, DfsReader ctx) throws java.io.IOException, java.util.zip.DataFormatException
- Throws:
java.io.IOException
java.util.zip.DataFormatException
-
copyPackAsIs
void copyPackAsIs(PackOutputStream out, DfsReader ctx) throws java.io.IOException
- Throws:
java.io.IOException
-
copyPackThroughCache
private void copyPackThroughCache(PackOutputStream out, DfsReader ctx, ReadableChannel rc) throws java.io.IOException
- Throws:
java.io.IOException
-
copyPackBypassCache
private long copyPackBypassCache(PackOutputStream out, ReadableChannel rc) throws java.io.IOException
- Throws:
java.io.IOException
-
newCopyBuffer
private java.nio.ByteBuffer newCopyBuffer(PackOutputStream out, ReadableChannel rc)
-
copyAsIs
void copyAsIs(PackOutputStream out, DfsObjectToPack src, boolean validate, DfsReader ctx) throws java.io.IOException, StoredObjectRepresentationNotAvailableException
- Throws:
java.io.IOException
StoredObjectRepresentationNotAvailableException
-
packfileIsTruncated
private java.io.IOException packfileIsTruncated()
-
readFully
private void readFully(long position, byte[] dstbuf, int dstoff, int cnt, DfsReader ctx) throws java.io.IOException
- Throws:
java.io.IOException
-
load
ObjectLoader load(DfsReader ctx, long pos) throws java.io.IOException
- Throws:
java.io.IOException
-
findDeltaBase
private long findDeltaBase(DfsReader ctx, ObjectId baseId) throws java.io.IOException, MissingObjectException
- Throws:
java.io.IOException
MissingObjectException
-
getDeltaHeader
byte[] getDeltaHeader(DfsReader wc, long pos) throws java.io.IOException, java.util.zip.DataFormatException
- Throws:
java.io.IOException
java.util.zip.DataFormatException
-
getObjectType
int getObjectType(DfsReader ctx, long pos) throws java.io.IOException
- Throws:
java.io.IOException
-
getObjectSize
long getObjectSize(DfsReader ctx, AnyObjectId id) throws java.io.IOException
- Throws:
java.io.IOException
-
getObjectSize
long getObjectSize(DfsReader ctx, long pos) throws java.io.IOException
- Throws:
java.io.IOException
-
representation
void representation(DfsObjectRepresentation r, long pos, DfsReader ctx, PackReverseIndex rev) throws java.io.IOException
- Throws:
java.io.IOException
-
isCorrupt
boolean isCorrupt(long offset)
-
setCorrupt
private void setCorrupt(long offset)
-
loadPackIndex
private DfsBlockCache.Ref<PackIndex> loadPackIndex(DfsReader ctx, DfsStreamKey idxKey) throws java.io.IOException
- Throws:
java.io.IOException
-
loadReverseIdx
private DfsBlockCache.Ref<PackReverseIndex> loadReverseIdx(DfsStreamKey revKey, PackIndex idx)
-
loadBitmapIndex
private DfsBlockCache.Ref<PackBitmapIndex> loadBitmapIndex(DfsReader ctx, DfsStreamKey bitmapKey, PackIndex idx, PackReverseIndex revidx) throws java.io.IOException
- Throws:
java.io.IOException
-
-