Class DfsPackFile
java.lang.Object
org.eclipse.jgit.internal.storage.dfs.BlockBasedFile
org.eclipse.jgit.internal.storage.dfs.DfsPackFile
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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PackBitmapIndex
Index of compressed bitmap mapping entire object graph.private LongList
Objects we have tried to read, and discovered to be corrupt.private PackIndex
Index mappingObjectId
to position within the pack stream.private final Object
Lock for initialization ofindex
andcorruptObjects
.private static final int
private static final long
private PackReverseIndex
Fields inherited from class org.eclipse.jgit.internal.storage.dfs.BlockBasedFile
blockSize, cache, desc, ext, invalid, invalidatingCause, key, length
-
Constructor Summary
ConstructorsConstructorDescriptionDfsPackFile
(DfsBlockCache cache, DfsPackDescription desc) Construct a reader for an existing, packfile. -
Method Summary
Modifier and TypeMethodDescription(package private) void
copyAsIs
(PackOutputStream out, DfsObjectToPack src, boolean validate, DfsReader ctx) (package private) void
copyPackAsIs
(PackOutputStream out, DfsReader ctx) private long
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) Get description that was originally used to configure this pack file.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
(package private) boolean
isCorrupt
(long offset) (package private) final boolean
boolean
Whether the pack index file is loaded and cached in memory.(package private) ObjectLoader
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 ByteBuffer
newCopyBuffer
(PackOutputStream out, ReadableChannel rc) private IOException
private void
(package private) void
representation
(DfsObjectRepresentation r, long pos, DfsReader ctx, PackReverseIndex rev) (package private) void
resolve
(DfsReader ctx, 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 Details
-
REC_SIZE
private static final int REC_SIZE- See Also:
-
REF_POSITION
private static final long REF_POSITION- See Also:
-
initLock
Lock for initialization ofindex
andcorruptObjects
.This lock ensures only one thread can perform the initialization work.
-
index
Index mappingObjectId
to position within the pack stream. -
reverseIndex
-
bitmapIndex
Index of compressed bitmap mapping entire object graph. -
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 Details
-
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 Details
-
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
-
getPackIndex
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:
IOException
- the pack index is not available, or is corrupt.
-
idx
- Throws:
IOException
-
isGarbage
final boolean isGarbage() -
getBitmapIndex
- Throws:
IOException
-
getReverseIdx
- Throws:
IOException
-
hasObject
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:
IOException
- the pack index is not available, or is corrupt.
-
get
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:
IOException
- the pack file or the index could not be read.
-
findOffset
- Throws:
IOException
-
resolve
void resolve(DfsReader ctx, Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit) throws IOException - Throws:
IOException
-
getObjectCount
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:
IOException
- the index file cannot be loaded into memory.
-
decompress
private byte[] decompress(long position, int sz, DfsReader ctx) throws IOException, DataFormatException - Throws:
IOException
DataFormatException
-
copyPackAsIs
- Throws:
IOException
-
copyPackThroughCache
private void copyPackThroughCache(PackOutputStream out, DfsReader ctx, ReadableChannel rc) throws IOException - Throws:
IOException
-
copyPackBypassCache
- Throws:
IOException
-
newCopyBuffer
-
copyAsIs
void copyAsIs(PackOutputStream out, DfsObjectToPack src, boolean validate, DfsReader ctx) throws IOException, StoredObjectRepresentationNotAvailableException -
packfileIsTruncated
-
readFully
private void readFully(long position, byte[] dstbuf, int dstoff, int cnt, DfsReader ctx) throws IOException - Throws:
IOException
-
load
- Throws:
IOException
-
findDeltaBase
private long findDeltaBase(DfsReader ctx, ObjectId baseId) throws IOException, MissingObjectException - Throws:
IOException
MissingObjectException
-
getDeltaHeader
- Throws:
IOException
DataFormatException
-
getObjectType
- Throws:
IOException
-
getObjectSize
- Throws:
IOException
-
getObjectSize
- Throws:
IOException
-
representation
void representation(DfsObjectRepresentation r, long pos, DfsReader ctx, PackReverseIndex rev) throws IOException - Throws:
IOException
-
isCorrupt
boolean isCorrupt(long offset) -
setCorrupt
private void setCorrupt(long offset) -
loadPackIndex
private DfsBlockCache.Ref<PackIndex> loadPackIndex(DfsReader ctx, DfsStreamKey idxKey) throws IOException - Throws:
IOException
-
loadReverseIdx
-
loadBitmapIndex
private DfsBlockCache.Ref<PackBitmapIndex> loadBitmapIndex(DfsReader ctx, DfsStreamKey bitmapKey, PackIndex idx, PackReverseIndex revidx) throws IOException - Throws:
IOException
-