Class ReftableReader
- java.lang.Object
-
- org.eclipse.jgit.internal.storage.reftable.Reftable
-
- org.eclipse.jgit.internal.storage.reftable.ReftableReader
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class ReftableReader extends Reftable implements java.lang.AutoCloseable
Reads a reftable formatted file.ReftableReader
is not thread-safe. Concurrent readers need their own instance to read from the same file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ReftableReader.LogCursorImpl
private class
ReftableReader.ObjCursorImpl
private class
ReftableReader.RefCursorImpl
-
Field Summary
Fields Modifier and Type Field Description private int
blockSize
(package private) static LongList
EMPTY_LONG_LIST
private LongMap<BlockReader>
indexCache
private long
logEnd
private BlockReader
logIndex
private long
logIndexPosition
private long
logPosition
private long
maxUpdateIndex
private long
minUpdateIndex
private long
objEnd
private int
objIdLen
private BlockReader
objIndex
private long
objIndexPosition
private long
objPosition
private long
refEnd
private BlockReader
refIndex
private long
refIndexPosition
private BlockSource
src
-
Fields inherited from class org.eclipse.jgit.internal.storage.reftable.Reftable
includeDeletes
-
-
Constructor Summary
Constructors Constructor Description ReftableReader(BlockSource src)
Initialize a new reftable reader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LogCursor
allLogs()
Seek reader to read log records.RefCursor
allRefs()
Seek to the first reference, to iterate in order.private BlockReader
binarySearch(byte blockType, byte[] key, long startPos, long endPos)
private int
blocksIn(long pos, long end)
int
blockSize()
Get the block size in bytes chosen for this file by the writer.RefCursor
byObjectId(AnyObjectId id)
Match references pointing to a specific object.void
close()
boolean
hasObjectMap()
private void
initLogIndex()
private void
initObjIndex()
private void
initRefIndex()
long
maxUpdateIndex()
Get the maximum update index for ref entries that appear in this reftable.long
minUpdateIndex()
Get the minimum update index for ref entries that appear in this reftable.private BlockReader
readBlock(long pos, long end)
private int
readBlockLen(long pos)
private void
readFileFooter()
private void
readFileHeader()
private byte[]
readHeaderOrFooter(long pos, int len)
private BlockReader
readIndex(long pos)
private BlockReader
seek(byte blockType, byte[] key, BlockReader idx, long startPos, long endPos)
LogCursor
seekLog(java.lang.String refName, long updateIndex)
Seek to an update index in a reference's log.RefCursor
seekRef(java.lang.String refName)
Seek to a reference.RefCursor
seekRefsWithPrefix(java.lang.String prefix)
Seek references with prefix.long
size()
Get size of the reftable, in bytes.-
Methods inherited from class org.eclipse.jgit.internal.storage.reftable.Reftable
exactRef, from, hasId, hasRef, hasRefsWithPrefix, resolve, seekLog, setIncludeDeletes
-
-
-
-
Field Detail
-
src
private final BlockSource src
-
blockSize
private int blockSize
-
minUpdateIndex
private long minUpdateIndex
-
maxUpdateIndex
private long maxUpdateIndex
-
refEnd
private long refEnd
-
objPosition
private long objPosition
-
objEnd
private long objEnd
-
logPosition
private long logPosition
-
logEnd
private long logEnd
-
objIdLen
private int objIdLen
-
refIndexPosition
private long refIndexPosition
-
objIndexPosition
private long objIndexPosition
-
logIndexPosition
private long logIndexPosition
-
refIndex
private BlockReader refIndex
-
objIndex
private BlockReader objIndex
-
logIndex
private BlockReader logIndex
-
indexCache
private LongMap<BlockReader> indexCache
-
EMPTY_LONG_LIST
static final LongList EMPTY_LONG_LIST
-
-
Constructor Detail
-
ReftableReader
public ReftableReader(BlockSource src)
Initialize a new reftable reader.- Parameters:
src
- the file content to read.
-
-
Method Detail
-
blockSize
public int blockSize() throws java.io.IOException
Get the block size in bytes chosen for this file by the writer.- Returns:
- the block size in bytes chosen for this file by the writer. Most
reads from the
BlockSource
will be aligned to the block size. - Throws:
java.io.IOException
- file cannot be read.
-
hasObjectMap
public boolean hasObjectMap() throws java.io.IOException
- Specified by:
hasObjectMap
in classReftable
- Returns:
- whether this reftable can do a fast SHA1 => ref lookup.
- Throws:
java.io.IOException
- on I/O problems.
-
minUpdateIndex
public long minUpdateIndex() throws java.io.IOException
Get the minimum update index for ref entries that appear in this reftable.- Specified by:
minUpdateIndex
in classReftable
- Returns:
- the minimum update index for ref entries that appear in this reftable.
- Throws:
java.io.IOException
- file cannot be read.
-
maxUpdateIndex
public long maxUpdateIndex() throws java.io.IOException
Get the maximum update index for ref entries that appear in this reftable.- Specified by:
maxUpdateIndex
in classReftable
- Returns:
- the maximum update index for ref entries that appear in this reftable.
- Throws:
java.io.IOException
- file cannot be read.
-
allRefs
public RefCursor allRefs() throws java.io.IOException
Seek to the first reference, to iterate in order.
-
seekRef
public RefCursor seekRef(java.lang.String refName) throws java.io.IOException
Seek to a reference.This method will seek to the reference
refName
. If present, the returned cursor will iterate exactly one entry. If not found, an empty cursor is returned.
-
seekRefsWithPrefix
public RefCursor seekRefsWithPrefix(java.lang.String prefix) throws java.io.IOException
Seek references with prefix.The method will seek all the references starting with
prefix
as a prefix. If no references start with this prefix, an empty cursor is returned.- Specified by:
seekRefsWithPrefix
in classReftable
- Parameters:
prefix
- prefix to find.- Returns:
- cursor to iterate; empty cursor if no references match.
- Throws:
java.io.IOException
- if references cannot be read.
-
byObjectId
public RefCursor byObjectId(AnyObjectId id) throws java.io.IOException
Match references pointing to a specific object.- Specified by:
byObjectId
in classReftable
- Parameters:
id
- object to find.- Returns:
- cursor to iterate; empty cursor if no references match.
- Throws:
java.io.IOException
- if references cannot be read.
-
allLogs
public LogCursor allLogs() throws java.io.IOException
Seek reader to read log records.
-
seekLog
public LogCursor seekLog(java.lang.String refName, long updateIndex) throws java.io.IOException
Seek to an update index in a reference's log.- Specified by:
seekLog
in classReftable
- Parameters:
refName
- exact name of the reference whose log to read.updateIndex
- most recent index to return first in the log cursor. Log records at or beforeupdateIndex
will be returned.- Returns:
- cursor to iterate; empty cursor if no logs match.
- Throws:
java.io.IOException
- if logs cannot be read.
-
seek
private BlockReader seek(byte blockType, byte[] key, BlockReader idx, long startPos, long endPos) throws java.io.IOException
- Throws:
java.io.IOException
-
binarySearch
private BlockReader binarySearch(byte blockType, byte[] key, long startPos, long endPos) throws java.io.IOException
- Throws:
java.io.IOException
-
readFileHeader
private void readFileHeader() throws java.io.IOException
- Throws:
java.io.IOException
-
readFileFooter
private void readFileFooter() throws java.io.IOException
- Throws:
java.io.IOException
-
readHeaderOrFooter
private byte[] readHeaderOrFooter(long pos, int len) throws java.io.IOException
- Throws:
java.io.IOException
-
initRefIndex
private void initRefIndex() throws java.io.IOException
- Throws:
java.io.IOException
-
initObjIndex
private void initObjIndex() throws java.io.IOException
- Throws:
java.io.IOException
-
initLogIndex
private void initLogIndex() throws java.io.IOException
- Throws:
java.io.IOException
-
readIndex
private BlockReader readIndex(long pos) throws java.io.IOException
- Throws:
java.io.IOException
-
readBlockLen
private int readBlockLen(long pos) throws java.io.IOException
- Throws:
java.io.IOException
-
readBlock
private BlockReader readBlock(long pos, long end) throws java.io.IOException
- Throws:
java.io.IOException
-
blocksIn
private int blocksIn(long pos, long end)
-
size
public long size() throws java.io.IOException
Get size of the reftable, in bytes.- Returns:
- size of the reftable, in bytes.
- Throws:
java.io.IOException
- size cannot be obtained.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.io.IOException
-
-