private byte[] buffer(DeltaWindowEntry ent) throws MissingObjectException, IncorrectObjectTypeException, IOException, LargeObjectException { byte[] buf = ent.buffer; if (buf == null) { checkLoadable(ent, ent.size()); buf = PackWriter.buffer(config, reader, ent.object); if (maxMemory != 0) loaded += buf.length; ent.buffer = buf; } return buf; }
private void writeBase(PackOutputStream out, ObjectToPack base) throws IOException { if (base != null && !base.isWritten() && !base.isEdge()) writeObjectImpl(out, base); }
private TemporaryBuffer.Heap delta(ObjectToPack otp) throws IOException { DeltaIndex index = new DeltaIndex(buffer(otp.getDeltaBaseId())); byte[] res = buffer(otp); // We never would have proposed this pair if the delta would be // larger than the unpacked version of the object. So using it // as our buffer limit is valid: we will never reach it. // TemporaryBuffer.Heap delta = new TemporaryBuffer.Heap(res.length); index.encode(delta, res); return delta; }
static int getAdjustedWeight(ObjectToPack o) { // Edge objects and those with reused deltas do not need to be // compressed. For compression calculations, ignore their weights. if (o.isEdge() || o.doNotAttemptDelta()) { return 0; } return o.getWeight(); }
private int findObjectsNeedingDelta(ObjectToPack[] list, int cnt, int type) { for (ObjectToPack otp : objectsLists[type]) { if (otp.isDoNotDelta()) // delta is disabled for this path continue; if (otp.isDeltaRepresentation()) // already reusing a delta continue; otp.setWeight(0); list[cnt++] = otp; } return cnt; }
private void searchForReuse(ProgressMonitor monitor, List<ObjectToPack> list) throws IOException, MissingObjectException { pruneCurrentObjectList = false; reuseSupport.selectObjectRepresentation(this, monitor, list); if (pruneCurrentObjectList) pruneEdgesFromObjectList(list); }
private static long estimateIndexSize(DeltaWindowEntry ent) { if (ent.buffer == null) return estimateSize(ent.object); int len = ent.buffer.length; return DeltaIndex.estimateIndexSize(len) - len; }
private void clear(DeltaWindowEntry ent) { if (ent.index != null) loaded -= ent.index.getIndexSize(); else if (ent.buffer != null) loaded -= ent.buffer.length; ent.set(null); }
private DeltaEncoder newEncoder(OutputStream out, long resSize, int limit) throws IOException { return new DeltaEncoder(out, getSourceSize(), resSize, limit); }
void writeObject(PackOutputStream out, ObjectToPack otp) throws IOException { if (!otp.isWritten()) writeObjectImpl(out, otp); }
private static long estimateSize(ObjectToPack ent) { return DeltaIndex.estimateIndexSize(ent.getWeight()); }
final int getFormat() { if (isReuseAsIs()) { if (isDeltaRepresentation()) return StoredObjectRepresentation.PACK_DELTA; return StoredObjectRepresentation.PACK_WHOLE; } return StoredObjectRepresentation.FORMAT_OTHER; }
/** * Format this delta as a human readable string. * * @param delta * the delta instruction sequence to format. * @return the formatted delta. */ public static String format(byte[] delta) { return format(delta, true); }
/** * Get blockSize of the file, in bytes. * * @param ext * the file extension. * @return blockSize of the file, in bytes. If 0 the blockSize size is not * yet known and may be discovered when opening the file. */ public int getBlockSize(PackExt ext) { int i = ext.getPosition(); return i < blockSizeMap.length ? blockSizeMap[i] : 0; }
DeltaWindow initWindow(Slice s) { DeltaWindow w = new DeltaWindow(block.config, block.dc, or, block.pm, block.bytesPerUnit, block.list, s.beginIndex, s.endIndex); synchronized (this) { dw = w; } return w; }
/** * Get snapshot of the current state of this PackWriter. * * @return snapshot of the current state of this PackWriter. */ public State getState() { return state.snapshot(); }
/** * Whether the pack file extension is known to exist. * * @param ext * the file extension * @return whether the pack file extension is known to exist. */ public boolean hasFileExt(PackExt ext) { return (extensions & ext.getBit()) != 0; }
/** * Get the bit mask of the extension e.g {@code 1 << getPosition()}. * * @return the bit mask of the extension e.g {@code 1 << getPosition()}. */ public int getBit() { return 1 << getPosition(); }