Class PackInserter
- java.lang.Object
-
- org.eclipse.jgit.lib.ObjectInserter
-
- org.eclipse.jgit.internal.storage.file.PackInserter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class PackInserter extends ObjectInserter
Object inserter that inserts one pack per call toflush(), and never inserts loose objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPackInserter.PackStreamStream that writes to a pack file.private classPackInserter.Reader-
Nested classes/interfaces inherited from class org.eclipse.jgit.lib.ObjectInserter
ObjectInserter.Filter, ObjectInserter.Formatter
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.zip.InflatercachedInflaterprivate booleancheckExistingprivate intcompressionprivate ObjectDirectorydbprivate static intINDEX_VERSIONAlways produce version 2 indexes, to get CRC data.private java.util.List<PackedObjectInfo>objectListprivate ObjectIdOwnerMap<PackedObjectInfo>objectMapprivate PackInserter.PackStreampackOutprivate PackConfigpconfigprivate booleanrollbackprivate java.io.FiletmpPack
-
Constructor Summary
Constructors Constructor Description PackInserter(ObjectDirectory db)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private longbeginObject(int type, long len)private voidbeginPack()voidcheckExisting(boolean check)Whether to check if objects exist in the repoprivate voidclear()voidclose()private ObjectIdcomputeName(java.util.List<PackedObjectInfo> list)private ObjectIdendObject(ObjectId id, long offset)voidflush()Make all inserted objects visible.(package private) intgetBufferSize()private static java.io.FileidxFor(java.io.File packFile)private java.util.zip.Inflaterinflater()ObjectIdinsert(int type, byte[] data, int off, int len)Insert a single object into the store, returning its unique name.ObjectIdinsert(int type, long len, java.io.InputStream in)Insert a single object into the store, returning its unique name.PackParsernewPackParser(java.io.InputStream in)Initialize a parser to read from a pack formatted stream.ObjectReadernewReader()Open a reader for objects that may have been written by this inserter.voidsetCompressionLevel(int compression)Set compression level for zlib deflater.private static intwritePackHeader(byte[] buf, int objectCount)private static voidwritePackIndex(java.io.File idx, byte[] packHash, java.util.List<PackedObjectInfo> list)
-
-
-
Field Detail
-
INDEX_VERSION
private static final int INDEX_VERSION
Always produce version 2 indexes, to get CRC data.- See Also:
- Constant Field Values
-
db
private final ObjectDirectory db
-
objectList
private java.util.List<PackedObjectInfo> objectList
-
objectMap
private ObjectIdOwnerMap<PackedObjectInfo> objectMap
-
rollback
private boolean rollback
-
checkExisting
private boolean checkExisting
-
compression
private int compression
-
tmpPack
private java.io.File tmpPack
-
packOut
private PackInserter.PackStream packOut
-
cachedInflater
private java.util.zip.Inflater cachedInflater
-
pconfig
private PackConfig pconfig
-
-
Constructor Detail
-
PackInserter
PackInserter(ObjectDirectory db)
-
-
Method Detail
-
checkExisting
public void checkExisting(boolean check)
Whether to check if objects exist in the repo- Parameters:
check- iffalse, will write out possibly-duplicate objects without first checking whether they exist in the repo; default is true.
-
setCompressionLevel
public void setCompressionLevel(int compression)
Set compression level for zlib deflater.- Parameters:
compression- compression level for zlib deflater.
-
getBufferSize
int getBufferSize()
-
insert
public ObjectId insert(int type, byte[] data, int off, int len) throws java.io.IOException
Insert a single object into the store, returning its unique name.- Overrides:
insertin classObjectInserter- Parameters:
type- type code of the object to store.data- complete content of the object.off- first position withindata.len- number of bytes to copy fromdata.- Returns:
- the name of the object.
- Throws:
java.io.IOException- the object could not be stored.
-
insert
public ObjectId insert(int type, long len, java.io.InputStream in) throws java.io.IOException
Insert a single object into the store, returning its unique name.- Specified by:
insertin classObjectInserter- Parameters:
type- type code of the object to store.len- number of bytes to copy fromin.in- stream providing the object content. The caller is responsible for closing the stream.- Returns:
- the name of the object.
- Throws:
java.io.IOException- the object could not be stored, or the source stream could not be read.
-
beginObject
private long beginObject(int type, long len) throws java.io.IOException- Throws:
java.io.IOException
-
idxFor
private static java.io.File idxFor(java.io.File packFile)
-
beginPack
private void beginPack() throws java.io.IOException- Throws:
java.io.IOException
-
writePackHeader
private static int writePackHeader(byte[] buf, int objectCount)
-
newPackParser
public PackParser newPackParser(java.io.InputStream in)
Initialize a parser to read from a pack formatted stream.- Specified by:
newPackParserin classObjectInserter- Parameters:
in- the input stream. The stream is not closed by the parser, and must instead be closed by the caller once parsing is complete.- Returns:
- the pack parser.
-
newReader
public ObjectReader newReader()
Open a reader for objects that may have been written by this inserter.The returned reader allows the calling thread to read back recently inserted objects without first calling
flush()to make them visible to the repository. The returned reader should only be used from the same thread as the inserter. Objects written by this inserter may not be visible tothis.newReader().newReader().The returned reader should return this inserter instance from
ObjectReader.getCreatedFromInserter().Behavior is undefined if an insert method is called on the inserter in the middle of reading from an
ObjectStreamopened from this reader. For example, reading the remainder of the object may fail, or newly written data may even be corrupted. Interleaving whole object reads (including streaming reads) with inserts is fine, just not interleaving streaming partial object reads with inserts.- Specified by:
newReaderin classObjectInserter- Returns:
- reader for any object, including an object recently inserted by this inserter since the last flush.
-
flush
public void flush() throws java.io.IOExceptionMake all inserted objects visible.The flush may take some period of time to make the objects available to other threads.
- Specified by:
flushin classObjectInserter- Throws:
java.io.IOException- the flush could not be completed; objects inserted thus far are in an indeterminate state.
-
writePackIndex
private static void writePackIndex(java.io.File idx, byte[] packHash, java.util.List<PackedObjectInfo> list) throws java.io.IOException- Throws:
java.io.IOException
-
computeName
private ObjectId computeName(java.util.List<PackedObjectInfo> list)
-
close
public void close()
Release any resources used by this inserter.
An inserter that has been released can be used again, but may need to be released after the subsequent usage.
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein classObjectInserter
-
clear
private void clear()
-
inflater
private java.util.zip.Inflater inflater()
-
-