Class Pack
java.lang.Object
org.eclipse.jgit.internal.storage.file.Pack
- All Implemented Interfaces:
Iterable<PackIndex.MutableEntry>
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 int
private int
private PackBitmapIndex
private PackFile
private LongList
Objects we have tried to read, and discovered to be corrupt.private RandomAccessFile
private PackFileSnapshot
(package private) final int
private boolean
private Exception
private PackFile
(package private) long
private PackIndex
private static final org.slf4j.Logger
private byte[]
private final PackFile
(package private) Instant
private final Object
Serializes reads performed againstfd
.private PackReverseIndex
static final Comparator<Pack>
Sorts PackFiles to be most recently created to least recently created.private AtomicInteger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
(package private) boolean
void
close()
Close the resources utilized by this repository(package private) final void
copyAsIs
(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) private void
copyAsIs2
(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) (package private) void
copyPackAsIs
(PackOutputStream out, WindowCursor curs) private final byte[]
decompress
(long position, int sz, WindowCursor curs) private void
doClose()
private void
doOpen()
private void
(package private) boolean
private long
findDeltaBase
(ObjectId baseId) private long
findEndOffset
(long startOffset) (package private) ObjectId
findObjectForOffset
(long offset) Search for object id with the specified start offset in associated pack (reverse) index.(package private) ObjectLoader
get
(WindowCursor curs, AnyObjectId id) Get an object from this pack.(package private) PackBitmapIndex
(package private) byte[]
getDeltaHeader
(WindowCursor wc, long pos) (package private) PackFileSnapshot
Return the @FileSnapshot
associated to the underlying packfile that has been used when the object was created.getIndex()
Get the index for this pack file.(package private) long
Obtain the total number of objects available in this pack.(package private) long
getObjectSize
(WindowCursor curs, long pos) (package private) long
getObjectSize
(WindowCursor curs, AnyObjectId id) (package private) int
getObjectType
(WindowCursor curs, long pos) (package private) AnyObjectId
Get the File object which locates this pack on disk.Get name extracted frompack-*.pack
pattern.private PackReverseIndex
boolean
hasObject
(AnyObjectId id) Determine if an object is contained within the pack file.private PackIndex
idx()
(package private) int
(package private) boolean
invalid()
private boolean
isCorrupt
(long offset) iterator()
(package private) ObjectLoader
load
(WindowCursor curs, long pos) (package private) ByteWindow
mmap
(long pos, int size) private void
private void
(package private) ByteArrayWindow
read
(long pos, int size) private void
readFully
(long position, byte[] dstbuf, int dstoff, int cnt, WindowCursor curs) (package private) LocalObjectRepresentation
representation
(WindowCursor curs, AnyObjectId objectId) (package private) void
(package private) void
resolve
(Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit) private void
setCorrupt
(long offset) (package private) void
boolean
Determines whether a .keep file exists for this pack file.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
SORT
Sorts PackFiles to be most recently created to least recently created. -
packFile
-
keepFile
-
hash
final int hash -
fd
-
readLock
Serializes reads performed againstfd
. -
length
long length -
activeWindows
private int activeWindows -
activeCopyRawData
private int activeCopyRawData -
packLastModified
Instant packLastModified -
fileSnapshot
-
invalid
private volatile boolean invalid -
invalidatingCause
-
bitmapIdxFile
-
transientErrorCount
-
packChecksum
private byte[] packChecksum -
loadedIdx
-
reverseIdx
-
bitmapIdx
-
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
-
Pack
Construct a reader for an existing, pre-indexed packfile.- Parameters:
packFile
- path of the.pack
file holding the data.bitmapIdxFile
- existing bitmap index file with the same base as the pack
-
-
Method Details
-
idx
- Throws:
IOException
-
getPackFile
Get the File object which locates this pack on disk.- Returns:
- the File object which locates this pack on disk.
-
getIndex
Get the index for this pack file.- Returns:
- the index for this pack file.
- Throws:
IOException
-
getPackName
Get name extracted frompack-*.pack
pattern.- Returns:
- name extracted from
pack-*.pack
pattern.
-
hasObject
Determine if an object is contained within the pack file.For performance reasons only the index file is searched; the main pack content is ignored entirely.
- Parameters:
id
- the object to look for. Must not be null.- Returns:
- true if the object is in this pack; false otherwise.
- Throws:
IOException
- the index file cannot be loaded into memory.
-
shouldBeKept
public boolean shouldBeKept()Determines whether a .keep file exists for this pack file.- Returns:
- true if a .keep file exist.
-
get
Get an object from this pack.- Parameters:
curs
- 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.
-
resolve
- Throws:
IOException
-
close
public void close()Close the resources utilized by this repository -
iterator
Provide iterator over entries in associated pack index, that should also exist in this pack file. Objects returned by such iterator are mutable during iteration.
Iterator returns objects in SHA-1 lexicographical order.
- Specified by:
iterator
in interfaceIterable<PackIndex.MutableEntry>
- See Also:
-
getObjectCount
Obtain the total number of objects available in this pack. This method relies on pack index, giving number of effectively available objects.- Returns:
- number of objects in index of this pack, likewise in this pack
- Throws:
IOException
- the index file cannot be loaded into memory.
-
findObjectForOffset
Search for object id with the specified start offset in associated pack (reverse) index.- Parameters:
offset
- start offset of object to find- Returns:
- object id for this offset, or null if no object was found
- Throws:
IOException
- the index file cannot be loaded into memory.
-
getFileSnapshot
PackFileSnapshot getFileSnapshot()Return the @FileSnapshot
associated to the underlying packfile that has been used when the object was created.- Returns:
- the packfile @
FileSnapshot
that the object is loaded from.
-
getPackChecksum
AnyObjectId getPackChecksum() -
decompress
private final byte[] decompress(long position, int sz, WindowCursor curs) throws IOException, DataFormatException - Throws:
IOException
DataFormatException
-
copyPackAsIs
- Throws:
IOException
-
copyAsIs
final void copyAsIs(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws IOException, StoredObjectRepresentationNotAvailableException -
copyAsIs2
private void copyAsIs2(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws IOException, StoredObjectRepresentationNotAvailableException -
invalid
boolean invalid() -
setInvalid
void setInvalid() -
incrementTransientErrorCount
int incrementTransientErrorCount() -
resetTransientErrorCount
void resetTransientErrorCount() -
readFully
private void readFully(long position, byte[] dstbuf, int dstoff, int cnt, WindowCursor curs) throws IOException - Throws:
IOException
-
beginCopyAsIs
-
endCopyAsIs
private void endCopyAsIs() -
beginWindowCache
- Throws:
IOException
-
endWindowCache
boolean endWindowCache() -
doOpen
- Throws:
IOException
-
openFail
-
doClose
private void doClose() -
read
- Throws:
IOException
-
mmap
- Throws:
IOException
-
onOpenPack
- Throws:
IOException
-
load
- Throws:
IOException
LargeObjectException
-
findDeltaBase
- Throws:
IOException
MissingObjectException
-
getDeltaHeader
- Throws:
IOException
DataFormatException
-
getObjectType
- Throws:
IOException
-
getObjectSize
- Throws:
IOException
-
getObjectSize
- Throws:
IOException
-
representation
LocalObjectRepresentation representation(WindowCursor curs, AnyObjectId objectId) throws IOException - Throws:
IOException
-
findEndOffset
- Throws:
IOException
CorruptObjectException
-
getBitmapIndex
- Throws:
IOException
-
getReverseIdx
- Throws:
IOException
-
isCorrupt
private boolean isCorrupt(long offset) -
setCorrupt
private void setCorrupt(long offset) -
toString
-