/** {@inheritDoc} */ @Override public RefCursor allRefs() throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].allRefs(), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor byObjectId(AnyObjectId name) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].byObjectId(name), i)); } return m; }
int sizeBytes() { int sfxLen = key.length - prefixLen; int sfx = encodeSuffixAndType(sfxLen, valueType()); return computeVarintSize(prefixLen) + computeVarintSize(sfx) + sfxLen + valueSize(); }
private void writeObjBlocks() throws IOException { List<RefList> sorted = sortById(obj2ref); obj2ref = null; objIdLen = shortestUniqueAbbreviation(sorted); out.padBetweenBlocksToNextBlock(); objs = new Section(OBJ_BLOCK_TYPE); objs.entryCnt = sorted.size(); for (RefList l : sorted) { objs.write(new ObjEntry(objIdLen, l, l.blockPos)); } objs.finishSectionMaybeWriteIndex(); }
long write(BlockWriter.Entry entry) throws IOException { if (cur == null) { beginBlock(entry); } else if (!cur.tryAdd(entry)) { flushCurBlock(); if (cur.padBetweenBlocks()) { out.padBetweenBlocksToNextBlock(); } beginBlock(entry); } entryCnt++; return out.size(); }
private void mergeRefs(MergedReftable mr) throws IOException { try (RefCursor rc = mr.allRefs()) { while (rc.next()) { writer.writeRef(rc.getRef(), rc.getUpdateIndex()); } } }
/** {@inheritDoc} */ @Override public LogCursor seekLog(String refName, long updateIdx) throws IOException { MergedLogCursor m = new MergedLogCursor(); for (int i = 0; i < tables.length; i++) { m.add(new LogQueueEntry(tables[i].seekLog(refName, updateIdx), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor seekRef(String name) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].seekRef(name), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor seekRefsWithPrefix(String prefix) throws IOException { MergedRefCursor m = new MergedRefCursor(); for (int i = 0; i < tables.length; i++) { m.add(new RefQueueEntry(tables[i].seekRefsWithPrefix(prefix), i)); } return m; }
void writeKey(ReftableOutputStream os) { int sfxLen = key.length - prefixLen; os.writeVarint(prefixLen); os.writeVarint(encodeSuffixAndType(sfxLen, valueType())); os.write(key, prefixLen, sfxLen); }
private void beginLog() throws IOException { if (logs == null) { finishRefAndObjSections(); // close prior ref blocks and their index, if present. out.flushFileHeader(); out.setBlockSize(logBlockSize); logs = new Section(LOG_BLOCK_TYPE); } }
private void beginBlock(BlockWriter.Entry entry) throws BlockSizeTooSmallException { byte blockType = entry.blockType(); int bs = out.bytesAvailableInBlock(); cur = new BlockWriter(blockType, idx.keyType, bs, restartInterval); cur.mustAdd(entry); }
void writeIndex() throws IOException { if (padBetweenBlocks(keyType)) { out.padBetweenBlocksToNextBlock(); } long startPos = out.size(); writeMultiLevelIndex(entries); bytes = (int) (out.size() - startPos); entries = null; }
/** {@inheritDoc} */ @Override public LogCursor allLogs() throws IOException { MergedLogCursor m = new MergedLogCursor(); for (int i = 0; i < tables.length; i++) { m.add(new LogQueueEntry(tables[i].allLogs(), i)); } return m; }
/** {@inheritDoc} */ @Override public RefCursor byObjectId(AnyObjectId id) throws IOException { initObjIndex(); ObjCursorImpl i = new ObjCursorImpl(refEnd, id); if (objIndex != null) { i.initSeek(); } else { i.initScan(); } return i; }
private BlockReader readIndex(long pos) throws IOException { int sz = readBlockLen(pos); BlockReader i = new BlockReader(); i.readBlock(src, pos, sz); i.verifyIndex(); return i; }
void finishSectionMaybeWriteIndex() throws IOException { flushCurBlock(); cur = null; if (shouldHaveIndex(idx)) { idx.writeIndex(); } bytes = out.size() - firstBlockPosition; } }
private BlockSizeTooSmallException blockSizeTooSmall(Entry entry) { // Compute size required to fit this entry by itself. int min = FILE_HEADER_LEN + computeBlockBytes(entry.sizeBytes(), 1); return new BlockSizeTooSmallException(min); }
private void finishLogSection() throws IOException { if (cur != null && cur.blockType() == LOG_BLOCK_TYPE) { logs.finishSectionMaybeWriteIndex(); } }
private void writeFileHeader() { byte[] hdr = new byte[FILE_HEADER_LEN]; encodeHeader(hdr); out.write(hdr, 0, FILE_HEADER_LEN); }