Add insert(TreeFormatter) to ObjectInserter
This makes usage of a TreeFormatter more similar to a CommitBuilder or a TagBuilder: populate the formatter and pass to the ObjectInserter. Change-Id: I5a45ef3a35cc73f4905a34bc6f6228510df8eb2c Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Reviewed-by: Chris Aniszczyk <caniszczyk@gmail.com>
This commit is contained in:
parent
9ad802c15b
commit
8d4c95a645
|
@ -338,7 +338,7 @@ ObjectId writeTree(final DirCacheEntry[] cache, int cIdx,
|
|||
entryIdx++;
|
||||
}
|
||||
|
||||
id = fmt.insert(ow);
|
||||
id = ow.insert(fmt);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -176,6 +176,22 @@ public ObjectId idFor(int objectType, long length, InputStream in)
|
|||
return ObjectId.fromRaw(md.digest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a single tree into the store, returning its unique name.
|
||||
*
|
||||
* @param formatter
|
||||
* the formatter containing the proposed tree's data.
|
||||
* @return the name of the tree object.
|
||||
* @throws IOException
|
||||
* the object could not be stored.
|
||||
*/
|
||||
public final ObjectId insert(TreeFormatter formatter) throws IOException {
|
||||
// Delegate to the formatter, as then it can pass the raw internal
|
||||
// buffer back to this inserter, avoiding unnecessary data copying.
|
||||
//
|
||||
return formatter.insertTo(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a single commit into the store, returning its unique name.
|
||||
*
|
||||
|
|
|
@ -279,7 +279,7 @@ private void fmtOverflowBuffer(byte[] nameBuf, int namePos, int nameLen,
|
|||
* @throws IOException
|
||||
* the tree could not be stored.
|
||||
*/
|
||||
public ObjectId insert(ObjectInserter ins) throws IOException {
|
||||
public ObjectId insertTo(ObjectInserter ins) throws IOException {
|
||||
if (buf != null)
|
||||
return ins.insert(OBJ_TREE, buf, 0, ptr);
|
||||
|
||||
|
@ -293,7 +293,7 @@ public ObjectId insert(ObjectInserter ins) throws IOException {
|
|||
* This method is not efficient, as it needs to create a copy of the
|
||||
* internal buffer in order to supply an array of the correct size to the
|
||||
* caller. If the buffer is just to pass to an ObjectInserter, consider
|
||||
* using {@link #insert(ObjectInserter)} instead.
|
||||
* using {@link ObjectInserter#insert(TreeFormatter)} instead.
|
||||
*
|
||||
* @return a copy of this formatter's buffer.
|
||||
*/
|
||||
|
|
|
@ -254,7 +254,7 @@ ObjectId writeTree(ObjectInserter inserter) throws IOException {
|
|||
|
||||
for (; e != null; e = e.next)
|
||||
e.format(fmt);
|
||||
return fmt.insert(inserter);
|
||||
return inserter.insert(fmt);
|
||||
}
|
||||
|
||||
private int treeSize() {
|
||||
|
|
|
@ -190,7 +190,7 @@ ObjectId writeTree(ObjectInserter inserter) throws IOException {
|
|||
|
||||
for (; e != null; e = e.next)
|
||||
e.format(fmt);
|
||||
return fmt.insert(inserter);
|
||||
return inserter.insert(fmt);
|
||||
}
|
||||
|
||||
private int treeSize(final int nameLen) {
|
||||
|
|
Loading…
Reference in New Issue