Class ReftableWriter
java.lang.Object
org.eclipse.jgit.internal.storage.reftable.ReftableWriter
Writes a reftable formatted file.
A reftable can be written in a streaming fashion, provided the caller sorts
all references. A
ReftableWriter
is
single-use, and not thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
private static class
private class
static class
Statistics about a written reftable. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate 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 int
private ReftableWriter.Section
private ReftableOutputStream
private OutputStream
private int
private ReftableWriter.Section
private int
private ReftableWriter.Stats
-
Constructor Summary
ConstructorsConstructorDescriptionInitialize a writer with a default configuration.ReftableWriter
(ReftableConfig cfg, OutputStream os) Initialize a writer with a configuration. -
Method Summary
Modifier and TypeMethodDescriptionbegin()
Begin writing the reftable.private void
beginLog()
void
Record deletion of one reflog entry in this reftable.private void
encodeHeader
(byte[] hdr) long
Get an estimate of the current size in bytes of the reftablefinish()
Finish writing the reftable by writing its trailer.private void
private void
private static long
getStats()
Get statistics of the last written reftable.private void
private static long
private void
setConfig
(ReftableConfig cfg) Set configuration for the writer.setMaxUpdateIndex
(long max) Set the maximum update index for log entries that appear in this reftable.setMinUpdateIndex
(long min) Set the minimum update index for log entries that appear in this reftable.private static int
private boolean
sortAndWriteRefs
(Collection<Ref> refsToPack) Sort a collection of references and write them to the reftable.private static List<ReftableWriter.RefList>
private void
throwIllegalEntry
(BlockWriter.Entry last, BlockWriter.Entry now) private void
private void
void
writeLog
(String ref, long updateIndex, PersonIdent who, ObjectId oldId, ObjectId newId, String message) Write one reflog entry to the reftable.private void
void
Write one reference to the reftable.void
Write one reference to the reftable.
-
Field Details
-
config
-
refBlockSize
private int refBlockSize -
logBlockSize
private int logBlockSize -
restartInterval
private int restartInterval -
maxIndexLevels
private int maxIndexLevels -
alignBlocks
private boolean alignBlocks -
indexObjects
private boolean indexObjects -
minUpdateIndex
private long minUpdateIndex -
maxUpdateIndex
private long maxUpdateIndex -
outputStream
-
out
-
obj2ref
-
lastRef
-
lastLog
-
cur
-
refs
-
objs
-
logs
-
objIdLen
private int objIdLen -
stats
-
-
Constructor Details
-
ReftableWriter
Initialize a writer with a default configuration.- Parameters:
os
- output stream.
-
ReftableWriter
Initialize a writer with a configuration.- Parameters:
cfg
- configuration for the writeros
- output stream.
-
-
Method Details
-
setConfig
Set configuration for the writer.- Parameters:
cfg
- configuration for the writer.- Returns:
this
-
setMinUpdateIndex
Set the minimum update index for log entries that appear in this reftable.- Parameters:
min
- the minimum update index for log entries that appear in this reftable. This should be 1 higher than the prior reftable'smaxUpdateIndex
if this table will be used in a stack.- Returns:
this
-
setMaxUpdateIndex
Set the maximum update index for log entries that appear in this reftable.- Parameters:
max
- the maximum update index for log entries that appear in this reftable. This should be at least 1 higher than the prior reftable'smaxUpdateIndex
if this table will be used in a stack.- Returns:
this
-
begin
Begin writing the reftable. Should be called only once. Call this if a stream was passed to the constructor.- Returns:
this
-
sortAndWriteRefs
Sort a collection of references and write them to the reftable. The input refs may not have duplicate names.- Parameters:
refsToPack
- references to sort and write.- Returns:
this
- Throws:
IOException
- if reftable cannot be written.
-
writeRef
Write one reference to the reftable.References must be passed in sorted order.
- Parameters:
ref
- the reference to store.- Throws:
IOException
- if reftable cannot be written.
-
writeRef
Write one reference to the reftable.References must be passed in sorted order.
- Parameters:
ref
- the reference to store.updateIndex
- the updateIndex that modified this reference. Must be>= minUpdateIndex
for this file.- Throws:
IOException
- if reftable cannot be written.
-
throwIllegalEntry
-
indexRef
-
indexId
-
writeLog
public void writeLog(String ref, long updateIndex, PersonIdent who, ObjectId oldId, ObjectId newId, @Nullable 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
- name of the reference.updateIndex
- identifier of the transaction that created the log record. TheupdateIndex
must be unique within the scope ofref
, and must be within the bounds defined byminUpdateIndex <= updateIndex <= maxUpdateIndex
.who
- committer of the reflog entry.oldId
- prior id; passObjectId.zeroId()
for creations.newId
- new id; passObjectId.zeroId()
for deletions.message
- optional message (may be null).- Throws:
IOException
- if reftable cannot be written.
-
deleteLog
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
- the ref to delete (hide) a reflog entry from.updateIndex
- the update index that must be hidden.- Throws:
IOException
- if reftable cannot be written.
-
beginLog
- Throws:
IOException
-
estimateTotalBytes
public long estimateTotalBytes()Get an estimate of the current size in bytes of the reftable- Returns:
- an estimate of the current size in bytes of the reftable, if it
was finished right now. Estimate is only accurate if
ReftableConfig.setIndexObjects(boolean)
isfalse
andReftableConfig.setMaxIndexLevels(int)
is1
.
-
finish
Finish writing the reftable by writing its trailer.- Returns:
this
- Throws:
IOException
- if reftable cannot be written.
-
finishRefAndObjSections
- Throws:
IOException
-
writeObjBlocks
- Throws:
IOException
-
finishLogSection
- Throws:
IOException
-
shouldHaveIndex
-
writeFileHeader
private void writeFileHeader() -
encodeHeader
private void encodeHeader(byte[] hdr) -
firstBlockPosition
-
indexPosition
-
getStats
Get statistics of the last written reftable.- Returns:
- statistics of the last written reftable.
-
sortById
-
shortestUniqueAbbreviation
-