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

public Class ReftableWriter

extends Object
Class Inheritance
Static Imports
java.lang.Math.log, java.nio.charset.StandardCharsets.UTF_8, org.eclipse.jgit.internal.storage.reftable.BlockWriter.padBetweenBlocks, .ReftableConstants.FILE_FOOTER_LEN, .ReftableConstants.FILE_HEADER_LEN, .ReftableConstants.FILE_HEADER_MAGIC, .ReftableConstants.INDEX_BLOCK_TYPE, .ReftableConstants.LOG_BLOCK_TYPE, .ReftableConstants.MAX_BLOCK_SIZE, .ReftableConstants.MAX_RESTARTS, .ReftableConstants.OBJ_BLOCK_TYPE, .ReftableConstants.REF_BLOCK_TYPE, .ReftableConstants.VERSION_1, org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH

Writes a reftable formatted file.

A reftable can be written in a streaming fashion, provided the caller sorts all references. A org.eclipse.jgit.internal.storage.reftable.ReftableWriter is single-use, and not thread-safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class
private class
public static class
ReftableWriter.Stats

Statistics about a written reftable.

Field Summary

Modifier and TypeField and Description
private boolean
private ReftableConfig
private BlockWriter
private boolean
private BlockWriter.Entry
private BlockWriter.Entry
private int
private ReftableWriter.Section
private int
private long
private long
private ObjectIdSubclassMap<ReftableWriter.RefList>
private int
private ReftableWriter.Section
private ReftableOutputStream
private OutputStream
private int
private ReftableWriter.Section
private int
private ReftableWriter.Stats

Constructor Summary

AccessConstructor and Description
public
ReftableWriter(OutputStream
output stream.
os
)

Initialize a writer with a default configuration.

public
ReftableWriter(ReftableConfig
configuration for the writer
cfg
,
OutputStream
output stream.
os
)

Initialize a writer with a configuration.

Method Summary

Modifier and TypeMethod and Description
public ReftableWriter

Returns:

this
begin
()

Begin writing the reftable.

private void
public void
deleteLog(String
the ref to delete (hide) a reflog entry from.
ref
,
long
the update index that must be hidden.
updateIndex
)

Record deletion of one reflog entry in this reftable.

private void
encodeHeader(byte[] hdr)

public long

Returns:

an estimate of the current size in bytes of the reftable, if it was finished right now. Estimate is only accurate if org.eclipse.jgit.internal.storage.reftable.ReftableConfig#setIndexObjects(boolean) is false and org.eclipse.jgit.internal.storage.reftable.ReftableConfig#setMaxIndexLevels(int) is 1.
estimateTotalBytes
()

Get an estimate of the current size in bytes of the reftable

public ReftableWriter

Returns:

this
finish
()

Finish writing the reftable by writing its trailer.

private void
private void
private static long
public ReftableWriter.Stats

Returns:

statistics of the last written reftable.
getStats
()

Get statistics of the last written reftable.

private void
indexId(ObjectId id, long blockPos)

private static long
private void
indexRef(Ref ref, long blockPos)

public ReftableWriter

Returns:

this
setConfig
(ReftableConfig
configuration for the writer.
cfg
)

Set configuration for the writer.

public ReftableWriter

Returns:

this
setMaxUpdateIndex
(long
the maximum update index for log entries that appear in this reftable. This should be at least 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.
max
)

Set the maximum update index for log entries that appear in this reftable.

public ReftableWriter

Returns:

this
setMinUpdateIndex
(long
the minimum update index for log entries that appear in this reftable. This should be 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.
min
)

Set the minimum update index for log entries that appear in this reftable.

private static int
private boolean
public ReftableWriter

Returns:

this
sortAndWriteRefs
(Collection<Ref>
references to sort and write.
refsToPack
)

Sort a collection of references and write them to the reftable.

private static List<ReftableWriter.RefList>
private void
private void
private void
public void
writeLog(String
name of the reference.
ref
,
long
identifier of the transaction that created the log record. The updateIndex must be unique within the scope of ref, and must be within the bounds defined by minUpdateIndex <= updateIndex <= maxUpdateIndex.
updateIndex
,
PersonIdent
committer of the reflog entry.
who
,
ObjectId
prior id; pass org.eclipse.jgit.lib.ObjectId#zeroId() for creations.
oldId
,
ObjectId
new id; pass org.eclipse.jgit.lib.ObjectId#zeroId() for deletions.
newId
,
String
optional message (may be null).
message
)

Write one reflog entry to the reftable.

private void
public void
writeRef(Ref
the reference to store.
ref
)

Write one reference to the reftable.

public void
writeRef(Ref
the reference to store.
ref
,
long
the updateIndex that modified this reference. Must be >= minUpdateIndex for this file.
updateIndex
)

Write one reference to the reftable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

alignBlocksback to summary
private boolean alignBlocks
configback to summary
private ReftableConfig config
curback to summary
private BlockWriter cur
indexObjectsback to summary
private boolean indexObjects
lastLogback to summary
private BlockWriter.Entry lastLog
lastRefback to summary
private BlockWriter.Entry lastRef
logBlockSizeback to summary
private int logBlockSize
logsback to summary
private ReftableWriter.Section logs
maxIndexLevelsback to summary
private int maxIndexLevels
maxUpdateIndexback to summary
private long maxUpdateIndex
minUpdateIndexback to summary
private long minUpdateIndex
obj2refback to summary
private ObjectIdSubclassMap<ReftableWriter.RefList> obj2ref
objIdLenback to summary
private int objIdLen
objsback to summary
private ReftableWriter.Section objs
outback to summary
private ReftableOutputStream out
outputStreamback to summary
private OutputStream outputStream
refBlockSizeback to summary
private int refBlockSize
refsback to summary
private ReftableWriter.Section refs
restartIntervalback to summary
private int restartInterval
statsback to summary
private ReftableWriter.Stats stats

Constructor Detail

ReftableWriterback to summary
public ReftableWriter(OutputStream os)

Initialize a writer with a default configuration.

Parameters
os:OutputStream

output stream.

ReftableWriterback to summary
public ReftableWriter(ReftableConfig cfg, OutputStream os)

Initialize a writer with a configuration.

Parameters
cfg:ReftableConfig

configuration for the writer

os:OutputStream

output stream.

Method Detail

beginback to summary
public ReftableWriter begin()

Begin writing the reftable. Should be called only once. Call this if a stream was passed to the constructor.

Returns:ReftableWriter

this

beginLogback to summary
private void beginLog() throws IOException
deleteLogback to summary
public void deleteLog(String ref, long updateIndex) throws IOException

Record deletion of one reflog entry in this reftable.

The deletion can shadow an entry stored in a lower table in the stack. This is useful for refs/stash and dropping an entry from its reflog.

Deletion must be properly interleaved in sorted updateIndex order with any other logs written by writeLog(String, long, PersonIdent, ObjectId, ObjectId, String).

Parameters
ref:String

the ref to delete (hide) a reflog entry from.

updateIndex:long

the update index that must be hidden.

Exceptions
IOException:
if reftable cannot be written.
encodeHeaderback to summary
private void encodeHeader(byte[] hdr)
estimateTotalBytesback to summary
public long estimateTotalBytes()

Get an estimate of the current size in bytes of the reftable

Returns:long

an estimate of the current size in bytes of the reftable, if it was finished right now. Estimate is only accurate if org.eclipse.jgit.internal.storage.reftable.ReftableConfig#setIndexObjects(boolean) is false and org.eclipse.jgit.internal.storage.reftable.ReftableConfig#setMaxIndexLevels(int) is 1.

finishback to summary
public ReftableWriter finish() throws IOException

Finish writing the reftable by writing its trailer.

Returns:ReftableWriter

this

Exceptions
IOException:
if reftable cannot be written.
finishLogSectionback to summary
private void finishLogSection() throws IOException
finishRefAndObjSectionsback to summary
private void finishRefAndObjSections() throws IOException
firstBlockPositionback to summary
private static long firstBlockPosition(ReftableWriter.Section s)
getStatsback to summary
public ReftableWriter.Stats getStats()

Get statistics of the last written reftable.

Returns:ReftableWriter.Stats

statistics of the last written reftable.

indexIdback to summary
private void indexId(ObjectId id, long blockPos)
indexPositionback to summary
private static long indexPosition(ReftableWriter.Section s)
indexRefback to summary
private void indexRef(Ref ref, long blockPos)
setConfigback to summary
public ReftableWriter setConfig(ReftableConfig cfg)

Set configuration for the writer.

Parameters
cfg:ReftableConfig

configuration for the writer.

Returns:ReftableWriter

this

setMaxUpdateIndexback to summary
public ReftableWriter setMaxUpdateIndex(long max)

Set the maximum update index for log entries that appear in this reftable.

Parameters
max:long

the maximum update index for log entries that appear in this reftable. This should be at least 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.

Returns:ReftableWriter

this

setMinUpdateIndexback to summary
public ReftableWriter setMinUpdateIndex(long min)

Set the minimum update index for log entries that appear in this reftable.

Parameters
min:long

the minimum update index for log entries that appear in this reftable. This should be 1 higher than the prior reftable's maxUpdateIndex if this table will be used in a stack.

Returns:ReftableWriter

this

shortestUniqueAbbreviationback to summary
private static int shortestUniqueAbbreviation(List<ReftableWriter.RefList> in)
shouldHaveIndexback to summary
private boolean shouldHaveIndex(ReftableWriter.IndexBuilder idx)
sortAndWriteRefsback to summary
public ReftableWriter sortAndWriteRefs(Collection<Ref> refsToPack) throws IOException

Sort a collection of references and write them to the reftable. The input refs may not have duplicate names.

Parameters
refsToPack:Collection<Ref>

references to sort and write.

Returns:ReftableWriter

this

Exceptions
IOException:
if reftable cannot be written.
sortByIdback to summary
private static List<ReftableWriter.RefList> sortById(ObjectIdSubclassMap<ReftableWriter.RefList> m)
throwIllegalEntryback to summary
private void throwIllegalEntry(BlockWriter.Entry last, BlockWriter.Entry now)
writeFileFooterback to summary
private void writeFileFooter()
writeFileHeaderback to summary
private void writeFileHeader()
writeLogback to summary
public void writeLog(String ref, long updateIndex, PersonIdent who, ObjectId oldId, ObjectId newId, String message) throws IOException

Write one reflog entry to the reftable.

Reflog entries must be written in reference name and descending updateIndex (highest first) order.

Parameters
ref:String

name of the reference.

updateIndex:long

identifier of the transaction that created the log record. The updateIndex must be unique within the scope of ref, and must be within the bounds defined by minUpdateIndex <= updateIndex <= maxUpdateIndex.

who:PersonIdent

committer of the reflog entry.

oldId:ObjectId

prior id; pass org.eclipse.jgit.lib.ObjectId#zeroId() for creations.

newId:ObjectId

new id; pass org.eclipse.jgit.lib.ObjectId#zeroId() for deletions.

message:String

optional message (may be null).

Exceptions
IOException:
if reftable cannot be written.
writeObjBlocksback to summary
private void writeObjBlocks() throws IOException
writeRefback to summary
public void writeRef(Ref ref) throws IOException

Write one reference to the reftable.

References must be passed in sorted order.

Parameters
ref:Ref

the reference to store.

Exceptions
IOException:
if reftable cannot be written.
writeRefback to summary
public void writeRef(Ref ref, long updateIndex) throws IOException

Write one reference to the reftable.

References must be passed in sorted order.

Parameters
ref:Ref

the reference to store.

updateIndex:long

the updateIndex that modified this reference. Must be >= minUpdateIndex for this file.

Exceptions
IOException:
if reftable cannot be written.
org.eclipse.jgit.internal.storage.reftable back to summary

private Class ReftableWriter.IndexBuilder

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.reftable.ReftableWriter.IndexBuilder

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv List<BlockWriter.IndexEntry>
pack-priv final byte
pack-priv int
pack-priv long

Constructor Summary

AccessConstructor and Description
pack-priv
IndexBuilder(byte kt)

Method Summary

Modifier and TypeMethod and Description
pack-priv int
estimateBytes(long curBlockPos)

pack-priv void
private void
private List<BlockWriter.IndexEntry>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bytesback to summary
pack-priv int bytes
entriesback to summary
pack-priv List<BlockWriter.IndexEntry> entries
keyTypeback to summary
pack-priv final byte keyType
levelsback to summary
pack-priv int levels
rootPositionback to summary
pack-priv long rootPosition

Constructor Detail

IndexBuilderback to summary
pack-priv IndexBuilder(byte kt)

Method Detail

estimateBytesback to summary
pack-priv int estimateBytes(long curBlockPos)
writeIndexback to summary
pack-priv void writeIndex() throws IOException
writeMultiLevelIndexback to summary
private void writeMultiLevelIndex(List<BlockWriter.IndexEntry> keys) throws IOException
writeOneLevelback to summary
private List<BlockWriter.IndexEntry> writeOneLevel(List<BlockWriter.IndexEntry> keys) throws IOException
org.eclipse.jgit.internal.storage.reftable back to summary

private Class ReftableWriter.RefList

extends Entry
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final LongList

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addBlock(long pos)

Field Detail

blockPosback to summary
pack-priv final LongList blockPos

Constructor Detail

RefListback to summary
pack-priv RefList(AnyObjectId id)

Method Detail

addBlockback to summary
pack-priv void addBlock(long pos)
org.eclipse.jgit.internal.storage.reftable back to summary

private Class ReftableWriter.Section

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.reftable.ReftableWriter.Section

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv long
pack-priv final long
pack-priv final ReftableWriter.IndexBuilder

Constructor Summary

AccessConstructor and Description
pack-priv
Section(byte keyType)

Method Summary

Modifier and TypeMethod and Description
private void
pack-priv void
pack-priv void
pack-priv long
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bytesback to summary
pack-priv long bytes
entryCntback to summary
pack-priv long entryCnt
firstBlockPositionback to summary
pack-priv final long firstBlockPosition
idxback to summary
pack-priv final ReftableWriter.IndexBuilder idx

Constructor Detail

Sectionback to summary
pack-priv Section(byte keyType)

Method Detail

beginBlockback to summary
private void beginBlock(BlockWriter.Entry entry) throws BlockSizeTooSmallException
finishSectionMaybeWriteIndexback to summary
pack-priv void finishSectionMaybeWriteIndex() throws IOException
flushCurBlockback to summary
pack-priv void flushCurBlock() throws IOException
writeback to summary
pack-priv long write(BlockWriter.Entry entry) throws IOException
org.eclipse.jgit.internal.storage.reftable back to summary

public Class ReftableWriter.Stats

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.reftable.ReftableWriter.Stats

Statistics about a written reftable.

Field Summary

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

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

number of bytes to compress into a log block.
logBlockSize
()

Get log block size

public long

Returns:

number of bytes for log, including log index.
logBytes
()

Get number of bytes for log

public long

Returns:

total number of log records in the reftable.
logCount
()

Get number of log records

public long

Returns:

largest update index contained in this reftable.
maxUpdateIndex
()

Get largest updated index

public long

Returns:

smallest update index contained in this reftable.
minUpdateIndex
()

Get smallest update index

public long

Returns:

number of bytes for objects, including object index.
objBytes
()

Get number of bytes for objects

public long

Returns:

number of unique objects in the reftable.
objCount
()

Get number of unique objects

public int

Returns:

number of bytes required to uniquely identify all objects in the reftable. Unique abbreviations in hex would be 2 * objIdLength().
objIdLength
()

Get number of bytes required to uniquely identify all objects in the reftable

public int

Returns:

number of levels in the object index.
objIndexLevels
()

Get number of levels in object index

public int

Returns:

number of bytes in the object index; 0 if no index.
objIndexSize
()

Get size of object index

public long

Returns:

bytes of padding used to maintain block alignment.
paddingBytes
()

Get number of padding bytes

public int

Returns:

number of bytes in a ref block.
refBlockSize
()

Get ref block size

public long

Returns:

number of bytes for references, including ref index.
refBytes
()

Get number of bytes for references

public long

Returns:

total number of references in the reftable.
refCount
()

Get number of refs

public int

Returns:

number of levels in the ref index.
refIndexLevels
()

Get number of ref index levels

public int

Returns:

number of bytes in the ref index; 0 if no index was used.
refIndexSize
()

Get size of ref index

public int

Returns:

number of references between binary search markers.
restartInterval
()

Get restart interval

public long

Returns:

total number of bytes in the reftable.
totalBytes
()

Get total number of bytes

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

logBlockSizeback to summary
private final int logBlockSize
logBytesback to summary
private final long logBytes
logCntback to summary
private final long logCnt
maxUpdateIndexback to summary
private final long maxUpdateIndex
minUpdateIndexback to summary
private final long minUpdateIndex
objBytesback to summary
private final long objBytes
objCntback to summary
private final long objCnt
objIdLenback to summary
private final int objIdLen
objIndexLevelsback to summary
private final int objIndexLevels
objIndexSizeback to summary
private final int objIndexSize
paddingUsedback to summary
private final long paddingUsed
refBlockSizeback to summary
private final int refBlockSize
refBytesback to summary
private final long refBytes
refCntback to summary
private final long refCnt
refIndexLevelsback to summary
private final int refIndexLevels
refIndexSizeback to summary
private final int refIndexSize
restartIntervalback to summary
private final int restartInterval
totalBytesback to summary
private final long totalBytes

Constructor Detail

Statsback to summary
pack-priv Stats(ReftableWriter w, ReftableOutputStream o)

Method Detail

logBlockSizeback to summary
public int logBlockSize()

Get log block size

Returns:int

number of bytes to compress into a log block.

logBytesback to summary
public long logBytes()

Get number of bytes for log

Returns:long

number of bytes for log, including log index.

logCountback to summary
public long logCount()

Get number of log records

Returns:long

total number of log records in the reftable.

maxUpdateIndexback to summary
public long maxUpdateIndex()

Get largest updated index

Returns:long

largest update index contained in this reftable.

minUpdateIndexback to summary
public long minUpdateIndex()

Get smallest update index

Returns:long

smallest update index contained in this reftable.

objBytesback to summary
public long objBytes()

Get number of bytes for objects

Returns:long

number of bytes for objects, including object index.

objCountback to summary
public long objCount()

Get number of unique objects

Returns:long

number of unique objects in the reftable.

objIdLengthback to summary
public int objIdLength()

Get number of bytes required to uniquely identify all objects in the reftable

Returns:int

number of bytes required to uniquely identify all objects in the reftable. Unique abbreviations in hex would be 2 * objIdLength().

objIndexLevelsback to summary
public int objIndexLevels()

Get number of levels in object index

Returns:int

number of levels in the object index.

objIndexSizeback to summary
public int objIndexSize()

Get size of object index

Returns:int

number of bytes in the object index; 0 if no index.

paddingBytesback to summary
public long paddingBytes()

Get number of padding bytes

Returns:long

bytes of padding used to maintain block alignment.

refBlockSizeback to summary
public int refBlockSize()

Get ref block size

Returns:int

number of bytes in a ref block.

refBytesback to summary
public long refBytes()

Get number of bytes for references

Returns:long

number of bytes for references, including ref index.

refCountback to summary
public long refCount()

Get number of refs

Returns:long

total number of references in the reftable.

refIndexLevelsback to summary
public int refIndexLevels()

Get number of ref index levels

Returns:int

number of levels in the ref index.

refIndexSizeback to summary
public int refIndexSize()

Get size of ref index

Returns:int

number of bytes in the ref index; 0 if no index was used.

restartIntervalback to summary
public int restartInterval()

Get restart interval

Returns:int

number of references between binary search markers.

totalBytesback to summary
public long totalBytes()

Get total number of bytes

Returns:long

total number of bytes in the reftable.