public class PackFile extends java.lang.Object implements java.lang.Iterable<PackIndex.MutableEntry>
Modifier and Type | Class and Description |
---|---|
private static class |
PackFile.Delta |
Modifier and Type | Field and Description |
---|---|
private int |
activeCopyRawData |
private int |
activeWindows |
private PackBitmapIndex |
bitmapIdx |
private LongList |
corruptObjects
Objects we have tried to read, and discovered to be corrupt.
|
private int |
extensions |
private java.io.RandomAccessFile |
fd |
private PackFileSnapshot |
fileSnapshot |
(package private) int |
hash |
private boolean |
invalid |
private java.lang.Exception |
invalidatingCause |
private boolean |
invalidBitmap |
private java.io.File |
keepFile |
(package private) long |
length |
private PackIndex |
loadedIdx |
private static org.slf4j.Logger |
LOG |
private byte[] |
packChecksum |
private java.io.File |
packFile |
(package private) int |
packLastModified |
private java.lang.String |
packName |
private java.lang.Object |
readLock
Serializes reads performed against
fd . |
private PackReverseIndex |
reverseIdx |
static java.util.Comparator<PackFile> |
SORT
Sorts PackFiles to be most recently created to least recently created.
|
private java.util.concurrent.atomic.AtomicInteger |
transientErrorCount |
Constructor and Description |
---|
PackFile(java.io.File packFile,
int extensions)
Construct a reader for an existing, pre-indexed packfile.
|
Modifier and Type | Method and 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 java.io.File |
extFile(PackExt ext) |
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,
AnyObjectId id) |
(package private) long |
getObjectSize(WindowCursor curs,
long pos) |
(package private) int |
getObjectType(WindowCursor curs,
long pos) |
(package private) AnyObjectId |
getPackChecksum() |
java.io.File |
getPackFile()
Get the File object which locates this pack on disk.
|
java.lang.String |
getPackName()
Get name extracted from
pack-*.pack pattern. |
private PackReverseIndex |
getReverseIdx() |
private boolean |
hasExt(PackExt ext) |
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() |
private static final org.slf4j.Logger LOG
public static final java.util.Comparator<PackFile> SORT
private final java.io.File packFile
private final int extensions
private java.io.File keepFile
private volatile java.lang.String packName
final int hash
private java.io.RandomAccessFile fd
private final java.lang.Object readLock
fd
.long length
private int activeWindows
private int activeCopyRawData
int packLastModified
private PackFileSnapshot fileSnapshot
private volatile boolean invalid
private volatile java.lang.Exception invalidatingCause
private boolean invalidBitmap
private java.util.concurrent.atomic.AtomicInteger transientErrorCount
private byte[] packChecksum
private volatile PackIndex loadedIdx
private PackReverseIndex reverseIdx
private PackBitmapIndex bitmapIdx
private volatile LongList corruptObjects
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.
public PackFile(java.io.File packFile, int extensions)
packFile
- path of the .pack
file holding the data.extensions
- additional pack file extensions with the same base as the packprivate PackIndex idx() throws java.io.IOException
java.io.IOException
public java.io.File getPackFile()
public PackIndex getIndex() throws java.io.IOException
java.io.IOException
public java.lang.String getPackName()
pack-*.pack
pattern.pack-*.pack
pattern.public boolean hasObject(AnyObjectId id) throws java.io.IOException
For performance reasons only the index file is searched; the main pack content is ignored entirely.
id
- the object to look for. Must not be null.java.io.IOException
- the index file cannot be loaded into memory.public boolean shouldBeKept()
ObjectLoader get(WindowCursor curs, AnyObjectId id) throws java.io.IOException
curs
- temporary working space associated with the calling thread.id
- the object to obtain from the pack. Must not be null.java.io.IOException
- the pack file or the index could not be read.void resolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit) throws java.io.IOException
java.io.IOException
public void close()
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.
iterator
in interface java.lang.Iterable<PackIndex.MutableEntry>
PackIndex.iterator()
long getObjectCount() throws java.io.IOException
java.io.IOException
- the index file cannot be loaded into memory.ObjectId findObjectForOffset(long offset) throws java.io.IOException
offset
- start offset of object to findjava.io.IOException
- the index file cannot be loaded into memory.PackFileSnapshot getFileSnapshot()
FileSnapshot
associated to the underlying packfile
that has been used when the object was created.FileSnapshot
that the object is loaded from.AnyObjectId getPackChecksum()
private final byte[] decompress(long position, int sz, WindowCursor curs) throws java.io.IOException, java.util.zip.DataFormatException
java.io.IOException
java.util.zip.DataFormatException
void copyPackAsIs(PackOutputStream out, WindowCursor curs) throws java.io.IOException
java.io.IOException
final void copyAsIs(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws java.io.IOException, StoredObjectRepresentationNotAvailableException
java.io.IOException
StoredObjectRepresentationNotAvailableException
private void copyAsIs2(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws java.io.IOException, StoredObjectRepresentationNotAvailableException
java.io.IOException
StoredObjectRepresentationNotAvailableException
boolean invalid()
void setInvalid()
int incrementTransientErrorCount()
void resetTransientErrorCount()
private void readFully(long position, byte[] dstbuf, int dstoff, int cnt, WindowCursor curs) throws java.io.IOException
java.io.IOException
private void beginCopyAsIs(ObjectToPack otp) throws StoredObjectRepresentationNotAvailableException
private void endCopyAsIs()
boolean beginWindowCache() throws java.io.IOException
java.io.IOException
boolean endWindowCache()
private void doOpen() throws java.io.IOException
java.io.IOException
private void openFail(boolean invalidate, java.lang.Exception cause)
private void doClose()
ByteArrayWindow read(long pos, int size) throws java.io.IOException
java.io.IOException
ByteWindow mmap(long pos, int size) throws java.io.IOException
java.io.IOException
private void onOpenPack() throws java.io.IOException
java.io.IOException
ObjectLoader load(WindowCursor curs, long pos) throws java.io.IOException, LargeObjectException
java.io.IOException
LargeObjectException
private long findDeltaBase(ObjectId baseId) throws java.io.IOException, MissingObjectException
java.io.IOException
MissingObjectException
byte[] getDeltaHeader(WindowCursor wc, long pos) throws java.io.IOException, java.util.zip.DataFormatException
java.io.IOException
java.util.zip.DataFormatException
int getObjectType(WindowCursor curs, long pos) throws java.io.IOException
java.io.IOException
long getObjectSize(WindowCursor curs, AnyObjectId id) throws java.io.IOException
java.io.IOException
long getObjectSize(WindowCursor curs, long pos) throws java.io.IOException
java.io.IOException
LocalObjectRepresentation representation(WindowCursor curs, AnyObjectId objectId) throws java.io.IOException
java.io.IOException
private long findEndOffset(long startOffset) throws java.io.IOException, CorruptObjectException
java.io.IOException
CorruptObjectException
PackBitmapIndex getBitmapIndex() throws java.io.IOException
java.io.IOException
private PackReverseIndex getReverseIdx() throws java.io.IOException
java.io.IOException
private boolean isCorrupt(long offset)
private void setCorrupt(long offset)
private java.io.File extFile(PackExt ext)
private boolean hasExt(PackExt ext)
public java.lang.String toString()
toString
in class java.lang.Object