/** * Insert a single object into the store, returning its unique name. * * @param type * type code of the object to store. * @param data * complete content of the object. * @return the name of the object. * @throws java.io.IOException * the object could not be stored. */ public ObjectId insert(int type, byte[] data) throws IOException { return insert(type, data, 0, data.length); }
/** * Insert a single object into the store, returning its unique name. * * @param type * type code of the object to store. * @param data * complete content of the object. * @param off * first position within {@code data}. * @param len * number of bytes to copy from {@code data}. * @return the name of the object. * @throws java.io.IOException * the object could not be stored. */ public ObjectId insert(int type, byte[] data, int off, int len) throws IOException { return insert(type, len, new ByteArrayInputStream(data, off, len)); }
@Override public ObjectId insert(int type, byte[] data, int off, int len) throws IOException { return delegate().insert(type, data, off, len); }
/** * Insert a single commit into the store, returning its unique name. * * @param builder * the builder containing the proposed commit's data. * @return the name of the commit object. * @throws java.io.IOException * the object could not be stored. */ public final ObjectId insert(CommitBuilder builder) throws IOException { return insert(Constants.OBJ_COMMIT, builder.build()); }
@Override public ObjectId insert(int objectType, long length, InputStream in) throws IOException { return delegate().insert(objectType, length, in); }
/** * Insert a single annotated tag into the store, returning its unique name. * * @param builder * the builder containing the proposed tag's data. * @return the name of the tag object. * @throws java.io.IOException * the object could not be stored. */ public final ObjectId insert(TagBuilder builder) throws IOException { return insert(Constants.OBJ_TAG, builder.build()); }
@Override public ObjectId insert(int type, byte[] data) throws IOException { return delegate().insert(type, data); }
@Override ObjectId writeTree(ObjectInserter inserter) throws IOException { return inserter.insert(build()); }
@Override ObjectId writeTree(ObjectInserter inserter) throws IOException { return inserter.insert(build(true, inserter)); }
/** * Insert this tree and obtain its ObjectId. * * @param ins * the inserter to store the tree. * @return computed ObjectId of the tree * @throws java.io.IOException * the tree could not be stored. */ public ObjectId insertTo(ObjectInserter ins) throws IOException { if (buf != null) return ins.insert(OBJ_TREE, buf, 0, ptr); final long len = overflowBuffer.length(); return ins.insert(OBJ_TREE, len, overflowBuffer.openInputStream()); }
/** * Write this reference tree. * * @param inserter * inserter to use when writing trees to the object database. * Caller is responsible for flushing the inserter before trying * to read the objects, or exposing them through a reference. * @return the top level tree. * @throws java.io.IOException * a tree could not be written. */ public ObjectId writeTree(ObjectInserter inserter) throws IOException { if (pendingBlobs != null) { for (String s : pendingBlobs.values()) { inserter.insert(OBJ_BLOB, encode(s)); } pendingBlobs = null; } return contents.writeTree(inserter); }
if (noteData != null) { byte[] dataUTF8 = Constants.encode(noteData); dataId = ins.insert(Constants.OBJ_BLOB, dataUTF8); } else { dataId = null;
private ObjectId insertMergeResult(TemporaryBuffer buf, Attributes attributes) throws IOException { InputStream in = buf.openInputStream(); try (LfsInputStream is = LfsFactory.getInstance().applyCleanFilter( getRepository(), in, buf.length(), attributes.get(Constants.ATTR_MERGE))) { return getObjectInserter().insert(OBJ_BLOB, is.getLength(), is); } }
ObjectId act = inserter.insert(type, raw); if (!AnyObjectId.equals(id, act)) { throw new TransportException(MessageFormat.format(
/** {@inheritDoc} */ @Override public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter) throws IOException { if (ours == null) return theirs; if (theirs == null) return ours; if (ours.getData().equals(theirs.getData())) return ours; ObjectLoader lo = reader.open(ours.getData()); ObjectLoader lt = reader.open(theirs.getData()); try (UnionInputStream union = new UnionInputStream(lo.openStream(), lt.openStream())) { ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + lt.getSize(), union); return new Note(ours, noteData); } } }
private ObjectId insertSingleProposal(Repository git, ProposedTimestamp ts, ObjectInserter inserter) throws IOException, NoOp { // Fast path: tree is passed in with all proposals applied. ObjectId treeId = queuedTree.writeTree(inserter); queuedTree = null; leader.roundHoldsReferenceToRefTree = false; if (!ObjectId.zeroId().equals(acceptedOldIndex)) { try (RevWalk rw = new RevWalk(git)) { RevCommit c = rw.parseCommit(acceptedOldIndex); if (treeId.equals(c.getTree())) { throw new NoOp(); } } } Proposal p = todo.get(0); CommitBuilder b = new CommitBuilder(); b.setTreeId(treeId); if (!ObjectId.zeroId().equals(acceptedOldIndex)) { b.setParentId(acceptedOldIndex); } b.setCommitter(leader.getSystem().newCommitter(ts)); b.setAuthor(p.getAuthor() != null ? p.getAuthor() : b.getCommitter()); b.setMessage(message(p)); return inserter.insert(b); }
static void commitNoteMap(Repository r, String ref, RevWalk walk, NoteMap map, RevCommit notesCommit, ObjectInserter inserter, String msg) throws IOException { // commit the note CommitBuilder builder = new CommitBuilder(); builder.setTreeId(map.writeTree(inserter)); builder.setAuthor(new PersonIdent(r)); builder.setCommitter(builder.getAuthor()); builder.setMessage(msg); if (notesCommit != null) builder.setParentIds(notesCommit); ObjectId commit = inserter.insert(builder); inserter.flush(); RefUpdate refUpdate = r.updateRef(ref); if (notesCommit != null) refUpdate.setExpectedOldObjectId(notesCommit); else refUpdate.setExpectedOldObjectId(ObjectId.zeroId()); refUpdate.setNewObjectId(commit); refUpdate.update(walk); }
private boolean apply(List<Command> todo) throws IOException { if (!tree.apply(todo)) { // apply set rejection information on commands. return false; } Repository repo = refdb.getRepository(); try (ObjectInserter ins = repo.newObjectInserter()) { CommitBuilder b = new CommitBuilder(); b.setTreeId(tree.writeTree(ins)); if (parentTreeId.equals(b.getTreeId())) { for (Command c : todo) { c.setResult(OK); } return true; } if (!parentCommitId.equals(ObjectId.zeroId())) { b.setParentId(parentCommitId); } author = getRefLogIdent(); if (author == null) { author = new PersonIdent(repo); } b.setAuthor(author); b.setCommitter(author); b.setMessage(getRefLogMessage()); newCommitId = ins.insert(b); ins.flush(); } return true; }
b.setCommitter(committer); b.setMessage(message(p)); lastIndex = inserter.insert(b);