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

public Class PackInserter

extends ObjectInserter
Class Inheritance
Static Imports
java.nio.file.StandardCopyOption.ATOMIC_MOVE, org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH, .Constants.OBJ_OFS_DELTA, .Constants.OBJ_REF_DELTA

Object inserter that inserts one pack per call to flush(), and never inserts loose objects.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
PackInserter.PackStream

Stream that writes to a pack file.

private class

Field Summary

Modifier and TypeField and Description
private Inflater
private boolean
private int
private final ObjectDirectory
private static final int
INDEX_VERSION

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

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private long
beginObject(int type, long len)

private void
public void
checkExisting(boolean
if false, will write out possibly-duplicate objects without first checking whether they exist in the repo; default is true.
check
)

Whether to check if objects exist in the repo

private void
public void
close()

Implements abstract org.eclipse.jgit.lib.ObjectInserter.close.

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

private ObjectId
private ObjectId
endObject(ObjectId id, long offset)

public void
flush()

Implements abstract org.eclipse.jgit.lib.ObjectInserter.flush.

Make all inserted objects visible.

pack-priv int
private static File
idxFor(File packFile)

private Inflater
public ObjectId
insert(int
type code of the object to store.
type
,
byte[]
complete content of the object.
data
,
int
first position within data.
off
,
int
number of bytes to copy from data.
len
)

Overrides org.eclipse.jgit.lib.ObjectInserter.insert.

Insert a single object into the store, returning its unique name.

public ObjectId
insert(int
type code of the object to store.
type
,
long
number of bytes to copy from in.
len
,
InputStream
stream providing the object content. The caller is responsible for closing the stream.
in
)

Implements abstract org.eclipse.jgit.lib.ObjectInserter.insert.

Insert a single object into the store, returning its unique name.

public PackParser
newPackParser(InputStream
the input stream. The stream is not closed by the parser, and must instead be closed by the caller once parsing is complete.
in
)

Implements abstract org.eclipse.jgit.lib.ObjectInserter.newPackParser.

Initialize a parser to read from a pack formatted stream.

public ObjectReader
newReader()

Implements abstract org.eclipse.jgit.lib.ObjectInserter.newReader.

Open a reader for objects that may have been written by this inserter.

public void
setCompressionLevel(int
compression level for zlib deflater.
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)

Inherited from org.eclipse.jgit.lib.ObjectInserter:
bufferdigestidForidForidForidForinsertinsertinsertinsert

Field Detail

cachedInflaterback to summary
private Inflater cachedInflater
checkExistingback to summary
private boolean checkExisting
compressionback to summary
private int compression
dbback to summary
private final ObjectDirectory db
INDEX_VERSIONback to summary
private static final int INDEX_VERSION

Always produce version 2 indexes, to get CRC data.

objectListback to summary
private List<PackedObjectInfo> objectList
objectMapback to summary
private ObjectIdOwnerMap<PackedObjectInfo> objectMap
packOutback to summary
private PackInserter.PackStream packOut
pconfigback to summary
private PackConfig pconfig
rollbackback to summary
private boolean rollback
tmpPackback to summary
private File tmpPack

Constructor Detail

PackInserterback to summary
pack-priv PackInserter(ObjectDirectory db)

Method Detail

beginObjectback to summary
private long beginObject(int type, long len) throws IOException
beginPackback to summary
private void beginPack() throws IOException
checkExistingback to summary
public void checkExisting(boolean check)

Whether to check if objects exist in the repo

Parameters
check:boolean

if false, will write out possibly-duplicate objects without first checking whether they exist in the repo; default is true.

clearback to summary
private void clear()
closeback to summary
public void close()

Implements abstract org.eclipse.jgit.lib.ObjectInserter.close.

Implements java.lang.AutoCloseable.close.

Doc from org.eclipse.jgit.lib.ObjectInserter.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

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.

Annotations
@Override
computeNameback to summary
private ObjectId computeName(List<PackedObjectInfo> list)
endObjectback to summary
private ObjectId endObject(ObjectId id, long offset)
flushback to summary
public void flush() throws IOException

Implements abstract org.eclipse.jgit.lib.ObjectInserter.flush.

Doc from org.eclipse.jgit.lib.ObjectInserter.flush.

Make all inserted objects visible.

The flush may take some period of time to make the objects available to other threads.

Annotations
@Override
Exceptions
IOException:
the flush could not be completed; objects inserted thus far are in an indeterminate state.
getBufferSizeback to summary
pack-priv int getBufferSize()
idxForback to summary
private static File idxFor(File packFile)
inflaterback to summary
private Inflater inflater()
insertback to summary
public ObjectId insert(int type, byte[] data, int off, int len) throws IOException

Overrides org.eclipse.jgit.lib.ObjectInserter.insert.

Doc from org.eclipse.jgit.lib.ObjectInserter.insert.

Insert a single object into the store, returning its unique name.

Parameters
type:int

type code of the object to store.

data:byte[]

complete content of the object.

off:int

first position within data.

len:int

number of bytes to copy from data.

Returns:ObjectId

the name of the object.

Annotations
@Override
Exceptions
IOException:
the object could not be stored.
insertback to summary
public ObjectId insert(int type, long len, InputStream in) throws IOException

Implements abstract org.eclipse.jgit.lib.ObjectInserter.insert.

Doc from org.eclipse.jgit.lib.ObjectInserter.insert.

Insert a single object into the store, returning its unique name.

Parameters
type:int

type code of the object to store.

len:long

number of bytes to copy from in.

in:InputStream

stream providing the object content. The caller is responsible for closing the stream.

Returns:ObjectId

the name of the object.

Annotations
@Override
Exceptions
IOException:
the object could not be stored, or the source stream could not be read.
newPackParserback to summary
public PackParser newPackParser(InputStream in)

Implements abstract org.eclipse.jgit.lib.ObjectInserter.newPackParser.

Doc from org.eclipse.jgit.lib.ObjectInserter.newPackParser.

Initialize a parser to read from a pack formatted stream.

Parameters
in:InputStream

the input stream. The stream is not closed by the parser, and must instead be closed by the caller once parsing is complete.

Returns:PackParser

the pack parser.

Annotations
@Override
newReaderback to summary
public ObjectReader newReader()

Implements abstract org.eclipse.jgit.lib.ObjectInserter.newReader.

Doc from org.eclipse.jgit.lib.ObjectInserter.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 to this.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.

Returns:ObjectReader

reader for any object, including an object recently inserted by this inserter since the last flush.

Annotations
@Override
setCompressionLevelback to summary
public void setCompressionLevel(int compression)

Set compression level for zlib deflater.

Parameters
compression:int

compression level for zlib deflater.

writePackHeaderback to summary
private static int writePackHeader(byte[] buf, int objectCount)
writePackIndexback to summary
private static void writePackIndex(File idx, byte[] packHash, List<PackedObjectInfo> list) throws IOException
org.eclipse.jgit.internal.storage.file back to summary

private Class PackInserter.PackStream

extends OutputStream
Class Inheritance

Stream that writes to a pack file.

Backed by two views of the same open file descriptor: a random-access file, and an output stream. Seeking in the file causes subsequent writes to the output stream to occur wherever the file pointer is pointing, so we need to take care to always seek to the end of the file before writing a new object.

Callers should always use seek(long) to seek, rather than reaching into the file member. As long as this contract is followed, calls to write(byte[], int, int) are guaranteed to write at the end of the file, even if there have been intermediate seeks.

Field Summary

Modifier and TypeField and Description
private boolean
pack-priv final DeflaterOutputStream
pack-priv final CRC32
private final Deflater
private final RandomAccessFile
pack-priv final byte[]
private final CountingOutputStream

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
beginObject(int objectType, long length)

public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

private int
encodeTypeSize(int type, long rawLength)

pack-priv byte[]
pack-priv long
pack-priv byte[]
inflate(long filePos, int len)

pack-priv void
seek(long offset)

private int
setInput(long filePos, Inflater inf, byte[] buf)

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[]
the data.
data
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from java.io.OutputStream:
flushnullOutputStreamwrite

Field Detail

atEndback to summary
private boolean atEnd
compressback to summary
pack-priv final DeflaterOutputStream compress
crc32back to summary
pack-priv final CRC32 crc32
deflaterback to summary
private final Deflater deflater
fileback to summary
private final RandomAccessFile file
hdrBufback to summary
pack-priv final byte[] hdrBuf
outback to summary
private final CountingOutputStream out

Constructor Detail

PackStreamback to summary
pack-priv PackStream(File pack) throws IOException

Method Detail

beginObjectback to summary
pack-priv void beginObject(int objectType, long length) throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
encodeTypeSizeback to summary
private int encodeTypeSize(int type, long rawLength)
finishPackback to summary
pack-priv byte[] finishPack() throws IOException
getOffsetback to summary
pack-priv long getOffset()
inflateback to summary
pack-priv byte[] inflate(long filePos, int len) throws IOException, DataFormatException
seekback to summary
pack-priv void seek(long offset) throws IOException
setInputback to summary
private int setInput(long filePos, Inflater inf, byte[] buf) throws IOException
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] data, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
data:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
org.eclipse.jgit.internal.storage.file back to summary

private Class PackInserter.Reader

extends ObjectReader
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final ObjectReader
Inherited from org.eclipse.jgit.lib.ObjectReader:
OBJ_ANYstreamFileThreshold

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract org.eclipse.jgit.lib.ObjectReader.close.

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

public ObjectInserter
getCreatedFromInserter()

Overrides org.eclipse.jgit.lib.ObjectReader.getCreatedFromInserter.

Get the org.eclipse.jgit.lib.ObjectInserter from which this reader was created using inserter.newReader()

public Set<ObjectId>
getShallowCommits()

Implements abstract org.eclipse.jgit.lib.ObjectReader.getShallowCommits.

Returns IDs for those commits which should be considered as shallow.

private byte[]
inflate(PackedObjectInfo obj, long zpos, int sz)

public ObjectReader
newReader()

Implements abstract org.eclipse.jgit.lib.ObjectReader.newReader.

Construct a new reader from the same data.

public ObjectLoader
open(AnyObjectId
identity of the object to open.
objectId
,
int
hint about the type of object being requested, e.g. org.eclipse.jgit.lib.Constants#OBJ_BLOB; OBJ_ANY if the object type is not known, or does not matter to the caller.
typeHint
)

Implements abstract org.eclipse.jgit.lib.ObjectReader.open.

Open an object from this database.

public Collection<ObjectId>
resolve(AbbreviatedObjectId
abbreviated id to resolve to a complete identity. The abbreviation must have a length of at least 2.
id
)

Implements abstract org.eclipse.jgit.lib.ObjectReader.resolve.

Resolve an abbreviated ObjectId to its full form.

Inherited from org.eclipse.jgit.lib.ObjectReader:
abbreviateabbreviatecreateObjectReachabilityCheckercreateReachabilityCheckergetBitmapIndexgetCommitGraphgetObjectSizegetObjectSizegetStreamFileThresholdhashasisNotLargerThanopenopensetAvoidUnreachableObjectssetStreamFileThreshold

Field Detail

ctxback to summary
private final ObjectReader ctx

Constructor Detail

Readerback to summary
private Reader()

Method Detail

closeback to summary
public void close()

Implements abstract org.eclipse.jgit.lib.ObjectReader.close.

Implements java.lang.AutoCloseable.close.

Doc from org.eclipse.jgit.lib.ObjectReader.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Release any resources used by this reader.

A reader that has been released can be used again, but may need to be released after the subsequent usage.

Annotations
@Override
getCreatedFromInserterback to summary
public ObjectInserter getCreatedFromInserter()

Overrides org.eclipse.jgit.lib.ObjectReader.getCreatedFromInserter.

Doc from org.eclipse.jgit.lib.ObjectReader.getCreatedFromInserter.

Get the org.eclipse.jgit.lib.ObjectInserter from which this reader was created using inserter.newReader()

Returns:ObjectInserter

the org.eclipse.jgit.lib.ObjectInserter from which this reader was created using inserter.newReader(), or null if this reader was not created from an inserter.

Annotations
@Override
getShallowCommitsback to summary
public Set<ObjectId> getShallowCommits() throws IOException

Implements abstract org.eclipse.jgit.lib.ObjectReader.getShallowCommits.

Doc from org.eclipse.jgit.lib.ObjectReader.getShallowCommits.

Returns IDs for those commits which should be considered as shallow.

Returns:Set<ObjectId>

IDs of shallow commits

Annotations
@Override
Exceptions
IOException:
if an error occurred
inflateback to summary
private byte[] inflate(PackedObjectInfo obj, long zpos, int sz) throws IOException, CorruptObjectException
newReaderback to summary
public ObjectReader newReader()

Implements abstract org.eclipse.jgit.lib.ObjectReader.newReader.

Doc from org.eclipse.jgit.lib.ObjectReader.newReader.

Construct a new reader from the same data.

Applications can use this method to build a new reader from the same data source, but for an different thread.

Returns:ObjectReader

a brand new reader, using the same data source.

Annotations
@Override
openback to summary
public ObjectLoader open(AnyObjectId objectId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, IOException

Implements abstract org.eclipse.jgit.lib.ObjectReader.open.

Doc from org.eclipse.jgit.lib.ObjectReader.open.

Open an object from this database.

Parameters
objectId:AnyObjectId

identity of the object to open.

typeHint:int

hint about the type of object being requested, e.g. org.eclipse.jgit.lib.Constants#OBJ_BLOB; OBJ_ANY if the object type is not known, or does not matter to the caller.

Returns:ObjectLoader

a org.eclipse.jgit.lib.ObjectLoader for accessing the object.

Annotations
@Override
Exceptions
MissingObjectException:
the object does not exist.
IncorrectObjectTypeException:
typeHint was not OBJ_ANY, and the object's actual type does not match typeHint.
IOException:
the object store cannot be accessed.
resolveback to summary
public Collection<ObjectId> resolve(AbbreviatedObjectId id) throws IOException

Implements abstract org.eclipse.jgit.lib.ObjectReader.resolve.

Doc from org.eclipse.jgit.lib.ObjectReader.resolve.

Resolve an abbreviated ObjectId to its full form. This method searches for an ObjectId that begins with the abbreviation, and returns at least some matching candidates. If the returned collection is empty, no objects start with this abbreviation. The abbreviation doesn't belong to this repository, or the repository lacks the necessary objects to complete it. If the collection contains exactly one member, the abbreviation is (currently) unique within this database. There is a reasonably high probability that the returned id is what was previously abbreviated. If the collection contains 2 or more members, the abbreviation is not unique. In this case the implementation is only required to return at least 2 candidates to signal the abbreviation has conflicts. User friendly implementations should return as many candidates as reasonably possible, as the caller may be able to disambiguate further based on context. However since databases can be very large (e.g. 10 million objects) returning 625,000 candidates for the abbreviation "0" is simply unreasonable, so implementors should draw the line at around 256 matches.

Parameters
id:AbbreviatedObjectId

abbreviated id to resolve to a complete identity. The abbreviation must have a length of at least 2.

Returns:Collection<ObjectId>

candidates that begin with the abbreviated identity.

Annotations
@Override
Exceptions
IOException:
the object store cannot be read.
org.eclipse.jgit.internal.storage.file back to summary

private Class PackInserter.Reader.StreamLoader

extends ObjectLoader
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final long
private final long
private final int

Constructor Summary

AccessConstructor and Description
pack-priv
StreamLoader(int type, long size, long pos)

Method Summary

Modifier and TypeMethod and Description
public byte[]
getCachedBytes()

Implements abstract org.eclipse.jgit.lib.ObjectLoader.getCachedBytes.

Obtain a reference to the (possibly cached) bytes of this object.

public long
getSize()

Implements abstract org.eclipse.jgit.lib.ObjectLoader.getSize.

Get size of object in bytes

public int
getType()

Implements abstract org.eclipse.jgit.lib.ObjectLoader.getType.

Get Git in pack object type

public ObjectStream
openStream()

Implements abstract org.eclipse.jgit.lib.ObjectLoader.openStream.

Obtain an input stream to read this object's data.

Inherited from org.eclipse.jgit.lib.ObjectLoader:
copyTogetBytesgetBytesgetCachedBytesisLarge

Field Detail

posback to summary
private final long pos
sizeback to summary
private final long size
typeback to summary
private final int type

Constructor Detail

StreamLoaderback to summary
pack-priv StreamLoader(int type, long size, long pos)

Method Detail

getCachedBytesback to summary
public byte[] getCachedBytes() throws LargeObjectException

Implements abstract org.eclipse.jgit.lib.ObjectLoader.getCachedBytes.

Doc from org.eclipse.jgit.lib.ObjectLoader.getCachedBytes.

Obtain a reference to the (possibly cached) bytes of this object.

This method offers direct access to the internal caches, potentially saving on data copies between the internal cache and higher level code. Callers who receive this reference must not modify its contents. Changes (if made) will affect the cache but not the repository itself.

Returns:byte[]

the cached bytes of this object. Do not modify it.

Annotations
@Override
Exceptions
LargeObjectException:
if the object won't fit into a byte array, because isLarge() returns true. Callers should use openStream() instead to access the contents.
getSizeback to summary
public long getSize()

Implements abstract org.eclipse.jgit.lib.ObjectLoader.getSize.

Doc from org.eclipse.jgit.lib.ObjectLoader.getSize.

Get size of object in bytes

Returns:long

size of object in bytes

Annotations
@Override
getTypeback to summary
public int getType()

Implements abstract org.eclipse.jgit.lib.ObjectLoader.getType.

Doc from org.eclipse.jgit.lib.ObjectLoader.getType.

Get Git in pack object type

Returns:int

Git in pack object type, see org.eclipse.jgit.lib.Constants.

Annotations
@Override
openStreamback to summary
public ObjectStream openStream() throws MissingObjectException, IOException

Implements abstract org.eclipse.jgit.lib.ObjectLoader.openStream.

Doc from org.eclipse.jgit.lib.ObjectLoader.openStream.

Obtain an input stream to read this object's data.

Returns:ObjectStream

a stream of this object's data. Caller must close the stream when through with it. The returned stream is buffered with a reasonable buffer size.

Annotations
@Override
Exceptions
MissingObjectException:
the object no longer exists.
IOException:
the object store cannot be accessed.