Top Description Inners Fields Constructors Methods
org.eclipse.jgit.transport

public abstract Class PackParser

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.internal.fsck.FsckPackParser, org.eclipse.jgit.internal.storage.dfs.DfsPackParser, org.eclipse.jgit.internal.storage.file.ObjectDirectoryPackParser
Imports
java.io.EOFException, .IOException, .InputStream, java.security.MessageDigest, java.text.MessageFormat, java.util.ArrayList, .Arrays, .Comparator, .List, java.util.concurrent.TimeUnit, java.util.zip.DataFormatException, .Inflater, org.eclipse.jgit.errors.CorruptObjectException, .MissingObjectException, .TooLargeObjectInPackException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.internal.storage.pack.BinaryDelta, org.eclipse.jgit.lib.AnyObjectId, .BatchingProgressMonitor, .BlobObjectChecker, .Constants, .InflaterCache, .MutableObjectId, .NullProgressMonitor, .ObjectChecker, .ObjectDatabase, .ObjectId, .ObjectIdOwnerMap, .ObjectIdSubclassMap, .ObjectLoader, .ObjectReader, .ObjectStream, .ProgressMonitor, org.eclipse.jgit.util.BlockList, .IO, .LongMap, .NB, org.eclipse.jgit.util.sha1.SHA1

Parses a pack stream and imports it for an org.eclipse.jgit.lib.ObjectInserter.

Applications can acquire an instance of a parser from ObjectInserter's org.eclipse.jgit.lib.ObjectInserter#newPackParser(InputStream) method.

Implementations of org.eclipse.jgit.lib.ObjectInserter should subclass this type and provide their own logic for the various on*() event methods declared to be abstract.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private class
public static class
PackParser.ObjectTypeAndSize

Type and size information about an object in the database buffer.

public static enum
PackParser.Source

Location data is being obtained from.

public static class
PackParser.UnresolvedDelta

Information about an unresolved delta in this pack stream.

Field Summary

Modifier and TypeField and Description
private boolean
private ObjectIdOwnerMap<PackParser.DeltaChain>
private LongMap<PackParser.UnresolvedDelta>
private ObjectIdSubclassMap<ObjectId>
baseObjectIds

Objects referenced by their name from deltas, that aren't in this pack.

pack-priv int
private long
bBase

Position in the input stream of buf[0].

private int
pack-priv byte[]
private static final int
BUFFER_SIZE

Size of the internal stream buffer.

private boolean
private boolean
private BlockList<PackedObjectInfo>
collisionCheckObjs

Objects need to be double-checked for collision after indexing.

private int
private PackedObjectInfo[]
private int
private boolean
private long
private byte[]
private InputStream
private PackParser.InflaterStream
private String
lockMessage

Message to protect the pack data from garbage collection.

private long
maxObjectSizeLimit

Git object size limit

private boolean
private ObjectIdSubclassMap<ObjectId>
newObjectIds

Every object contained within the incoming pack.

private ObjectChecker
private final ObjectDatabase
objectDatabase

Object database used for loading existing objects.

private final SHA1
private MessageDigest
private ObjectReader
private final ReceivedPackStatistics.Builder
private byte[]
private final MutableObjectId

Constructor Summary

AccessConstructor and Description
protected
PackParser(ObjectDatabase
database the parser will write its objects into.
odb
,
InputStream
the stream the parser will read.
src
)

Initialize a pack parser.

Method Summary

Modifier and TypeMethod and Description
private void
protected byte[]

Returns:

a temporary byte array for use by the caller.
buffer
()

Get a temporary byte array for use by the caller.

protected abstract boolean

Returns:

true if the CRC matches; false if it does not.
checkCRC
(int
the prior CRC that was recorded during the first scan of the object from the pack stream.
oldCRC
)

Check the current CRC matches the expected value.

private final void
checkIfTooLarge(int typeCode, long size)

private void
private void
private void
checkObjectCollision(AnyObjectId obj, int type, byte[] data, long sizeBeforeInflating)

private void
pack-priv int
fill(PackParser.Source src, int need)

private PackParser.UnresolvedDelta
public ObjectIdSubclassMap<ObjectId>

Returns:

set of objects the incoming pack assumed for delta purposes
getBaseObjectIds
()

Get set of objects the incoming pack assumed for delta purposes

public String

Returns:

the message to record with the pack lock.
getLockMessage
()

Get the message to record with the pack lock.

public ObjectIdSubclassMap<ObjectId>

Returns:

the new objects that were sent by the user
getNewObjectIds
()

Get the new objects that were sent by the user

public PackedObjectInfo

Returns:

the object information.
getObject
(int
index of the object in the stream. Must be between 0 and getObjectCount()-1.
nth
)

Get the information about the requested object.

public int

Returns:

number of objects parsed out of the stream.
getObjectCount
()

Get the number of objects in the stream.

public long

Returns:

the pack size (including the index size) or -1 if the size cannot be determined
getPackSize
()

Get the size of the newly created pack.

public ReceivedPackStatistics
getReceivedPackStatistics()

Returns the statistics of the parsed pack.

public List<PackedObjectInfo>

Returns:

sorted list of objects in this pack stream.
getSortedObjectList
(Comparator<PackedObjectInfo>
comparison function, if null objects are stored by ObjectId.
cmp
)

Get all of the objects, sorted by their name.

private void
growEntries(int extraObjects)

private void
private InputStream
inflate(PackParser.Source src, long inflatedSize)

private byte[]
inflateAndReturn(PackParser.Source src, long inflatedSize)

private void
inflateAndSkip(PackParser.Source src, long inflatedSize)

public boolean

Returns:

true if a thin pack (missing base objects) is permitted.
isAllowThin
()

Whether a thin pack (missing base objects) is permitted.

public boolean

Returns:

true if the EOF should be read from the input after the footer.
isCheckEofAfterPackFooter
()

Whether the EOF should be read from the input after the footer.

protected boolean

Returns:

if true received objects are verified to prevent collisions.
isCheckObjectCollisions
()

Whether received objects are verified to prevent collisions.

public boolean

Returns:

true if there is data expected after the pack footer.
isExpectDataAfterPackFooter
()

Whether there is data expected after the pack footer.

private boolean
protected PackedObjectInfo

Returns:

info object containing this object's data.
newInfo
(AnyObjectId
identity of the object to be tracked.
id
,
PackParser.UnresolvedDelta
if the object was previously an unresolved delta, this is the delta object that was tracking it. Otherwise null.
delta
,
ObjectId
if the object was previously an unresolved delta, this is the ObjectId of the base of the delta. The base may be outside of the pack stream if the stream was a thin-pack.
deltaBase
)

Construct a PackedObjectInfo instance for this parser.

protected abstract boolean

Returns:

true if the info should be included in the object list returned by getSortedObjectList(Comparator), false if it should not be included.
onAppendBase
(int
type of the base object.
typeCode
,
byte[]
complete content of the base object.
data
,
PackedObjectInfo
packed object information for this base. Implementors must populate the CRC and offset members if returning true.
info
)

Provide the implementation with a base that was outside of the pack.

protected abstract void
onBeginOfsDelta(long
position of this object in the incoming stream.
deltaStreamPosition
,
long
position of the base object in the incoming stream. The base must be before the delta, therefore baseStreamPosition < deltaStreamPosition. This is not the position returned by a prior end object event.
baseStreamPosition
,
long
size of the delta when fully inflated. The size stored within the pack may be larger or smaller, and is not yet known.
inflatedSize
)

Event notifying start of a delta referencing its base by offset.

protected abstract void
onBeginRefDelta(long
position of this object in the incoming stream.
deltaStreamPosition
,
AnyObjectId
name of the base object. This object may be later in the stream, or might not appear at all in the stream (in the case of a thin-pack).
baseId
,
long
size of the delta when fully inflated. The size stored within the pack may be larger or smaller, and is not yet known.
inflatedSize
)

Event notifying start of a delta referencing its base by ObjectId.

protected abstract void
onBeginWholeObject(long
position of this object in the incoming stream.
streamPosition
,
int type, long
size of the object when fully inflated. The size stored within the pack may be larger or smaller, and is not yet known.
inflatedSize
)

Event notifying the start of an object stored whole (not as a delta).

protected PackParser.UnresolvedDelta

Returns:

object information that must be populated with at least the offset.
onEndDelta
()

Event notifying the current object.

protected abstract void
onEndThinPack()

Event indicating a thin pack has been completely processed.

protected abstract void
onEndWholeObject(PackedObjectInfo
object information.
info
)

Event notifying the current object.

protected abstract void
onInflatedObjectData(PackedObjectInfo
the object info, populated.
obj
,
int
the type of the object.
typeCode
,
byte[]
inflated data for the object.
data
)

Invoked for commits, trees, tags, and small blobs.

protected abstract void
onObjectData(PackParser.Source
where the data came from
src
,
byte[]
buffer to read data from.
raw
,
int
first offset within buffer that is valid.
pos
,
int
number of bytes in buffer that are valid.
len
)

Store (and/or checksum) a portion of an object's data.

protected abstract void
onObjectHeader(PackParser.Source
where the data came from
src
,
byte[]
buffer to read data from.
raw
,
int
first offset within buffer that is valid.
pos
,
int
number of bytes in buffer that are valid.
len
)

Store (and/or checksum) an object header.

protected abstract void
onPackFooter(byte[]
the trailing 20 bytes of the pack, this is a SHA-1 checksum of all of the pack data.
hash
)

Provide the implementation with the original stream's pack footer.

protected abstract void
onPackHeader(long
number of objects expected in the stream.
objCnt
)

Provide the implementation with the original stream's pack header.

protected abstract void
onStoreStream(byte[]
buffer to copy data out of.
raw
,
int
first offset within the buffer that is valid.
pos
,
int
number of bytes in the buffer that are valid.
len
)

Store bytes received from the raw stream.

private PackParser.ObjectTypeAndSize
private PackParser.ObjectTypeAndSize
public final PackLock

Returns:

the pack lock, if one was requested by setting setLockMessage(String).
parse
(ProgressMonitor
callback to provide progress feedback during parsing. If null, org.eclipse.jgit.lib.NullProgressMonitor will be used.
progress
)

Parse the pack stream.

public PackLock

Returns:

the pack lock, if one was requested by setting setLockMessage(String).
parse
(ProgressMonitor
receives progress feedback during the initial receiving objects phase. If null, org.eclipse.jgit.lib.NullProgressMonitor will be used.
receiving
,
ProgressMonitor
receives progress feedback during the resolving objects phase.
resolving
)

Parse the pack stream.

private void
protected abstract int

Returns:

number of bytes stored.
readDatabase
(byte[]
the buffer to copy read data into.
dst
,
int
position within dst to start copying data into.
pos
,
int
ideal target number of bytes to read. Actual read length may be shorter.
cnt
)

Read from the database's current position into the buffer.

private int
protected PackParser.ObjectTypeAndSize

Returns:

info, after populating.
readObjectHeader
(PackParser.ObjectTypeAndSize
the info object to populate.
info
)

Read the header of the current object.

private void
private void
private PackParser.UnresolvedDelta
private void
private void
private void
private void
private static PackParser.UnresolvedDelta
protected abstract PackParser.ObjectTypeAndSize

Returns:

the info object.
seekDatabase
(PackedObjectInfo
the object position to begin reading from. This is from newInfo(AnyObjectId, UnresolvedDelta, ObjectId).
obj
,
PackParser.ObjectTypeAndSize
object to populate with type and size.
info
)

Reposition the database to re-read a previously stored object.

protected abstract PackParser.ObjectTypeAndSize

Returns:

the info object.
seekDatabase
(PackParser.UnresolvedDelta
the object position to begin reading from. This is an instance previously returned by onEndDelta().
delta
,
PackParser.ObjectTypeAndSize
object to populate with type and size.
info
)

Reposition the database to re-read a previously stored object.

public void
setAllowThin(boolean
true to enable a thin pack.
allow
)

Configure this index pack instance to allow a thin pack.

public void
setCheckEofAfterPackFooter(boolean
true if the EOF should be read; false if it is not checked.
b
)

Ensure EOF is read from the input stream after the footer.

protected void
setCheckObjectCollisions(boolean
true to enable collision checking (strongly encouraged).
check
)

Enable checking for collisions with existing objects.

public void
setExpectDataAfterPackFooter(boolean
true if there is additional data in InputStream after pack. This requires the InputStream to support the mark and reset functions.
e
)

Set if there is additional data in InputStream after pack.

protected void
setExpectedObjectCount(long
a long.
expectedObjectCount
)

Set the expected number of objects in the pack stream.

public void
setLockMessage(String
if not null, the message to associate with the incoming data while it is locked to prevent garbage collection.
msg
)

Set the lock message for the incoming pack data.

public void
setMaxObjectSizeLimit(long
the Git object size limit. If zero then there is not limit.
limit
)

Set the maximum allowed Git object size.

public void
setNeedBaseObjectIds(boolean
true to enable keeping track of delta bases.
b
)

Configure this index pack instance to keep track of the objects assumed for delta bases.

public void
setNeedNewObjectIds(boolean
true to enable keeping track of new objects.
b
)

Configure this index pack instance to keep track of new objects.

public void
setObjectChecker(ObjectChecker
the checker instance; null to disable object checking.
oc
)

Configure the checker used to validate received objects.

public void
setObjectChecking(boolean
true to enable the default checker; false to disable it.
on
)

Configure the checker used to validate received objects.

private long

Returns:

current position of the input stream being parsed.
streamPosition
()

private void
sync()

pack-priv void
use(int cnt)

protected void
verifySafeObject(final AnyObjectId
identity of the object to be checked.
id
,
final int
the type of the object.
type
,
final byte[]
raw content of the object.
data
)

Verify the integrity of the object.

private void
whole(long pos, int type, long sz)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait