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

public Class MultiPackIndexWriter

extends Object
Class Inheritance
Static Imports
org.eclipse.jgit.internal.storage.midx.MultiPackIndexConstants.CHUNK_LOOKUP_WIDTH, .MultiPackIndexConstants.MIDX_CHUNKID_LARGEOFFSETS, .MultiPackIndexConstants.MIDX_CHUNKID_OBJECTOFFSETS, .MultiPackIndexConstants.MIDX_CHUNKID_OIDFANOUT, .MultiPackIndexConstants.MIDX_CHUNKID_OIDLOOKUP, .MultiPackIndexConstants.MIDX_CHUNKID_PACKNAMES, .MultiPackIndexConstants.MIDX_CHUNKID_REVINDEX, .MultiPackIndexConstants.MIDX_SIGNATURE, .MultiPackIndexConstants.MIDX_VERSION, .MultiPackIndexConstants.MULTIPACK_INDEX_FANOUT_SIZE, .MultiPackIndexConstants.OID_HASH_VERSION, org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH

Writes a collection of indexes as a multipack index.

See multipack index format spec

Since
7.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
private static interface
private static class
private static record
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static long
private List<MultiPackIndexWriter.ChunkHeader>
private static boolean

Returns:

true if the offset fits in 31 bits
fitsIn31bits
(long
object offset
offset
)

If there is at least one offset value larger than 2^32-1, then the large offset chunk must exist, and offsets larger than 2^31-1 must be stored in it instead

public void
write(ProgressMonitor
progress monitor
monitor
,
OutputStream
stream to write the multipack index file
outputStream
,
Map<String, PackIndex>
pairs of name and index for each pack to include in the multipack index.
inputs
)

Writes the inputs in the multipack index format in the outputStream.

private void
writeCheckSum(CancellableDigestOutputStream
output stream used to write
out
)

Write final checksum of the data written to the stream

private void
writeChunkLookup(CancellableDigestOutputStream
output stream to write
out
,
List<MultiPackIndexWriter.ChunkHeader>
list of chunks in the order they are expected to be written
chunkHeaders
)

Write a table of "chunkId, start-offset", with a special value "0, end-of-previous_chunk", to mark the end.

private void
writeFanoutTable(MultiPackIndexWriter.WriteContext
write context
ctx
)

Write the fanout table for the object ids

Table with 256 entries (one byte), where the ith entry, F[i], stores the number of OIDs with first byte at most i.

private void
writeHeader(CancellableDigestOutputStream
output stream to write
out
,
int
number of chunks this multipack index is going to have
numChunks
,
int
number of packs covered by this multipack index
packCount
)

Write the first 12 bytes of the multipack index.

private void
writeObjectLargeOffsets(MultiPackIndexWriter.WriteContext
writer context
ctx
)

Write the large offset chunk

A list of large offsets (long).

private void
writeObjectOffsets(MultiPackIndexWriter.WriteContext
write context
ctx
)

Write the object offsets chunk

A list of offsets, parallel to the list of OIDs.

private void
writeOidLookUp(MultiPackIndexWriter.WriteContext
write context
ctx
)

Write the OID lookup chunk

A list of OIDs in sha1 order.

private void
writePackfileNames(MultiPackIndexWriter.WriteContext
writer context
ctx
)

Write the list of packfiles chunk

List of packfiles (in lexicographical order) with an \0 at the end

private void
writeRidx(MultiPackIndexWriter.WriteContext
write context
ctx
)

Writes the reverse index chunk

This stores the position of the objects in the main index, ordered first by pack and then by offset

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LIMIT_31_BITSback to summary
private static final int LIMIT_31_BITS
MIDX_HEADER_SIZEback to summary
private static final int MIDX_HEADER_SIZE

Constructor Detail

MultiPackIndexWriterback to summary
public MultiPackIndexWriter()

Method Detail

calculateExpectedSizeback to summary
private static long calculateExpectedSize(List<MultiPackIndexWriter.ChunkHeader> chunks)
createChunkHeadersback to summary
private List<MultiPackIndexWriter.ChunkHeader> createChunkHeaders(PackIndexMerger data)
fitsIn31bitsback to summary
private static boolean fitsIn31bits(long offset)

If there is at least one offset value larger than 2^32-1, then the large offset chunk must exist, and offsets larger than 2^31-1 must be stored in it instead

Parameters
offset:long

object offset

Returns:boolean

true if the offset fits in 31 bits

writeback to summary
public void write(ProgressMonitor monitor, OutputStream outputStream, Map<String, PackIndex> inputs) throws IOException

Writes the inputs in the multipack index format in the outputStream.

Parameters
monitor:ProgressMonitor

progress monitor

outputStream:OutputStream

stream to write the multipack index file

inputs:Map<String, PackIndex>

pairs of name and index for each pack to include in the multipack index.

Exceptions
IOException:
Error writing to the stream
writeCheckSumback to summary
private void writeCheckSum(CancellableDigestOutputStream out) throws IOException

Write final checksum of the data written to the stream

Parameters
out:CancellableDigestOutputStream

output stream used to write

Exceptions
IOException:
error writing to the output stream
writeChunkLookupback to summary
private void writeChunkLookup(CancellableDigestOutputStream out, List<MultiPackIndexWriter.ChunkHeader> chunkHeaders) throws IOException

Write a table of "chunkId, start-offset", with a special value "0, end-of-previous_chunk", to mark the end.

Parameters
out:CancellableDigestOutputStream

output stream to write

chunkHeaders:List<MultiPackIndexWriter.ChunkHeader>

list of chunks in the order they are expected to be written

Exceptions
IOException:
error writing to the output stream
writeFanoutTableback to summary
private void writeFanoutTable(MultiPackIndexWriter.WriteContext ctx) throws IOException

Write the fanout table for the object ids

Table with 256 entries (one byte), where the ith entry, F[i], stores the number of OIDs with first byte at most i. Thus, F[255] stores the total number of objects.

Parameters
ctx:MultiPackIndexWriter.WriteContext

write context

Exceptions
IOException:
error writing to the output stream
writeHeaderback to summary
private void writeHeader(CancellableDigestOutputStream out, int numChunks, int packCount) throws IOException

Write the first 12 bytes of the multipack index.

These bytes include things like magic number, version, number of chunks...

Parameters
out:CancellableDigestOutputStream

output stream to write

numChunks:int

number of chunks this multipack index is going to have

packCount:int

number of packs covered by this multipack index

Exceptions
IOException:
error writing to the output stream
writeObjectLargeOffsetsback to summary
private void writeObjectLargeOffsets(MultiPackIndexWriter.WriteContext ctx) throws IOException

Write the large offset chunk

A list of large offsets (long). The regular offset chunk will point to a position here.

Parameters
ctx:MultiPackIndexWriter.WriteContext

writer context

Exceptions
IOException:
error writing to the output stream
writeObjectOffsetsback to summary
private void writeObjectOffsets(MultiPackIndexWriter.WriteContext ctx) throws IOException

Write the object offsets chunk

A list of offsets, parallel to the list of OIDs. If the offset is too large (see fitsIn31bits(long)), this contains the position in the large offsets list (marked with a 1 in the most significant bit).

Parameters
ctx:MultiPackIndexWriter.WriteContext

write context

Exceptions
IOException:
error writing to the output stream
writeOidLookUpback to summary
private void writeOidLookUp(MultiPackIndexWriter.WriteContext ctx) throws IOException

Write the OID lookup chunk

A list of OIDs in sha1 order.

Parameters
ctx:MultiPackIndexWriter.WriteContext

write context

Exceptions
IOException:
error writing to the output stream
writePackfileNamesback to summary
private void writePackfileNames(MultiPackIndexWriter.WriteContext ctx) throws IOException

Write the list of packfiles chunk

List of packfiles (in lexicographical order) with an \0 at the end

Parameters
ctx:MultiPackIndexWriter.WriteContext

writer context

Exceptions
IOException:
error writing to the output stream
writeRidxback to summary
private void writeRidx(MultiPackIndexWriter.WriteContext ctx) throws IOException

Writes the reverse index chunk

This stores the position of the objects in the main index, ordered first by pack and then by offset

Parameters
ctx:MultiPackIndexWriter.WriteContext

write context

Exceptions
IOException:
erorr writing to the output stream
org.eclipse.jgit.internal.storage.midx back to summary

private final Record MultiPackIndexWriter.ChunkHeader

extends Record
Class Inheritance
Record Components
chunkId:int 
size:long 
writerFn:MultiPackIndexWriter.ChunkWriter 

Field Summary

Modifier and TypeField and Description
private final int
chunkId

Record Component accessed by chunkId().

private final long
size

Record Component accessed by size().

private final MultiPackIndexWriter.ChunkWriter
writerFn

Record Component accessed by writerFn().

Constructor Summary

AccessConstructor and Description
private
ChunkHeader(int chunkId, long size, MultiPackIndexWriter.ChunkWriter writerFn)

Method Summary

Modifier and TypeMethod and Description
public int
chunkId()

Record Component getter of chunkId.

public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public long
size()

Record Component getter of size.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

public MultiPackIndexWriter.ChunkWriter
writerFn()

Record Component getter of writerFn.

Field Detail

chunkIdback to summary
private final int chunkId

Record Component accessed by chunkId().

sizeback to summary
private final long size

Record Component accessed by size().

writerFnback to summary
private final MultiPackIndexWriter.ChunkWriter writerFn

Record Component accessed by writerFn().

Constructor Detail

ChunkHeaderback to summary
private ChunkHeader(int chunkId, long size, MultiPackIndexWriter.ChunkWriter writerFn)

Method Detail

chunkIdback to summary
public int chunkId()

Record Component getter of chunkId.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

sizeback to summary
public long size()

Record Component getter of size.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.

writerFnback to summary
public MultiPackIndexWriter.ChunkWriter writerFn()

Record Component getter of writerFn.

org.eclipse.jgit.internal.storage.midx back to summary

private Interface MultiPackIndexWriter.ChunkWriter

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public void

Method Detail

writeback to summary
public void write(MultiPackIndexWriter.WriteContext ctx) throws IOException
org.eclipse.jgit.internal.storage.midx back to summary

private Class MultiPackIndexWriter.LargeOffsets

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.midx.MultiPackIndexWriter.LargeOffsets

Field Summary

Modifier and TypeField and Description
private int
private final byte[]

Constructor Summary

AccessConstructor and Description
pack-priv
LargeOffsets(int largeOffsetsCount)

Method Summary

Modifier and TypeMethod and Description
pack-priv int

Returns:

the position of the just inserted offset (as in number of offsets, NOT in bytes)
append
(long
a large offset
largeOffset
)

Add an offset to the large offset chunk

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bytePositionback to summary
private int bytePosition
offsetsback to summary
private final byte[] offsets

Constructor Detail

LargeOffsetsback to summary
pack-priv LargeOffsets(int largeOffsetsCount)

Method Detail

appendback to summary
pack-priv int append(long largeOffset)

Add an offset to the large offset chunk

Parameters
largeOffset:long

a large offset

Returns:int

the position of the just inserted offset (as in number of offsets, NOT in bytes)

org.eclipse.jgit.internal.storage.midx back to summary

private final Record MultiPackIndexWriter.OffsetPosition

extends Record
Class Inheritance
Record Components
offset:long 
position:int 

Field Summary

Modifier and TypeField and Description
private final long
offset

Record Component accessed by offset().

private final int
position

Record Component accessed by position().

Constructor Summary

AccessConstructor and Description
private
OffsetPosition(long offset, int position)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public long
offset()

Record Component getter of offset.

public int
position()

Record Component getter of position.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

offsetback to summary
private final long offset

Record Component accessed by offset().

positionback to summary
private final int position

Record Component accessed by position().

Constructor Detail

OffsetPositionback to summary
private OffsetPosition(long offset, int position)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

offsetback to summary
public long offset()

Record Component getter of offset.

positionback to summary
public int position()

Record Component getter of position.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.

org.eclipse.jgit.internal.storage.midx back to summary

private Class MultiPackIndexWriter.WriteContext

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.midx.MultiPackIndexWriter.WriteContext

Field Summary

Modifier and TypeField and Description
pack-priv final PackIndexMerger
pack-priv final MultiPackIndexWriter.LargeOffsets
pack-priv final CancellableDigestOutputStream

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databack to summary
pack-priv final PackIndexMerger data
largeOffsetsback to summary
pack-priv final MultiPackIndexWriter.LargeOffsets largeOffsets
outback to summary
pack-priv final CancellableDigestOutputStream out

Constructor Detail

WriteContextback to summary
pack-priv WriteContext(CancellableDigestOutputStream out, PackIndexMerger data)