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

public abstract Class PackObjectSizeIndexWriter

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter.PackObjectSizeWriterV1
Imports
java.io.BufferedOutputStream, .IOException, .OutputStream, java.util.List, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.Constants, org.eclipse.jgit.transport.PackedObjectInfo, org.eclipse.jgit.util.NB

Write an object index in the output stream

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
protected static final byte[]
HEADER

Magic constant for the object size index file

private static final int
private static final PackObjectSizeIndexWriter

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static PackObjectSizeIndexWriter

Returns:

the index writer
createWriter
(OutputStream
Output stream where to write the index
os
,
int
objects strictly smaller than this size won't be added to the index. Negative size won't write AT ALL. Other sizes could write an empty index.
minSize
)

Returns a writer for the latest index version

public abstract void
write(List<? extends PackedObjectInfo>
objects in the pack, in sha1 order. Their position in the list matches their position in the primary index.
objs
)

Add the objects to the index

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MAX_24BITS_UINTback to summary
private static final int MAX_24BITS_UINT
NULL_WRITERback to summary
private static final PackObjectSizeIndexWriter NULL_WRITER

Constructor Detail

PackObjectSizeIndexWriterback to summary
public PackObjectSizeIndexWriter()

Method Detail

createWriterback to summary
public static PackObjectSizeIndexWriter createWriter(OutputStream os, int minSize)

Returns a writer for the latest index version

Parameters
os:OutputStream

Output stream where to write the index

minSize:int

objects strictly smaller than this size won't be added to the index. Negative size won't write AT ALL. Other sizes could write an empty index.

Returns:PackObjectSizeIndexWriter

the index writer

writeback to summary
public abstract void write(List<? extends PackedObjectInfo> objs) throws IOException

Add the objects to the index

Parameters
objs:List<? extends PackedObjectInfo>

objects in the pack, in sha1 order. Their position in the list matches their position in the primary index.

Exceptions
IOException:
problem writing to the stream
org.eclipse.jgit.internal.storage.file back to summary

pack-priv Class PackObjectSizeIndexWriter.PackObjectSizeWriterV1

extends PackObjectSizeIndexWriter
Class Inheritance

Object size index v1. Store position (in the main index) to size as parallel arrays.

Positions in the main index fit well in unsigned 24 bits (16M) for most repositories, but some outliers have even more objects, so we need to store also 32 bits positions.

Sizes are stored as a first array parallel to positions. If a size doesn't fit in an element of that array, then we encode there a position on the next-size array. This "overflow" array doesn't have entries for all positions.


     positions       [10, 500, 1000, 1001]
     sizes (32bits)  [15MB, -1, 6MB, -2]
                         ___/  ______/
                       /     /
     sizes (64 bits) [3GB, 6GB]

For sizes we use 32 bits as the first level and 64 for the rare objects over 2GB.

A 24/32/64 bits hierarchy of arrays saves space if we have a lot of small objects, but wastes space if we have only big ones. The min size to index is controlled by conf and in principle we want to index only rather big objects (e.g. > 10MB). We could support more dynamics read/write of sizes (e.g. 24 only if the threshold will include many of those objects) but it complicates a lot code and spec. If needed it could go for a v2 of the protocol.

Format:

(if count == 0, stop here)

Blocks of

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
private static class

Field Summary

Modifier and TypeField and Description
private final byte[]
private final int
private final OutputStream
Inherited from org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter:
HEADER

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static void
applyToRange(int[] allPositions, int start, int end, PackObjectSizeIndexWriter.PackObjectSizeWriterV1.IntEncoder encoder)

private PackObjectSizeIndexWriter.PackObjectSizeWriterV1.PackedObjectStats
private int[]
findIndexablePositions(List<? extends PackedObjectInfo> allObjects, int indexableObjs)

private boolean
public void
write(List<? extends PackedObjectInfo>
objects in the pack, in sha1 order. Their position in the list matches their position in the primary index.
allObjects
)

Implements abstract org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter.write.

Add the objects to the index

private void
writeInt24(int i)

private void
writeInt32(int i)

private void
writeSizes(List<? extends PackedObjectInfo> allObjects, int[] indexablePositions, int objsBiggerThan2Gb)

private void
writeUInt8(int i)

Inherited from org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter:
createWriter

Field Detail

intBufferback to summary
private final byte[] intBuffer
minObjSizeback to summary
private final int minObjSize
osback to summary
private final OutputStream os

Constructor Detail

PackObjectSizeWriterV1back to summary
pack-priv PackObjectSizeWriterV1(OutputStream os, int minSize)

Method Detail

applyToRangeback to summary
private static void applyToRange(int[] allPositions, int start, int end, PackObjectSizeIndexWriter.PackObjectSizeWriterV1.IntEncoder encoder) throws IOException
countIndexableObjectsback to summary
private PackObjectSizeIndexWriter.PackObjectSizeWriterV1.PackedObjectStats countIndexableObjects(List<? extends PackedObjectInfo> objs)
findIndexablePositionsback to summary
private int[] findIndexablePositions(List<? extends PackedObjectInfo> allObjects, int indexableObjs)
shouldIndexback to summary
private boolean shouldIndex(PackedObjectInfo o)
writeback to summary
public void write(List<? extends PackedObjectInfo> allObjects) throws IOException

Implements abstract org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter.write.

Doc from org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter.write.

Add the objects to the index

Parameters
allObjects:List<? extends PackedObjectInfo>

objects in the pack, in sha1 order. Their position in the list matches their position in the primary index.

Annotations
@Override
Exceptions
IOException:
problem writing to the stream
writeInt24back to summary
private void writeInt24(int i) throws IOException
writeInt32back to summary
private void writeInt32(int i) throws IOException
writeSizesback to summary
private void writeSizes(List<? extends PackedObjectInfo> allObjects, int[] indexablePositions, int objsBiggerThan2Gb) throws IOException
writeUInt8back to summary
private void writeUInt8(int i) throws IOException
org.eclipse.jgit.internal.storage.file back to summary

pack-priv Interface PackObjectSizeIndexWriter.PackObjectSizeWriterV1.IntEncoder

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public void
encode(int i)

Method Detail

encodeback to summary
public void encode(int i) throws IOException
org.eclipse.jgit.internal.storage.file back to summary

private Class PackObjectSizeIndexWriter.PackObjectSizeWriterV1.PackedObjectStats

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter.PackObjectSizeWriterV1.PackedObjectStats

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int
pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
private

Field Detail

indexableObjsback to summary
pack-priv int indexableObjs
pos24Bitsback to summary
pack-priv int pos24Bits
pos31Bitsback to summary
pack-priv int pos31Bits
sizeOver2GBback to summary
pack-priv int sizeOver2GB

Constructor Detail

PackedObjectStatsback to summary
private PackedObjectStats()