Class Pack
- java.lang.Object
-
- org.eclipse.jgit.internal.storage.file.Pack
-
- All Implemented Interfaces:
java.lang.Iterable<PackIndex.MutableEntry>
public class Pack extends java.lang.Object implements java.lang.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 Modifier and Type Class Description private static classPack.Delta
-
Field Summary
Fields Modifier and Type Field Description private intactiveCopyRawDataprivate intactiveWindowsprivate PackBitmapIndexbitmapIdxprivate PackFilebitmapIdxFileprivate LongListcorruptObjectsObjects we have tried to read, and discovered to be corrupt.private java.io.RandomAccessFilefdprivate PackFileSnapshotfileSnapshot(package private) inthashprivate booleaninvalidprivate java.lang.ExceptioninvalidatingCauseprivate PackFilekeepFile(package private) longlengthprivate PackIndexloadedIdxprivate static org.slf4j.LoggerLOGprivate byte[]packChecksumprivate PackFilepackFile(package private) java.time.InstantpackLastModifiedprivate java.lang.ObjectreadLockSerializes reads performed againstfd.private PackReverseIndexreverseIdxstatic java.util.Comparator<Pack>SORTSorts PackFiles to be most recently created to least recently created.private java.util.concurrent.atomic.AtomicIntegertransientErrorCount
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbeginCopyAsIs(ObjectToPack otp)(package private) booleanbeginWindowCache()voidclose()Close the resources utilized by this repository(package private) voidcopyAsIs(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs)private voidcopyAsIs2(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs)(package private) voidcopyPackAsIs(PackOutputStream out, WindowCursor curs)private byte[]decompress(long position, int sz, WindowCursor curs)private voiddoClose()private voiddoOpen()private voidendCopyAsIs()(package private) booleanendWindowCache()private longfindDeltaBase(ObjectId baseId)private longfindEndOffset(long startOffset)(package private) ObjectIdfindObjectForOffset(long offset)Search for object id with the specified start offset in associated pack (reverse) index.(package private) ObjectLoaderget(WindowCursor curs, AnyObjectId id)Get an object from this pack.(package private) PackBitmapIndexgetBitmapIndex()(package private) byte[]getDeltaHeader(WindowCursor wc, long pos)(package private) PackFileSnapshotgetFileSnapshot()Return the @FileSnapshotassociated to the underlying packfile that has been used when the object was created.PackIndexgetIndex()Get the index for this pack file.(package private) longgetObjectCount()Obtain the total number of objects available in this pack.(package private) longgetObjectSize(WindowCursor curs, long pos)(package private) longgetObjectSize(WindowCursor curs, AnyObjectId id)(package private) intgetObjectType(WindowCursor curs, long pos)(package private) AnyObjectIdgetPackChecksum()PackFilegetPackFile()Get the File object which locates this pack on disk.java.lang.StringgetPackName()Get name extracted frompack-*.packpattern.private PackReverseIndexgetReverseIdx()booleanhasObject(AnyObjectId id)Determine if an object is contained within the pack file.private PackIndexidx()(package private) intincrementTransientErrorCount()(package private) booleaninvalid()private booleanisCorrupt(long offset)java.util.Iterator<PackIndex.MutableEntry>iterator()(package private) ObjectLoaderload(WindowCursor curs, long pos)(package private) ByteWindowmmap(long pos, int size)private voidonOpenPack()private voidopenFail(boolean invalidate, java.lang.Exception cause)(package private) ByteArrayWindowread(long pos, int size)private voidreadFully(long position, byte[] dstbuf, int dstoff, int cnt, WindowCursor curs)(package private) LocalObjectRepresentationrepresentation(WindowCursor curs, AnyObjectId objectId)(package private) voidresetTransientErrorCount()(package private) voidresolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit)private voidsetCorrupt(long offset)(package private) voidsetInvalid()booleanshouldBeKept()Determines whether a .keep file exists for this pack file.java.lang.StringtoString()
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
SORT
public static final java.util.Comparator<Pack> SORT
Sorts PackFiles to be most recently created to least recently created.
-
packFile
private final PackFile packFile
-
keepFile
private PackFile keepFile
-
hash
final int hash
-
fd
private java.io.RandomAccessFile fd
-
readLock
private final java.lang.Object readLock
Serializes reads performed againstfd.
-
length
long length
-
activeWindows
private int activeWindows
-
activeCopyRawData
private int activeCopyRawData
-
packLastModified
java.time.Instant packLastModified
-
fileSnapshot
private PackFileSnapshot fileSnapshot
-
invalid
private volatile boolean invalid
-
invalidatingCause
private volatile java.lang.Exception invalidatingCause
-
transientErrorCount
private java.util.concurrent.atomic.AtomicInteger transientErrorCount
-
packChecksum
private byte[] packChecksum
-
loadedIdx
private volatile PackIndex loadedIdx
-
reverseIdx
private PackReverseIndex reverseIdx
-
bitmapIdx
private PackBitmapIndex bitmapIdx
-
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.
-
-
Method Detail
-
idx
private PackIndex idx() throws java.io.IOException
- Throws:
java.io.IOException
-
getPackFile
public PackFile getPackFile()
Get the File object which locates this pack on disk.- Returns:
- the File object which locates this pack on disk.
-
getIndex
public PackIndex getIndex() throws java.io.IOException
Get the index for this pack file.- Returns:
- the index for this pack file.
- Throws:
java.io.IOException
-
getPackName
public java.lang.String getPackName()
Get name extracted frompack-*.packpattern.- Returns:
- name extracted from
pack-*.packpattern.
-
hasObject
public boolean hasObject(AnyObjectId id) throws java.io.IOException
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:
java.io.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
ObjectLoader get(WindowCursor curs, AnyObjectId id) throws java.io.IOException
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:
java.io.IOException- the pack file or the index could not be read.
-
resolve
void resolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit) throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close()
Close the resources utilized by this repository
-
iterator
public java.util.Iterator<PackIndex.MutableEntry> 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:
iteratorin interfacejava.lang.Iterable<PackIndex.MutableEntry>- See Also:
PackIndex.iterator()
-
getObjectCount
long getObjectCount() throws java.io.IOExceptionObtain 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:
java.io.IOException- the index file cannot be loaded into memory.
-
findObjectForOffset
ObjectId findObjectForOffset(long offset) throws java.io.IOException
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:
java.io.IOException- the index file cannot be loaded into memory.
-
getFileSnapshot
PackFileSnapshot getFileSnapshot()
Return the @FileSnapshotassociated to the underlying packfile that has been used when the object was created.- Returns:
- the packfile @
FileSnapshotthat the object is loaded from.
-
getPackChecksum
AnyObjectId getPackChecksum()
-
decompress
private final byte[] decompress(long position, int sz, WindowCursor curs) throws java.io.IOException, java.util.zip.DataFormatException- Throws:
java.io.IOExceptionjava.util.zip.DataFormatException
-
copyPackAsIs
void copyPackAsIs(PackOutputStream out, WindowCursor curs) throws java.io.IOException
- Throws:
java.io.IOException
-
copyAsIs
final void copyAsIs(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws java.io.IOException, StoredObjectRepresentationNotAvailableException
- Throws:
java.io.IOExceptionStoredObjectRepresentationNotAvailableException
-
copyAsIs2
private void copyAsIs2(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws java.io.IOException, StoredObjectRepresentationNotAvailableException
- Throws:
java.io.IOExceptionStoredObjectRepresentationNotAvailableException
-
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 java.io.IOException- Throws:
java.io.IOException
-
beginCopyAsIs
private void beginCopyAsIs(ObjectToPack otp) throws StoredObjectRepresentationNotAvailableException
-
endCopyAsIs
private void endCopyAsIs()
-
beginWindowCache
boolean beginWindowCache() throws java.io.IOException- Throws:
java.io.IOException
-
endWindowCache
boolean endWindowCache()
-
doOpen
private void doOpen() throws java.io.IOException- Throws:
java.io.IOException
-
openFail
private void openFail(boolean invalidate, java.lang.Exception cause)
-
doClose
private void doClose()
-
read
ByteArrayWindow read(long pos, int size) throws java.io.IOException
- Throws:
java.io.IOException
-
mmap
ByteWindow mmap(long pos, int size) throws java.io.IOException
- Throws:
java.io.IOException
-
onOpenPack
private void onOpenPack() throws java.io.IOException- Throws:
java.io.IOException
-
load
ObjectLoader load(WindowCursor curs, long pos) throws java.io.IOException, LargeObjectException
- Throws:
java.io.IOExceptionLargeObjectException
-
findDeltaBase
private long findDeltaBase(ObjectId baseId) throws java.io.IOException, MissingObjectException
- Throws:
java.io.IOExceptionMissingObjectException
-
getDeltaHeader
byte[] getDeltaHeader(WindowCursor wc, long pos) throws java.io.IOException, java.util.zip.DataFormatException
- Throws:
java.io.IOExceptionjava.util.zip.DataFormatException
-
getObjectType
int getObjectType(WindowCursor curs, long pos) throws java.io.IOException
- Throws:
java.io.IOException
-
getObjectSize
long getObjectSize(WindowCursor curs, AnyObjectId id) throws java.io.IOException
- Throws:
java.io.IOException
-
getObjectSize
long getObjectSize(WindowCursor curs, long pos) throws java.io.IOException
- Throws:
java.io.IOException
-
representation
LocalObjectRepresentation representation(WindowCursor curs, AnyObjectId objectId) throws java.io.IOException
- Throws:
java.io.IOException
-
findEndOffset
private long findEndOffset(long startOffset) throws java.io.IOException, CorruptObjectException- Throws:
java.io.IOExceptionCorruptObjectException
-
getBitmapIndex
PackBitmapIndex getBitmapIndex() throws java.io.IOException
- Throws:
java.io.IOException
-
getReverseIdx
private PackReverseIndex getReverseIdx() throws java.io.IOException
- Throws:
java.io.IOException
-
isCorrupt
private boolean isCorrupt(long offset)
-
setCorrupt
private void setCorrupt(long offset)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-