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

pack-priv final Class WindowCursor

extends ObjectReader
implements ObjectReuseAsIs
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs
Imports
java.io.IOException, java.util.Collection, .Collections, .HashSet, .List, .Optional, .Set, java.util.zip.DataFormatException, .Inflater, org.eclipse.jgit.annotations.Nullable, org.eclipse.jgit.errors.IncorrectObjectTypeException, .MissingObjectException, .StoredObjectRepresentationNotAvailableException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.internal.storage.pack.CachedPack, .ObjectReuseAsIs, .ObjectToPack, .PackOutputStream, .PackWriter, org.eclipse.jgit.lib.AbbreviatedObjectId, .AnyObjectId, .BitmapIndex, .BitmapIndex.BitmapBuilder, .Constants, .InflaterCache, .ObjectId, .ObjectInserter, .ObjectLoader, .ObjectReader, .ProgressMonitor, org.eclipse.jgit.internal.storage.commitgraph.CommitGraph

Active handle to a ByteWindow.

Field Summary

Modifier and TypeField and Description
private DeltaBaseCache
private final ObjectInserter
pack-priv final FileObjectDatabase
private Inflater
pack-priv final byte[]
tempId

Temporary buffer large enough for at least one raw object id.

private ByteWindow
Inherited from org.eclipse.jgit.lib.ObjectReader:
OBJ_ANYstreamFileThreshold

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

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.

pack-priv int

Returns:

number of bytes actually copied; this may be less than cnt if cnt exceeded the number of bytes available.
copy
(final Pack
the file the desired window is stored within.
pack
,
long
position within the file to read from.
position
,
final byte[]
destination buffer to copy into.
dstbuf
,
int
offset within dstbuf to start copying into.
dstoff
,
final int
number of bytes to copy. This value may exceed the number of bytes remaining in the window starting at offset position.
cnt
)

Copy bytes from the window to a caller supplied buffer.

public void
copyObjectAsIs(PackOutputStream
stream the object should be written to.
out
,
ObjectToPack
the object's saved representation information.
otp
,
boolean
if true the representation must be validated and not be corrupt before being reused. If false, validation may be skipped as it will be performed elsewhere in the processing pipeline.
validate
)

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.copyObjectAsIs.

Output a previously selected representation.

public void
copyPackAsIs(PackOutputStream
stream to append the pack onto.
out
,
CachedPack
the cached pack to send.
pack
)

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.copyPackAsIs.

Append an entire pack's contents onto the output stream.

pack-priv void
copyPackAsIs(final Pack pack, final long length, final PackOutputStream out)

public BitmapIndex
getBitmapIndex()

Overrides org.eclipse.jgit.lib.ObjectReader.getBitmapIndex.

An index that can be used to speed up ObjectWalks.

public Collection<CachedPack>
getCachedPacksAndUpdate(BitmapIndex.BitmapBuilder
the bitmap that contains all of the objects the client wants.
needBitmap
)

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.getCachedPacksAndUpdate.

Obtain the available cached packs that match the bitmap and update the bitmap by removing the items that are in the CachedPack.

public Optional<CommitGraph>
getCommitGraph()

Overrides org.eclipse.jgit.lib.ObjectReader.getCommitGraph.

Get the commit-graph for this repository if available.

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()

pack-priv DeltaBaseCache
public long
getObjectSize(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
)

Overrides org.eclipse.jgit.lib.ObjectReader.getObjectSize.

Get only the size of an object.

public Set<ObjectId>
getShallowCommits()

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

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

public boolean
has(AnyObjectId
identity of the object to test for existence of.
objectId
)

Overrides org.eclipse.jgit.lib.ObjectReader.has.

Does the requested object exist in this database?

pack-priv int

Returns:

number of bytes inflated into dstbuf.
inflate
(final Pack
the file the desired window is stored within.
pack
,
long
position within the file to read from.
position
,
final byte[]
destination buffer the inflater should output decompressed data to. Must be large enough to store the entire stream, unless headerOnly is true.
dstbuf
,
boolean
if true the caller wants only dstbuf.length bytes.
headerOnly
)

Inflate a region of the pack starting at position.

pack-priv Inflater
public LocalObjectToPack
newObjectToPack(AnyObjectId
the id of the object that will be packed.
objectId
,
int
the Git type of the object that will be packed.
type
)

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.newObjectToPack.

Allocate a new PackWriter state structure for an object.

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.

pack-priv void
pin(Pack pack, long position)

private void
pack-priv ByteArrayWindow
quickCopy(Pack p, long pos, long cnt)

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.

public void
selectObjectRepresentation(PackWriter
the packer that will write the object in the near future.
packer
,
ProgressMonitor
progress monitor, implementation should update the monitor once for each item in the iteration when selection is done.
monitor
,
Iterable<ObjectToPack>
the objects that are being packed.
objects
)

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.selectObjectRepresentation.

Select the best object representation for a packer.

public void
writeObjects(PackOutputStream
the stream to write each object to.
out
,
List<ObjectToPack>
the list of objects to write. Objects should be written in approximately this order. Implementors may resort the list elements in-place during writing if desired.
list
)

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.writeObjects.

Write objects to the pack stream in roughly the order given.

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

Field Detail

baseCacheback to summary
private DeltaBaseCache baseCache
createdFromInserterback to summary
private final ObjectInserter createdFromInserter
Annotations
@Nullable
dbback to summary
pack-priv final FileObjectDatabase db
infback to summary
private Inflater inf
tempIdback to summary
pack-priv final byte[] tempId

Temporary buffer large enough for at least one raw object id.

windowback to summary
private ByteWindow window

Constructor Detail

WindowCursorback to summary
pack-priv WindowCursor(FileObjectDatabase db)
WindowCursorback to summary
pack-priv WindowCursor(FileObjectDatabase db, ObjectDirectoryInserter createdFromInserter)

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.

Release the current window cursor.

Annotations
@Override
copyback to summary
pack-priv int copy(final Pack pack, long position, final byte[] dstbuf, int dstoff, final int cnt) throws IOException

Copy bytes from the window to a caller supplied buffer.

Parameters
pack:Pack

the file the desired window is stored within.

position:long

position within the file to read from.

dstbuf:byte[]

destination buffer to copy into.

dstoff:int

offset within dstbuf to start copying into.

cnt:int

number of bytes to copy. This value may exceed the number of bytes remaining in the window starting at offset position.

Returns:int

number of bytes actually copied; this may be less than cnt if cnt exceeded the number of bytes available.

Exceptions
IOException:
this cursor does not match the provider or id and the proper window could not be acquired through the provider's cache.
copyObjectAsIsback to summary
public void copyObjectAsIs(PackOutputStream out, ObjectToPack otp, boolean validate) throws IOException, StoredObjectRepresentationNotAvailableException

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.copyObjectAsIs.

Doc from org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.copyObjectAsIs.

Output a previously selected representation.

PackWriter invokes this method only if a representation previously given to it by selectObjectRepresentation was chosen for reuse into the output stream. The otp argument is an instance created by this reader's own newObjectToPack, and the representation data saved within it also originated from this reader.

Implementors must write the object header before copying the raw data to the output stream. The typical implementation is like:

MyToPack mtp = (MyToPack) otp;
byte[] raw;
if (validate)
	 raw = validate(mtp); // throw SORNAE here, if at all
else
	 raw = readFast(mtp);
out.writeHeader(mtp, mtp.inflatedSize);
out.write(raw);
Parameters
out:PackOutputStream

stream the object should be written to.

otp:ObjectToPack

the object's saved representation information.

validate:boolean

if true the representation must be validated and not be corrupt before being reused. If false, validation may be skipped as it will be performed elsewhere in the processing pipeline.

Annotations
@Override
Exceptions
IOException:
the stream's write method threw an exception. Packing will abort.
StoredObjectRepresentationNotAvailableException:
the previously selected representation is no longer available. If thrown before out.writeHeader the pack writer will try to find another representation, and write that one instead. If throw after out.writeHeader, packing will abort.
copyPackAsIsback to summary
public void copyPackAsIs(PackOutputStream out, CachedPack pack) throws IOException

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.copyPackAsIs.

Doc from org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.copyPackAsIs.

Append an entire pack's contents onto the output stream.

The entire pack, excluding its header and trailing footer is sent.

Parameters
out:PackOutputStream

stream to append the pack onto.

pack:CachedPack

the cached pack to send.

Annotations
@Override
Exceptions
IOException:
the pack cannot be read, or stream did not accept a write.
copyPackAsIsback to summary
pack-priv void copyPackAsIs(final Pack pack, final long length, final PackOutputStream out) throws IOException
getBitmapIndexback to summary
public BitmapIndex getBitmapIndex() throws IOException

Overrides org.eclipse.jgit.lib.ObjectReader.getBitmapIndex.

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

An index that can be used to speed up ObjectWalks.

Returns:BitmapIndex

the index or null if one does not exist.

Annotations
@Override
Exceptions
IOException:
when the index fails to load
getCachedPacksAndUpdateback to summary
public Collection<CachedPack> getCachedPacksAndUpdate(BitmapIndex.BitmapBuilder needBitmap) throws IOException

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.getCachedPacksAndUpdate.

Doc from org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.getCachedPacksAndUpdate.

Obtain the available cached packs that match the bitmap and update the bitmap by removing the items that are in the CachedPack.

A cached pack has known starting points and may be sent entirely as-is, with almost no effort on the sender's part.

Parameters
needBitmap:BitmapIndex.BitmapBuilder

the bitmap that contains all of the objects the client wants.

Returns:Collection<CachedPack>

the available cached packs.

Annotations
@Override
Exceptions
IOException:
the cached packs cannot be listed from the repository. Callers may choose to ignore this and continue as-if there were no cached packs.
getCommitGraphback to summary
public Optional<CommitGraph> getCommitGraph()

Overrides org.eclipse.jgit.lib.ObjectReader.getCommitGraph.

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

Get the commit-graph for this repository if available.

The commit graph can be created/modified/deleted while the repository is open and specific implementations decide when to refresh it.

Returns:Optional<CommitGraph>

the commit-graph or empty if the commit-graph does not exist or is invalid; always returns empty when core.commitGraph is false (default is false).

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
@Nullable
getDeltaBaseCacheback to summary
pack-priv DeltaBaseCache getDeltaBaseCache()
getObjectSizeback to summary
public long getObjectSize(AnyObjectId objectId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, IOException

Overrides org.eclipse.jgit.lib.ObjectReader.getObjectSize.

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

Get only the size of an object.

The default implementation of this method opens an ObjectLoader. Databases are encouraged to override this if a faster access method is available to them.

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:long

size of object in bytes.

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.
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
hasback to summary
public boolean has(AnyObjectId objectId) throws IOException

Overrides org.eclipse.jgit.lib.ObjectReader.has.

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

Does the requested object exist in this database?

Parameters
objectId:AnyObjectId

identity of the object to test for existence of.

Returns:boolean

true if the specified object is stored in this database.

Annotations
@Override
Exceptions
IOException:
the object store cannot be accessed.
inflateback to summary
pack-priv int inflate(final Pack pack, long position, final byte[] dstbuf, boolean headerOnly) throws IOException, DataFormatException

Inflate a region of the pack starting at position.

Parameters
pack:Pack

the file the desired window is stored within.

position:long

position within the file to read from.

dstbuf:byte[]

destination buffer the inflater should output decompressed data to. Must be large enough to store the entire stream, unless headerOnly is true.

headerOnly:boolean

if true the caller wants only dstbuf.length bytes.

Returns:int

number of bytes inflated into dstbuf.

Exceptions
IOException:
this cursor does not match the provider or id and the proper window could not be acquired through the provider's cache.
DataFormatException:
the inflater encountered an invalid chunk of data. Data stream corruption is likely.
inflaterback to summary
pack-priv Inflater inflater()
newObjectToPackback to summary
public LocalObjectToPack newObjectToPack(AnyObjectId objectId, int type)

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.newObjectToPack.

Doc from org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.newObjectToPack.

Allocate a new PackWriter state structure for an object.

org.eclipse.jgit.internal.storage.pack.PackWriter allocates these objects to keep track of the per-object state, and how to load the objects efficiently into the generated stream. Implementers may subclass this type with additional object state, such as to remember what file and offset contains the object's pack encoded data.

Parameters
objectId:AnyObjectId

the id of the object that will be packed.

type:int

the Git type of the object that will be packed.

Returns:LocalObjectToPack

a new instance for this object.

Annotations
@Override
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.
pinback to summary
pack-priv void pin(Pack pack, long position) throws IOException
prepareInflaterback to summary
private void prepareInflater()
quickCopyback to summary
pack-priv ByteArrayWindow quickCopy(Pack p, long pos, long cnt) throws IOException
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.
selectObjectRepresentationback to summary
public void selectObjectRepresentation(PackWriter packer, ProgressMonitor monitor, Iterable<ObjectToPack> objects) throws IOException, MissingObjectException

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.selectObjectRepresentation.

Doc from org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.selectObjectRepresentation.

Select the best object representation for a packer.

Implementations should iterate through all available representations of an object, and pass them in turn to the PackWriter though org.eclipse.jgit.internal.storage.pack.PackWriter#select(ObjectToPack, StoredObjectRepresentation) so the writer can select the most suitable representation to reuse into the output stream.

If the implementation returns CachedPack from getCachedPacksAndUpdate(BitmapBuilder) it must consider the representation of any object that is stored in any of the offered CachedPacks. PackWriter relies on this behavior to prune duplicate objects out of the pack stream when it selects a CachedPack and the object was also reached through the thin-pack enumeration.

The implementation may choose to consider multiple objects at once on concurrent threads, but must evaluate all representations of an object within the same thread.

Parameters
packer:PackWriter

the packer that will write the object in the near future.

monitor:ProgressMonitor

progress monitor, implementation should update the monitor once for each item in the iteration when selection is done.

objects:Iterable<ObjectToPack>

the objects that are being packed.

Annotations
@Override
Exceptions
IOException:
the repository cannot be accessed. Packing will abort.
MissingObjectException:
there is no representation available for the object, as it is no longer in the repository. Packing will abort.
writeObjectsback to summary
public void writeObjects(PackOutputStream out, List<ObjectToPack> list) throws IOException

Implements org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.writeObjects.

Doc from org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs.writeObjects.

Write objects to the pack stream in roughly the order given. PackWriter invokes this method to write out one or more objects, in approximately the order specified by the iteration over the list. A simple implementation of this method would just iterate the list and output each object:

for (ObjectToPack obj : list)
  out.writeObject(obj)
However more sophisticated implementors may try to perform some (small) reordering to access objects that are stored close to each other at roughly the same time. Implementations may choose to write objects out of order, but this may increase pack file size due to using a larger header format to reach a delta base that is later in the stream. It may also reduce data locality for the reader, slowing down data access. Invoking org.eclipse.jgit.internal.storage.pack.PackOutputStream#writeObject(ObjectToPack) will cause copyObjectAsIs(PackOutputStream, ObjectToPack, boolean) to be invoked recursively on this if the current object is scheduled for reuse.
Parameters
out:PackOutputStream

the stream to write each object to.

list:List<ObjectToPack>

the list of objects to write. Objects should be written in approximately this order. Implementors may resort the list elements in-place during writing if desired.

Annotations
@Override
Exceptions
IOException:
the stream cannot be written to, or one or more required objects cannot be accessed from the object database.