Class PackInserter
- All Implemented Interfaces:
AutoCloseable
flush()
, and never
inserts loose objects.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
Stream that writes to a pack file.private class
Nested classes/interfaces inherited from class org.eclipse.jgit.lib.ObjectInserter
ObjectInserter.Filter, ObjectInserter.Formatter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Inflater
private boolean
private int
private final ObjectDirectory
private static final int
Always produce version 2 indexes, to get CRC data.private List<PackedObjectInfo>
private ObjectIdOwnerMap<PackedObjectInfo>
private PackInserter.PackStream
private PackConfig
private boolean
private File
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate long
beginObject
(int type, long len) private void
void
checkExisting
(boolean check) Whether to check if objects exist in the repoprivate void
clear()
void
close()
private ObjectId
computeName
(List<PackedObjectInfo> list) private ObjectId
void
flush()
Make all inserted objects visible.(package private) int
private static File
private Inflater
inflater()
insert
(int type, byte[] data, int off, int len) Insert a single object into the store, returning its unique name.insert
(int type, long len, InputStream in) Insert a single object into the store, returning its unique name.Initialize a parser to read from a pack formatted stream.Open a reader for objects that may have been written by this inserter.void
setCompressionLevel
(int compression) Set compression level for zlib deflater.private static int
writePackHeader
(byte[] buf, int objectCount) private static void
writePackIndex
(File idx, byte[] packHash, List<PackedObjectInfo> list)
-
Field Details
-
INDEX_VERSION
private static final int INDEX_VERSIONAlways produce version 2 indexes, to get CRC data.- See Also:
-
db
-
objectList
-
objectMap
-
rollback
private boolean rollback -
checkExisting
private boolean checkExisting -
compression
private int compression -
tmpPack
-
packOut
-
cachedInflater
-
pconfig
-
-
Constructor Details
-
PackInserter
PackInserter(ObjectDirectory db)
-
-
Method Details
-
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
Insert a single object into the store, returning its unique name.- Overrides:
insert
in 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:
IOException
- the object could not be stored.
-
insert
Insert a single object into the store, returning its unique name.- Specified by:
insert
in 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:
IOException
- the object could not be stored, or the source stream could not be read.
-
beginObject
- Throws:
IOException
-
endObject
-
idxFor
-
beginPack
- Throws:
IOException
-
writePackHeader
private static int writePackHeader(byte[] buf, int objectCount) -
newPackParser
Initialize a parser to read from a pack formatted stream.- Specified by:
newPackParser
in 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
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
ObjectStream
opened 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:
newReader
in classObjectInserter
- Returns:
- reader for any object, including an object recently inserted by this inserter since the last flush.
-
flush
Make all inserted objects visible.The flush may take some period of time to make the objects available to other threads.
- Specified by:
flush
in classObjectInserter
- Throws:
IOException
- the flush could not be completed; objects inserted thus far are in an indeterminate state.
-
writePackIndex
private static void writePackIndex(File idx, byte[] packHash, List<PackedObjectInfo> list) throws IOException - Throws:
IOException
-
computeName
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in classObjectInserter
-
clear
private void clear() -
inflater
-