Class ObjectDirectoryPackParser
ObjectDirectory.
To obtain an instance of a parser, applications should use
ObjectInserter.newPackParser(InputStream).
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jgit.transport.PackParser
PackParser.ObjectTypeAndSize, PackParser.Source, PackParser.UnresolvedDelta -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CRC32CRC-32 computation for objects that are appended onto the pack.private final FileObjectDatabaseprivate DeflaterCompresses delta bases when completing a thin pack.private intPreferred format version of the pack-*.idx file to generate.private booleanIf true, pack with 0 objects will be stored.private PackThe pack that was created, if parsing was successful.private longLength of the original pack stream, before missing bases were appended.private byte[]The original checksum of data up toorigEnd.private RandomAccessFileRead/write handle totmpPackwhile it is being parsed.private longCurrent end of the pack file.private byte[]Checksum of the entire pack file.private PackConfigprivate final MessageDigestRunning SHA-1 of any base objects appended afterorigEnd.private FilePath of the index created for the pack, to find objects quickly at read time.private FilePath of the temporary file holding the pack data. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Stringprotected booleancheckCRC(int oldCRC) Check the current CRC matches the expected value.private voidgetPack()Get the importedPack.longGet the size of the newly created pack.protected booleanonAppendBase(int typeCode, byte[] data, PackedObjectInfo info) Provide the implementation with a base that was outside of the pack.protected voidonBeginOfsDelta(long streamPosition, long baseStreamPosition, long inflatedSize) Event notifying start of a delta referencing its base by offset.protected voidonBeginRefDelta(long streamPosition, AnyObjectId baseId, long inflatedSize) Event notifying start of a delta referencing its base by ObjectId.protected voidonBeginWholeObject(long streamPosition, int type, long inflatedSize) Event notifying the start of an object stored whole (not as a delta).protected PackParser.UnresolvedDeltaEvent notifying the current object.protected voidEvent indicating a thin pack has been completely processed.protected voidEvent notifying the current object.protected voidonInflatedObjectData(PackedObjectInfo obj, int typeCode, byte[] data) Invoked for commits, trees, tags, and small blobs.protected voidonObjectData(PackParser.Source src, byte[] raw, int pos, int len) Store (and/or checksum) a portion of an object's data.protected voidonObjectHeader(PackParser.Source src, byte[] raw, int pos, int len) Store (and/or checksum) an object header.protected voidonPackFooter(byte[] hash) Provide the implementation with the original stream's pack footer.protected voidonPackHeader(long objectCount) Provide the implementation with the original stream's pack header.protected voidonStoreStream(byte[] raw, int pos, int len) Store bytes received from the raw stream.parse(ProgressMonitor receiving, ProgressMonitor resolving) Parse the pack stream.protected intreadDatabase(byte[] dst, int pos, int cnt) Read from the database's current position into the buffer.private PackLockrenameAndOpenPack(String lockMessage) protected PackParser.ObjectTypeAndSizeReposition the database to re-read a previously stored object.protected PackParser.ObjectTypeAndSizeReposition the database to re-read a previously stored object.voidsetIndexVersion(int version) Set the pack index file format version this instance will create.voidsetKeepEmpty(boolean empty) Configure this index pack instance to keep an empty pack.private voidwriteIdx()Methods inherited from class org.eclipse.jgit.transport.PackParser
buffer, getBaseObjectIds, getLockMessage, getNewObjectIds, getObject, getObjectCount, getReceivedPackStatistics, getSortedObjectList, isAllowThin, isCheckEofAfterPackFooter, isCheckObjectCollisions, isExpectDataAfterPackFooter, newInfo, parse, readObjectHeader, setAllowThin, setCheckEofAfterPackFooter, setCheckObjectCollisions, setExpectDataAfterPackFooter, setExpectedObjectCount, setLockMessage, setMaxObjectSizeLimit, setNeedBaseObjectIds, setNeedNewObjectIds, setObjectChecker, setObjectChecking, verifySafeObject
-
Field Details
-
db
-
crc
CRC-32 computation for objects that are appended onto the pack. -
tailDigest
Running SHA-1 of any base objects appended afterorigEnd. -
indexVersion
private int indexVersionPreferred format version of the pack-*.idx file to generate. -
keepEmpty
private boolean keepEmptyIf true, pack with 0 objects will be stored. Usually these are deleted. -
tmpPack
Path of the temporary file holding the pack data. -
tmpIdx
Path of the index created for the pack, to find objects quickly at read time. -
out
Read/write handle totmpPackwhile it is being parsed. -
origEnd
private long origEndLength of the original pack stream, before missing bases were appended. -
origHash
private byte[] origHashThe original checksum of data up toorigEnd. -
packEnd
private long packEndCurrent end of the pack file. -
packHash
private byte[] packHashChecksum of the entire pack file. -
def
Compresses delta bases when completing a thin pack. -
newPack
The pack that was created, if parsing was successful. -
pconfig
-
-
Constructor Details
-
ObjectDirectoryPackParser
ObjectDirectoryPackParser(FileObjectDatabase odb, InputStream src)
-
-
Method Details
-
setIndexVersion
public void setIndexVersion(int version) Set the pack index file format version this instance will create.- Parameters:
version- the version to write. The special version 0 designates the oldest (most compatible) format available for the objects.- See Also:
-
setKeepEmpty
public void setKeepEmpty(boolean empty) Configure this index pack instance to keep an empty pack.By default an empty pack (a pack with no objects) is not kept, as doi so is completely pointless. With no objects in the pack there is no d stored by it, so the pack is unnecessary.
- Parameters:
empty- true to enable keeping an empty pack.
-
getPack
Get the importedPack.This method is supplied only to support testing; applications shouldn't be using it directly to access the imported data.
- Returns:
- the imported PackFile, if parsing was successful.
-
getPackSize
public long getPackSize()Get the size of the newly created pack.This will also include the pack index size if an index was created. This method should only be called after pack parsing is finished.
- Overrides:
getPackSizein classPackParser- Returns:
- the pack size (including the index size) or -1 if the size cannot be determined
-
parse
Parse the pack stream.- Overrides:
parsein classPackParser- Parameters:
receiving- receives progress feedback during the initial receiving objects phase. If null,NullProgressMonitorwill be used.resolving- receives progress feedback during the resolving objects phase.- Returns:
- the pack lock, if one was requested by setting
PackParser.setLockMessage(String). - Throws:
IOException- the stream is malformed, or contains corrupt objects.
-
onPackHeader
Provide the implementation with the original stream's pack header.- Specified by:
onPackHeaderin classPackParser- Parameters:
objectCount- number of objects expected in the stream.- Throws:
IOException- the implementation refuses to work with this many objects.
-
onBeginWholeObject
protected void onBeginWholeObject(long streamPosition, int type, long inflatedSize) throws IOException Event notifying the start of an object stored whole (not as a delta).- Specified by:
onBeginWholeObjectin classPackParser- Parameters:
streamPosition- position of this object in the incoming stream.type- type of the object; one ofConstants.OBJ_COMMIT,Constants.OBJ_TREE,Constants.OBJ_BLOB, orConstants.OBJ_TAG.inflatedSize- size of the object when fully inflated. The size stored within the pack may be larger or smaller, and is not yet known.- Throws:
IOException- the object cannot be recorded.
-
onEndWholeObject
Event notifying the current object.- Specified by:
onEndWholeObjectin classPackParser- Parameters:
info- object information.- Throws:
IOException- the object cannot be recorded.
-
onBeginOfsDelta
protected void onBeginOfsDelta(long streamPosition, long baseStreamPosition, long inflatedSize) throws IOException Event notifying start of a delta referencing its base by offset.- Specified by:
onBeginOfsDeltain classPackParser- Parameters:
streamPosition- position of this object in the incoming stream.baseStreamPosition- position of the base object in the incoming stream. The base must be before the delta, thereforebaseStreamPosition < deltaStreamPosition. This is not the position returned by a prior end object event.inflatedSize- size of the delta when fully inflated. The size stored within the pack may be larger or smaller, and is not yet known.- Throws:
IOException- the object cannot be recorded.
-
onBeginRefDelta
protected void onBeginRefDelta(long streamPosition, AnyObjectId baseId, long inflatedSize) throws IOException Event notifying start of a delta referencing its base by ObjectId.- Specified by:
onBeginRefDeltain classPackParser- Parameters:
streamPosition- position of this object in the incoming stream.baseId- 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).inflatedSize- size of the delta when fully inflated. The size stored within the pack may be larger or smaller, and is not yet known.- Throws:
IOException- the object cannot be recorded.
-
onEndDelta
Event notifying the current object.- Overrides:
onEndDeltain classPackParser- Returns:
- object information that must be populated with at least the offset.
- Throws:
IOException- the object cannot be recorded.
-
onInflatedObjectData
protected void onInflatedObjectData(PackedObjectInfo obj, int typeCode, byte[] data) throws IOException Invoked for commits, trees, tags, and small blobs.- Specified by:
onInflatedObjectDatain classPackParser- Parameters:
obj- the object info, populated.typeCode- the type of the object.data- inflated data for the object.- Throws:
IOException- the object cannot be archived.
-
onObjectHeader
protected void onObjectHeader(PackParser.Source src, byte[] raw, int pos, int len) throws IOException Store (and/or checksum) an object header.Invoked after any of the
onBegin()events. The entire header is supplied in a single invocation, before any object data is supplied.- Specified by:
onObjectHeaderin classPackParser- Parameters:
src- where the data came fromraw- buffer to read data from.pos- first offset within buffer that is valid.len- number of bytes in buffer that are valid.- Throws:
IOException- the stream cannot be archived.
-
onObjectData
Store (and/or checksum) a portion of an object's data.This method may be invoked multiple times per object, depending on the size of the object, the size of the parser's internal read buffer, and the alignment of the object relative to the read buffer.
Invoked after
PackParser.onObjectHeader(Source, byte[], int, int).- Specified by:
onObjectDatain classPackParser- Parameters:
src- where the data came fromraw- buffer to read data from.pos- first offset within buffer that is valid.len- number of bytes in buffer that are valid.- Throws:
IOException- the stream cannot be archived.
-
onStoreStream
Store bytes received from the raw stream.This method is invoked during
PackParser.parse(ProgressMonitor)as data is consumed from the incoming stream. Implementors may use this event to archive the raw incoming stream to the destination repository in large chunks, without paying attention to object boundaries.The only component of the pack not supplied to this method is the last 20 bytes of the pack that comprise the trailing SHA-1 checksum. Those are passed to
PackParser.onPackFooter(byte[]).- Specified by:
onStoreStreamin classPackParser- Parameters:
raw- buffer to copy data out of.pos- first offset within the buffer that is valid.len- number of bytes in the buffer that are valid.- Throws:
IOException- the stream cannot be archived.
-
seekDatabase
protected PackParser.ObjectTypeAndSize seekDatabase(PackParser.UnresolvedDelta delta, PackParser.ObjectTypeAndSize info) throws IOException Reposition the database to re-read a previously stored object.If the database is computing CRC-32 checksums for object data, it should reset its internal CRC instance during this method call.
- Specified by:
seekDatabasein classPackParser- Parameters:
delta- the object position to begin reading from. This is an instance previously returned byPackParser.onEndDelta().info- object to populate with type and size.- Returns:
- the
infoobject. - Throws:
IOException- the database cannot reposition to this location.
-
seekDatabase
protected PackParser.ObjectTypeAndSize seekDatabase(PackedObjectInfo obj, PackParser.ObjectTypeAndSize info) throws IOException Reposition the database to re-read a previously stored object.If the database is computing CRC-32 checksums for object data, it should reset its internal CRC instance during this method call.
- Specified by:
seekDatabasein classPackParser- Parameters:
obj- the object position to begin reading from. This is fromPackParser.newInfo(AnyObjectId, UnresolvedDelta, ObjectId).info- object to populate with type and size.- Returns:
- the
infoobject. - Throws:
IOException- the database cannot reposition to this location.
-
readDatabase
Read from the database's current position into the buffer.- Specified by:
readDatabasein classPackParser- Parameters:
dst- the buffer to copy read data into.pos- position withindstto start copying data into.cnt- ideal target number of bytes to read. Actual read length may be shorter.- Returns:
- number of bytes stored.
- Throws:
IOException- the database cannot be accessed.
-
checkCRC
protected boolean checkCRC(int oldCRC) Check the current CRC matches the expected value.This method is invoked when an object is read back in from the database and its data is used during delta resolution. The CRC is validated after the object has been fully read, allowing the parser to verify there was no silent data corruption.
Implementations are free to ignore this check by always returning true if they are performing other data integrity validations at a lower level.
- Specified by:
checkCRCin classPackParser- Parameters:
oldCRC- the prior CRC that was recorded during the first scan of the object from the pack stream.- Returns:
- true if the CRC matches; false if it does not.
-
baseName
-
cleanupTemporaryFiles
private void cleanupTemporaryFiles() -
onAppendBase
Provide the implementation with a base that was outside of the pack.This event only occurs on a thin pack for base objects that were outside of the pack and came from the local repository. Usually an implementation uses this event to compress the base and append it onto the end of the pack, so the pack stays self-contained.
- Specified by:
onAppendBasein classPackParser- Parameters:
typeCode- type of the base object.data- complete content of the base object.info- packed object information for this base. Implementors must populate the CRC and offset members if returning true.- Returns:
- true if the
infoshould be included in the object list returned byPackParser.getSortedObjectList(Comparator), false if it should not be included. - Throws:
IOException- the base could not be included into the pack.
-
onEndThinPack
Event indicating a thin pack has been completely processed.This event is invoked only if a thin pack has delta references to objects external from the pack. The event is called after all of those deltas have been resolved.
- Specified by:
onEndThinPackin classPackParser- Throws:
IOException- the pack cannot be archived.
-
writeIdx
- Throws:
IOException
-
renameAndOpenPack
- Throws:
IOException
-