private BlockReader readBlock(long pos, long end) throws IOException { if (indexCache != null) { BlockReader b = indexCache.get(pos); if (b != null) { return b; } } int sz = blockSize; if (sz == 0) { sz = readBlockLen(pos); } else if (pos + sz > end) { sz = (int) (end - pos); // last block may omit padding. } BlockReader b = new BlockReader(); b.readBlock(src, pos, sz); if (b.type() == INDEX_BLOCK_TYPE && !b.truncated()) { if (indexCache == null) { indexCache = new LongMap<>(); } indexCache.put(pos, b); } return b; }
if (pos == 0) { if (bufLen == FILE_HEADER_LEN) { setupEmptyFileBlock(); return; int blockLen = decodeBlockLen(typeAndSize); if (blockType == LOG_BLOCK_TYPE) { long deflatedSize = inflateBuf(src, pos, blockLen, fileBlockSize); endPosition = pos + 4 + deflatedSize; throw invalidBlock();
@Override public boolean next() throws IOException { for (;;) { if (block == null || block.type() != LOG_BLOCK_TYPE) { return false; } else if (!block.next()) { long pos = block.endPosition(); if (pos >= scanEnd) { return false; } block = readBlock(pos, scanEnd); continue; } block.parseKey(); if (match != null && !block.match(match, false)) { block.skipValue(); return false; } refName = block.name(); updateIndex = block.readLogUpdateIndex(); entry = block.readLogEntry(); if (entry == null && !includeDeletes) { continue; } return true; } }
void readBlock(BlockSource src, long pos, int fileBlockSize) throws IOException { readBlockIntoBuf(src, pos, fileBlockSize); parseBlockStart(src, pos, fileBlockSize); }
long readPositionFromIndex() throws IOException { if (blockType != INDEX_BLOCK_TYPE) { throw invalidBlock(); } readVarint32(); // skip prefix length int n = readVarint32() >>> 3; ptr += n; // skip name return readVarint64(); }
private BlockReader readIndex(long pos) throws IOException { int sz = readBlockLen(pos); BlockReader i = new BlockReader(); i.readBlock(src, pos, sz); i.verifyIndex(); return i; }
@Override public boolean next() throws IOException { for (;;) { if (block == null || block.type() != REF_BLOCK_TYPE) { return false; } else if (!block.next()) { long pos = block.endPosition(); if (pos >= scanEnd) { return false; } block = readBlock(pos, scanEnd); continue; } block.parseKey(); if (match != null && !block.match(match, prefix)) { block.skipValue(); return false; } updateIndex = minUpdateIndex + block.readUpdateIndexDelta(); ref = block.readRef(); if (!includeDeletes && wasDeleted()) { continue; } return true; } }
if (b.seekKey(key) > 0) { blockPos = EMPTY_LONG_LIST; return; long pos = b.readPositionFromIndex(); b = readBlock(pos, objEnd); } while (b.type() == INDEX_BLOCK_TYPE); b.seekKey(key); while (b.next()) { b.parseKey(); if (b.match(key, false)) { blockPos = b.readBlockPositionList(); if (blockPos == null) { initScan(); b.skipValue();
@Override public boolean next() throws IOException { for (;;) { if (block == null || block.type() != REF_BLOCK_TYPE) { return false; } else if (!block.next()) { long pos; if (blockPos != null) { pos = block.endPosition(); block.parseKey(); updateIndex = minUpdateIndex + block.readUpdateIndexDelta(); ref = block.readRef(); ObjectId id = ref.getObjectId(); if (id != null && match.equals(id)
Ref readRef() throws IOException { String name = RawParseUtils.decode(UTF_8, nameBuf, 0, nameLen); switch (valueType & VALUE_TYPE_MASK) { case VALUE_NONE: // delete return newRef(name); case VALUE_1ID: return new ObjectIdRef.PeeledNonTag(PACKED, name, readValueId()); case VALUE_2ID: { // annotated tag ObjectId id1 = readValueId(); ObjectId id2 = readValueId(); return new ObjectIdRef.PeeledTag(PACKED, name, id1, id2); } case VALUE_SYMREF: { String val = readValueString(); return new SymbolicRef(name, newRef(val)); } default: throw invalidBlock(); } }
} else if (n <= 0 && inf.needsInput()) { long p = pos + 4 + inf.getBytesRead(); readBlockIntoBuf(src, p, fileBlockSize); inf.setInput(buf, 0, bufLen); } else if (n <= 0) { throw invalidBlock(); throw invalidBlock(e); } finally { InflaterCache.release(inf);
void verifyIndex() throws IOException { if (blockType != INDEX_BLOCK_TYPE || truncated) { throw invalidBlock(); } }
private int readBlockLen(long pos) throws IOException { int sz = pos == 0 ? FILE_HEADER_LEN + 4 : 4; ByteBuffer tmp = src.read(pos, sz); if (tmp.position() < sz) { throw new IOException(JGitText.get().invalidReftableFile); } byte[] buf; if (tmp.hasArray() && tmp.arrayOffset() == 0) { buf = tmp.array(); } else { buf = new byte[sz]; tmp.flip(); tmp.get(buf); } if (pos == 0 && buf[FILE_HEADER_LEN] == FILE_BLOCK_TYPE) { return FILE_HEADER_LEN; } int p = pos == 0 ? FILE_HEADER_LEN : 0; return decodeBlockLen(NB.decodeInt32(buf, p)); }
@Override public boolean next() throws IOException { for (;;) { if (block == null || block.type() != REF_BLOCK_TYPE) { return false; } else if (!block.next()) { long pos = block.endPosition(); if (pos >= scanEnd) { return false; } block = readBlock(pos, scanEnd); continue; } block.parseKey(); if (match != null && !block.match(match, prefix)) { block.skipValue(); return false; } updateIndex = minUpdateIndex + block.readUpdateIndexDelta(); ref = block.readRef(); if (!includeDeletes && wasDeleted()) { continue; } return true; } }
if (b.seekKey(key) > 0) { blockPos = EMPTY_LONG_LIST; return; long pos = b.readPositionFromIndex(); b = readBlock(pos, objEnd); } while (b.type() == INDEX_BLOCK_TYPE); b.seekKey(key); while (b.next()) { b.parseKey(); if (b.match(key, false)) { blockPos = b.readBlockPositionList(); if (blockPos == null) { initScan(); b.skipValue();
@Override public boolean next() throws IOException { for (;;) { if (block == null || block.type() != REF_BLOCK_TYPE) { return false; } else if (!block.next()) { long pos; if (blockPos != null) { pos = block.endPosition(); block.parseKey(); updateIndex = minUpdateIndex + block.readUpdateIndexDelta(); ref = block.readRef(); ObjectId id = ref.getObjectId(); if (id != null && match.equals(id)
Ref readRef() throws IOException { String name = RawParseUtils.decode(UTF_8, nameBuf, 0, nameLen); switch (valueType & VALUE_TYPE_MASK) { case VALUE_NONE: // delete return newRef(name); case VALUE_1ID: return new ObjectIdRef.PeeledNonTag(PACKED, name, readValueId()); case VALUE_2ID: { // annotated tag ObjectId id1 = readValueId(); ObjectId id2 = readValueId(); return new ObjectIdRef.PeeledTag(PACKED, name, id1, id2); } case VALUE_SYMREF: { String val = readValueString(); return new SymbolicRef(name, newRef(val)); } default: throw invalidBlock(); } }
long readPositionFromIndex() throws IOException { if (blockType != INDEX_BLOCK_TYPE) { throw invalidBlock(); } readVarint32(); // skip prefix length int n = readVarint32() >>> 3; ptr += n; // skip name return readVarint64(); }
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 readBlock(BlockSource src, long pos, int fileBlockSize) throws IOException { readBlockIntoBuf(src, pos, fileBlockSize); parseBlockStart(src, pos, fileBlockSize); }