[JGIT PATCH 12/14] Allow application code to set ObjectIds in DirCacheEntry

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <spearce@xxxxxxxxxxx>
---
 .../org/spearce/jgit/dircache/DirCacheEntry.java   |   26 ++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

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 011bc16..a83cc78 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java
@@ -43,6 +43,7 @@
 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;
@@ -346,6 +347,31 @@ public ObjectId getObjectId() {
 	}
 
 	/**
+	 * 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.
 	 * <p>
 	 * This method is not very efficient and is primarily meant for debugging
-- 
1.6.0.87.g2858d

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux