From 219ce47ed7f356cd20bbba1c4c042ba1c8791ba1 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 18 Aug 2008 16:53:20 -0700 Subject: [PATCH] Allow application code to set ObjectIds in DirCacheEntry We support setting the ObjectId both from AnyObjectId (as we copy it) and from a raw byte[] (as we are really copying into a raw byte[]). The latter form is the most efficient as it probably permits callers to avoid unnecessary conversion to some form of AnyObjectId. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../org/spearce/jgit/dircache/DirCacheEntry.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java index dbd74b50..b23d96c8 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java +++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java @@ -45,6 +45,7 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.Arrays; +import org.spearce.jgit.lib.AnyObjectId; import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.FileMode; import org.spearce.jgit.lib.ObjectId; @@ -367,6 +368,31 @@ public class DirCacheEntry { } /** + * Set the ObjectId for the entry. + * + * @param id + * new object identifier for the entry. May be + * {@link ObjectId#zeroId()} to remove the current identifier. + */ + public void setObjectId(final AnyObjectId id) { + id.copyRawTo(idBuffer(), idOffset()); + } + + /** + * Set the ObjectId for the entry from the raw binary representation. + * + * @param bs + * the raw byte buffer to read from. At least 20 bytes after p + * must be available within this byte array. + * @param p + * position to read the first byte of data from. + */ + public void setObjectIdFromRaw(final byte[] bs, final int p) { + final int n = Constants.OBJECT_ID_LENGTH; + System.arraycopy(bs, p, idBuffer(), idOffset(), n); + } + + /** * Get the entry's complete path. *

* This method is not very efficient and is primarily meant for debugging -- 2.11.4.GIT