git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 18, 2008, 23:53 UTC
Message-ID
<1219103602-32222-13-git-send-email-spearce@spearce.org>
In-Reply-To
<1219103602-32222-12-git-send-email-spearce@spearce.org>

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@spearce.org>
---
 .../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
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 13 of 20 in “TreeWalk D/F conflict detection”
  1. 00/14 TreeWalk D/F conflict detectionShawn O. Pearce, Aug 18, 2008
  2. 01/14 Detect path names which overflow the name length field in the indexShawn O. Pearce, Aug 18, 2008
  3. 02/14 Fix NB.decodeUInt16 to correctly handle the high byteShawn O. Pearce, Aug 18, 2008
  4. 03/14 Add test cases for NB.encode and NB.decode family of routinesShawn O. Pearce, Aug 18, 2008
  5. 04/14 Fix DirCache's skip over null byte padding when reading a DIRC fileShawn O. Pearce, Aug 18, 2008
  6. 05/14 Fix usage of assertEquals in DirCacheIteratorTestShawn O. Pearce, Aug 18, 2008
  7. 06/14 Refactor AbstractTreeIterator.pathCompare to force another modeShawn O. Pearce, Aug 18, 2008
  8. 07/14 Micro-optimize AbstractTreeIterator.pathCompareShawn O. Pearce, Aug 18, 2008
  9. 08/14 Optimize path comparsion within subtrees during TreeWalkShawn O. Pearce, Aug 18, 2008
  10. 09/14 Refactor AbstractTreeIterator semantics to start on first entryShawn O. Pearce, Aug 18, 2008
  11. 10/14 Make all AbstractTreeIterator implementations bi-directionalShawn O. Pearce, Aug 18, 2008
  12. 11/14 Expose beginning of iterator indication from AbstractTreeIteratorShawn O. Pearce, Aug 18, 2008
  13. 12/14 Allow application code to set ObjectIds in DirCacheEntryShawn O. Pearce, Aug 18, 2008
  14. 13/14 Create NameConflictTreeWalk to transparently detect D/F conflictsShawn O. Pearce, Aug 18, 2008
  15. 14/14 Add test case for NameConflictTreeWalkShawn O. Pearce, Aug 18, 2008
  16. Junio C HamanoAug 19, 2008
  17. Robin RosenbergAug 19, 2008
  18. Shawn O. PearceAug 19, 2008
  19. David WoodhouseAug 19, 2008
  20. Shawn O. PearceAug 19, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.