Top Description Inners Fields Constructors Methods
org.eclipse.jgit.internal.storage.file

public Class Pack

extends Object
implements Iterable<PackIndex.MutableEntry>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Static Imports
org.eclipse.jgit.internal.storage.pack.PackExt.INDEX, .PackExt.KEEP, .PackExt.REVERSE_INDEX, org.eclipse.jgit.lib.ConfigConstants.CONFIG_CORE_SECTION, .ConfigConstants.CONFIG_KEY_PACKED_INDEX_GIT_USE_STRONGREFS

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 and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private int
private final Object
activeLock

For managing open/close accounting of fd.

private int
private Optionally<PackBitmapIndex>
private volatile PackFile
private volatile LongList
corruptObjects

Objects we have tried to read, and discovered to be corrupt.

private RandomAccessFile
private PackFileSnapshot
pack-priv final int
private volatile boolean
private volatile Exception
private PackFile
pack-priv long
private Optionally<PackIndex>
private static final Logger
private byte[]
private final PackFile
pack-priv Instant
private final Object
readLock

Serializes reads performed against fd.

private Optionally<PackReverseIndex>
public static final Comparator<Pack>
SORT

Sorts PackFiles to be most recently created to least recently created.

private AtomicInteger
private boolean

Constructor Summary

AccessConstructor and Description
public
Pack(Config
configuration this directory consults for write settings.
cfg
,
File
path of the .pack file holding the data.
packFile
,
PackFile
existing bitmap index file with the same base as the pack
bitmapIdxFile
)

Construct a reader for an existing, pre-indexed packfile.

Method Summary

Modifier and TypeMethod and Description
private void
pack-priv boolean
public static void
close(Set<Pack>
packs to close
packs
)

Close the resources utilized by these pack files

public void
close()

Close the resources utilized by this pack file

private synchronized void
pack-priv final void
copyAsIs(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs)

private void
copyAsIs2(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs)

pack-priv void
private final byte[]
decompress(final long position, final int sz, final WindowCursor curs)

private void
private void
private void
pack-priv boolean
private long
private long
findEndOffset(long startOffset)

pack-priv ObjectId

Returns:

object id for this offset, or null if no object was found
findObjectForOffset
(long
start offset of object to find
offset
)

Search for object id with the specified start offset in associated pack (reverse) index.

pack-priv ObjectLoader

Returns:

the object loader for the requested object if it is contained in this pack; null if the object was not found.
get
(WindowCursor
temporary working space associated with the calling thread.
curs
,
AnyObjectId
the object to obtain from the pack. Must not be null.
id
)

Get an object from this pack.

pack-priv synchronized PackBitmapIndex
pack-priv byte[]
pack-priv PackFileSnapshot

Returns:

the packfile @FileSnapshot that the object is loaded from.
getFileSnapshot
()

Return the @FileSnapshot associated to the underlying packfile that has been used when the object was created.

public PackIndex

Returns:

the index for this pack file.
getIndex
()

Get the index for this pack file.

pack-priv long

Returns:

number of objects in index of this pack, likewise in this pack
getObjectCount
()

Obtain the total number of objects available in this pack.

pack-priv long
pack-priv long
getObjectSize(WindowCursor curs, long pos)

pack-priv int
getObjectType(WindowCursor curs, long pos)

pack-priv AnyObjectId
public PackFile

Returns:

the File object which locates this pack on disk.
getPackFile
()

Get the File object which locates this pack on disk.

public String

Returns:

name extracted from pack-*.pack pattern.
getPackName
()

Get name extracted from pack-*.pack pattern.

private synchronized PackReverseIndex
public boolean

Returns:

true if the object is in this pack; false otherwise.
hasObject
(AnyObjectId
the object to look for. Must not be null.
id
)

Determine if an object is contained within the pack file.

private synchronized PackIndex
idx()

pack-priv int
pack-priv boolean
private boolean
isCorrupt(long offset)

public Iterator<PackIndex.MutableEntry>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

pack-priv ObjectLoader
load(WindowCursor curs, long pos)

pack-priv ByteWindow
mmap(long pos, int size)

private void
private void
private <T> Optionally<T>
optionally(T element)

pack-priv ByteArrayWindow
read(long pos, int size)

private void
readFully(final long position, final byte[] dstbuf, int dstoff, final int cnt, final WindowCursor curs)

pack-priv LocalObjectRepresentation
representation(final WindowCursor curs, final AnyObjectId objectId)

pack-priv void
pack-priv void
resolve(Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit)

pack-priv void
setBitmapIndexFile(PackFile bitmapIndexFile)

private void
setCorrupt(long offset)

pack-priv void
public boolean

Returns:

true if a .keep file exist.
shouldBeKept
()

Determines whether a .keep file exists for this pack file.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

activeCopyRawDataback to summary
private int activeCopyRawData
activeLockback to summary
private final Object activeLock

For managing open/close accounting of fd.

activeWindowsback to summary
private int activeWindows
bitmapIdxback to summary
private Optionally<PackBitmapIndex> bitmapIdx
bitmapIdxFileback to summary
private volatile PackFile bitmapIdxFile
Annotations
@Nullable
corruptObjectsback to summary
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.

fdback to summary
private RandomAccessFile fd
fileSnapshotback to summary
private PackFileSnapshot fileSnapshot
hashback to summary
pack-priv final int hash
invalidback to summary
private volatile boolean invalid
invalidatingCauseback to summary
private volatile Exception invalidatingCause
keepFileback to summary
private PackFile keepFile
lengthback to summary
pack-priv long length
loadedIdxback to summary
private Optionally<PackIndex> loadedIdx
LOGback to summary
private static final Logger LOG
packChecksumback to summary
private byte[] packChecksum
packFileback to summary
private final PackFile packFile
packLastModifiedback to summary
pack-priv Instant packLastModified
readLockback to summary
private final Object readLock

Serializes reads performed against fd.

reverseIdxback to summary
private Optionally<PackReverseIndex> reverseIdx
SORTback to summary
public static final Comparator<Pack> SORT

Sorts PackFiles to be most recently created to least recently created.

transientErrorCountback to summary
private AtomicInteger transientErrorCount
useStrongRefsback to summary
private boolean useStrongRefs

Constructor Detail

Packback to summary
public Pack(Config cfg, File packFile, PackFile bitmapIdxFile)

Construct a reader for an existing, pre-indexed packfile.

Parameters
cfg:Config

configuration this directory consults for write settings.

packFile:File

path of the .pack file holding the data.

bitmapIdxFile:PackFile

existing bitmap index file with the same base as the pack

Method Detail

beginCopyAsIsback to summary
private void beginCopyAsIs() throws StoredObjectRepresentationNotAvailableException
beginWindowCacheback to summary
pack-priv boolean beginWindowCache() throws IOException
closeback to summary
public static void close(Set<Pack> packs)

Close the resources utilized by these pack files

Parameters
packs:Set<Pack>

packs to close

closeback to summary
public void close()

Close the resources utilized by this pack file

closeIndicesback to summary
private synchronized void closeIndices()
copyAsIsback to summary
pack-priv final void copyAsIs(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws IOException, StoredObjectRepresentationNotAvailableException
copyAsIs2back to summary
private void copyAsIs2(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws IOException, StoredObjectRepresentationNotAvailableException
copyPackAsIsback to summary
pack-priv void copyPackAsIs(PackOutputStream out, WindowCursor curs) throws IOException
decompressback to summary
private final byte[] decompress(final long position, final int sz, final WindowCursor curs) throws IOException, DataFormatException
doCloseback to summary
private void doClose()
doOpenback to summary
private void doOpen() throws IOException
endCopyAsIsback to summary
private void endCopyAsIs()
endWindowCacheback to summary
pack-priv boolean endWindowCache()
findDeltaBaseback to summary
private long findDeltaBase(ObjectId baseId) throws IOException, MissingObjectException
findEndOffsetback to summary
private long findEndOffset(long startOffset) throws IOException, CorruptObjectException
findObjectForOffsetback to summary
pack-priv ObjectId findObjectForOffset(long offset) throws IOException

Search for object id with the specified start offset in associated pack (reverse) index.

Parameters
offset:long

start offset of object to find

Returns:ObjectId

object id for this offset, or null if no object was found

Exceptions
IOException:
the index file cannot be loaded into memory.
getback to summary
pack-priv ObjectLoader get(WindowCursor curs, AnyObjectId id) throws IOException

Get an object from this pack.

Parameters
curs:WindowCursor

temporary working space associated with the calling thread.

id:AnyObjectId

the object to obtain from the pack. Must not be null.

Returns:ObjectLoader

the object loader for the requested object if it is contained in this pack; null if the object was not found.

Exceptions
IOException:
the pack file or the index could not be read.
getBitmapIndexback to summary
pack-priv synchronized PackBitmapIndex getBitmapIndex() throws IOException
getDeltaHeaderback to summary
pack-priv byte[] getDeltaHeader(WindowCursor wc, long pos) throws IOException, DataFormatException
getFileSnapshotback to summary
pack-priv PackFileSnapshot getFileSnapshot()

Return the @FileSnapshot associated to the underlying packfile that has been used when the object was created.

Returns:PackFileSnapshot

the packfile @FileSnapshot that the object is loaded from.

getIndexback to summary
public PackIndex getIndex() throws IOException

Get the index for this pack file.

Returns:PackIndex

the index for this pack file.

Exceptions
IOException:
if an IO error occurred
getObjectCountback to summary
pack-priv long getObjectCount() throws IOException

Obtain the total number of objects available in this pack. This method relies on pack index, giving number of effectively available objects.

Returns:long

number of objects in index of this pack, likewise in this pack

Exceptions
IOException:
the index file cannot be loaded into memory.
getObjectSizeback to summary
pack-priv long getObjectSize(WindowCursor curs, AnyObjectId id) throws IOException
getObjectSizeback to summary
pack-priv long getObjectSize(WindowCursor curs, long pos) throws IOException
getObjectTypeback to summary
pack-priv int getObjectType(WindowCursor curs, long pos) throws IOException
getPackChecksumback to summary
pack-priv AnyObjectId getPackChecksum()
getPackFileback to summary
public PackFile getPackFile()

Get the File object which locates this pack on disk.

Returns:PackFile

the File object which locates this pack on disk.

getPackNameback to summary
public String getPackName()

Get name extracted from pack-*.pack pattern.

Returns:String

name extracted from pack-*.pack pattern.

getReverseIdxback to summary
private synchronized PackReverseIndex getReverseIdx() throws IOException
hasObjectback to summary
public boolean hasObject(AnyObjectId id) throws 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:AnyObjectId

the object to look for. Must not be null.

Returns:boolean

true if the object is in this pack; false otherwise.

Exceptions
IOException:
the index file cannot be loaded into memory.
idxback to summary
private synchronized PackIndex idx() throws IOException
incrementTransientErrorCountback to summary
pack-priv int incrementTransientErrorCount()
invalidback to summary
pack-priv boolean invalid()
isCorruptback to summary
private boolean isCorrupt(long offset)
iteratorback to summary
public Iterator<PackIndex.MutableEntry> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

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.

Returns:Iterator<PackIndex.MutableEntry>

an Iterator.

Annotations
@Override
See Also
PackIndex#iterator()
loadback to summary
pack-priv ObjectLoader load(WindowCursor curs, long pos) throws IOException, LargeObjectException
mmapback to summary
pack-priv ByteWindow mmap(long pos, int size) throws IOException
onOpenPackback to summary
private void onOpenPack() throws IOException
openFailback to summary
private void openFail(Exception cause)
optionallyback to summary
private <T> Optionally<T> optionally(T element)
readback to summary
pack-priv ByteArrayWindow read(long pos, int size) throws IOException
readFullyback to summary
private void readFully(final long position, final byte[] dstbuf, int dstoff, final int cnt, final WindowCursor curs) throws IOException
representationback to summary
pack-priv LocalObjectRepresentation representation(final WindowCursor curs, final AnyObjectId objectId) throws IOException
resetTransientErrorCountback to summary
pack-priv void resetTransientErrorCount()
resolveback to summary
pack-priv void resolve(Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit) throws IOException
setBitmapIndexFileback to summary
pack-priv void setBitmapIndexFile(PackFile bitmapIndexFile)
setCorruptback to summary
private void setCorrupt(long offset)
setInvalidback to summary
pack-priv void setInvalid()
shouldBeKeptback to summary
public boolean shouldBeKept()

Determines whether a .keep file exists for this pack file.

Returns:boolean

true if a .keep file exist.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@SuppressWarnings:nls
@Override
org.eclipse.jgit.internal.storage.file back to summary

private Class Pack.Delta

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final long
basePos

Offset of the base object this delta applies onto.

pack-priv final long
deltaPos

Offset of the delta object.

pack-priv final int
deltaSize

Size of the inflated delta stream.

pack-priv final int
hdrLen

Total size of the delta's pack entry header (including base).

pack-priv final Pack.Delta
next

Child that applies onto this object.

Constructor Summary

AccessConstructor and Description
pack-priv
Delta(Pack.Delta next, long ofs, int sz, int hdrLen, long baseOffset)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

basePosback to summary
pack-priv final long basePos

Offset of the base object this delta applies onto.

deltaPosback to summary
pack-priv final long deltaPos

Offset of the delta object.

deltaSizeback to summary
pack-priv final int deltaSize

Size of the inflated delta stream.

hdrLenback to summary
pack-priv final int hdrLen

Total size of the delta's pack entry header (including base).

nextback to summary
pack-priv final Pack.Delta next

Child that applies onto this object.

Constructor Detail

Deltaback to summary
pack-priv Delta(Pack.Delta next, long ofs, int sz, int hdrLen, long baseOffset)