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 class
Pack.Delta
-
Field Summary
Fields Modifier and Type Field Description private int
activeCopyRawData
private int
activeWindows
private PackBitmapIndex
bitmapIdx
private PackFile
bitmapIdxFile
private LongList
corruptObjects
Objects we have tried to read, and discovered to be corrupt.private java.io.RandomAccessFile
fd
private PackFileSnapshot
fileSnapshot
(package private) int
hash
private boolean
invalid
private java.lang.Exception
invalidatingCause
private PackFile
keepFile
(package private) long
length
private PackIndex
loadedIdx
private static org.slf4j.Logger
LOG
private byte[]
packChecksum
private PackFile
packFile
(package private) java.time.Instant
packLastModified
private java.lang.Object
readLock
Serializes reads performed againstfd
.private PackReverseIndex
reverseIdx
static java.util.Comparator<Pack>
SORT
Sorts PackFiles to be most recently created to least recently created.private java.util.concurrent.atomic.AtomicInteger
transientErrorCount
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
beginCopyAsIs(ObjectToPack otp)
(package private) boolean
beginWindowCache()
void
close()
Close the resources utilized by this repository(package private) 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 byte[]
decompress(long position, int sz, WindowCursor curs)
private void
doClose()
private void
doOpen()
private void
endCopyAsIs()
(package private) boolean
endWindowCache()
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
getBitmapIndex()
(package private) byte[]
getDeltaHeader(WindowCursor wc, long pos)
(package private) PackFileSnapshot
getFileSnapshot()
Return the @FileSnapshot
associated to the underlying packfile that has been used when the object was created.PackIndex
getIndex()
Get the index for this pack file.(package private) long
getObjectCount()
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
getPackChecksum()
PackFile
getPackFile()
Get the File object which locates this pack on disk.java.lang.String
getPackName()
Get name extracted frompack-*.pack
pattern.private PackReverseIndex
getReverseIdx()
boolean
hasObject(AnyObjectId id)
Determine if an object is contained within the pack file.private PackIndex
idx()
(package private) int
incrementTransientErrorCount()
(package private) boolean
invalid()
private boolean
isCorrupt(long offset)
java.util.Iterator<PackIndex.MutableEntry>
iterator()
(package private) ObjectLoader
load(WindowCursor curs, long pos)
(package private) ByteWindow
mmap(long pos, int size)
private void
onOpenPack()
private void
openFail(boolean invalidate, java.lang.Exception cause)
(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
resetTransientErrorCount()
(package private) void
resolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit)
private void
setCorrupt(long offset)
(package private) void
setInvalid()
boolean
shouldBeKept()
Determines whether a .keep file exists for this pack file.java.lang.String
toString()
-
-
-
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-*.pack
pattern.- Returns:
- name extracted from
pack-*.pack
pattern.
-
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:
iterator
in interfacejava.lang.Iterable<PackIndex.MutableEntry>
- See Also:
PackIndex.iterator()
-
getObjectCount
long getObjectCount() 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.- 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 @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 java.io.IOException, java.util.zip.DataFormatException
- Throws:
java.io.IOException
java.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.IOException
StoredObjectRepresentationNotAvailableException
-
copyAsIs2
private void copyAsIs2(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws java.io.IOException, StoredObjectRepresentationNotAvailableException
- Throws:
java.io.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 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.IOException
LargeObjectException
-
findDeltaBase
private long findDeltaBase(ObjectId baseId) throws java.io.IOException, MissingObjectException
- Throws:
java.io.IOException
MissingObjectException
-
getDeltaHeader
byte[] getDeltaHeader(WindowCursor wc, long pos) throws java.io.IOException, java.util.zip.DataFormatException
- Throws:
java.io.IOException
java.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.IOException
CorruptObjectException
-
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:
toString
in classjava.lang.Object
-
-