/** * Sort a collection of references and write them to the reftable. * * @param refsToPack * references to sort and write. * @return {@code this} * @throws java.io.IOException * if reftable cannot be written. */ public ReftableWriter sortAndWriteRefs(Collection<Ref> refsToPack) throws IOException { Iterator<RefEntry> itr = refsToPack.stream() .map(r -> new RefEntry(r, maxUpdateIndex - minUpdateIndex)) .sorted(Entry::compare) .iterator(); while (itr.hasNext()) { RefEntry entry = itr.next(); long blockPos = refs.write(entry); indexRef(entry.ref, blockPos); } return this; }
/** * Write one reference to the reftable. * <p> * References must be passed in sorted order. * * @param ref * the reference to store. * @param updateIndex * the updateIndex that modified this reference. Must be * {@code >= minUpdateIndex} for this file. * @throws java.io.IOException * if reftable cannot be written. */ public void writeRef(Ref ref, long updateIndex) throws IOException { if (updateIndex < minUpdateIndex) { throw new IllegalArgumentException(); } long d = updateIndex - minUpdateIndex; long blockPos = refs.write(new RefEntry(ref, d)); indexRef(ref, blockPos); }
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(); }
String msg = message != null ? message : ""; //$NON-NLS-1$ beginLog(); logs.write(new LogEntry(ref, updateIndex, who, oldId, newId, msg));
private List<IndexEntry> writeOneLevel(List<IndexEntry> keys) throws IOException { Section thisLevel = new Section(keyType); for (Entry e : keys) { thisLevel.write(e); } if (!thisLevel.idx.entries.isEmpty()) { thisLevel.flushCurBlock(); if (cur.padBetweenBlocks()) { out.padBetweenBlocksToNextBlock(); } cur = null; return thisLevel.idx.entries; } // The current block fit entire level; make it the root. rootPosition = out.size(); cur.writeTo(out); cur = null; return null; } }
/** * Record deletion of one reflog entry in this reftable. * * <p> * The deletion can shadow an entry stored in a lower table in the stack. * This is useful for {@code refs/stash} and dropping an entry from its * reflog. * <p> * Deletion must be properly interleaved in sorted updateIndex order with * any other logs written by * {@link #writeLog(String, long, PersonIdent, ObjectId, ObjectId, String)}. * * @param ref * the ref to delete (hide) a reflog entry from. * @param updateIndex * the update index that must be hidden. * @throws java.io.IOException * if reftable cannot be written. */ public void deleteLog(String ref, long updateIndex) throws IOException { beginLog(); logs.write(new DeleteLogEntry(ref, updateIndex)); }
/** * Sort a collection of references and write them to the reftable. * * @param refsToPack * references to sort and write. * @return {@code this} * @throws java.io.IOException * if reftable cannot be written. */ public ReftableWriter sortAndWriteRefs(Collection<Ref> refsToPack) throws IOException { Iterator<RefEntry> itr = refsToPack.stream() .map(r -> new RefEntry(r, maxUpdateIndex - minUpdateIndex)) .sorted(Entry::compare) .iterator(); while (itr.hasNext()) { RefEntry entry = itr.next(); long blockPos = refs.write(entry); indexRef(entry.ref, blockPos); } return this; }
/** * Write one reference to the reftable. * <p> * References must be passed in sorted order. * * @param ref * the reference to store. * @param updateIndex * the updateIndex that modified this reference. Must be * {@code >= minUpdateIndex} for this file. * @throws java.io.IOException * if reftable cannot be written. */ public void writeRef(Ref ref, long updateIndex) throws IOException { if (updateIndex < minUpdateIndex) { throw new IllegalArgumentException(); } long d = updateIndex - minUpdateIndex; long blockPos = refs.write(new RefEntry(ref, d)); indexRef(ref, blockPos); }
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(); }
String msg = message != null ? message : ""; //$NON-NLS-1$ beginLog(); logs.write(new LogEntry(ref, updateIndex, who, oldId, newId, msg));
/** * Record deletion of one reflog entry in this reftable. * * <p> * The deletion can shadow an entry stored in a lower table in the stack. * This is useful for {@code refs/stash} and dropping an entry from its * reflog. * <p> * Deletion must be properly interleaved in sorted updateIndex order with * any other logs written by * {@link #writeLog(String, long, PersonIdent, ObjectId, ObjectId, String)}. * * @param ref * the ref to delete (hide) a reflog entry from. * @param updateIndex * the update index that must be hidden. * @throws java.io.IOException * if reftable cannot be written. */ public void deleteLog(String ref, long updateIndex) throws IOException { beginLog(); logs.write(new DeleteLogEntry(ref, updateIndex)); }
private List<IndexEntry> writeOneLevel(List<IndexEntry> keys) throws IOException { Section thisLevel = new Section(keyType); for (Entry e : keys) { thisLevel.write(e); } if (!thisLevel.idx.entries.isEmpty()) { thisLevel.flushCurBlock(); if (cur.padBetweenBlocks()) { out.padBetweenBlocksToNextBlock(); } cur = null; return thisLevel.idx.entries; } // The current block fit entire level; make it the root. rootPosition = out.size(); cur.writeTo(out); cur = null; return null; } }