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

[JGIT PATCH 08/10] Allow DirCacheEntry instances to be created with stage > 0

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 22, 2009, 23:28 UTC
Message-ID
<1232666890-23488-9-git-send-email-spearce@spearce.org>
In-Reply-To
<1232666890-23488-8-git-send-email-spearce@spearce.org>

As the stage is part of the sorting criteria for DirCacheEntry objects we don't allow the stage to be modified on the fly in an existing instance. Instead the stage must be set by reading it from the on-disk format or by creating a new entry with the proper path and stage components.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../org/spearce/jgit/dircache/DirCacheEntry.java   |   52 +++++++++++++++++---
 1 files changed, 45 insertions(+), 7 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 355cd3e..9304501 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java
@@ -60,6 +60,18 @@
 public class DirCacheEntry {
 	private static final byte[] nullpad = new byte[8];
 
+	/** The standard (fully merged) stage for an entry. */
+	public static final int STAGE_0 = 0;
+
+	/** The base tree revision for an entry. */
+	public static final int STAGE_1 = 1;
+
+	/** The first tree revision (usually called "ours"). */
+	public static final int STAGE_2 = 2;
+
+	/** The second tree revision (usually called "theirs"). */
+	public static final int STAGE_3 = 3;
+
 	// private static final int P_CTIME = 0;
 
 	// private static final int P_CTIME_NSEC = 4;
@@ -141,8 +153,8 @@ DirCacheEntry(final byte[] sharedInfo, final int infoAt,
 	}
 
 	/**
-	 * Create an empty entry.
-	 *
+	 * Create an empty entry at stage 0.
+	 * 
 	 * @param newPath
 	 *            name of the cache entry.
 	 */
@@ -151,20 +163,46 @@ public DirCacheEntry(final String newPath) {
 	}
 
 	/**
-	 * Create an empty entry.
-	 *
+	 * Create an empty entry at the specified stage.
+	 * 
+	 * @param newPath
+	 *            name of the cache entry.
+	 * @param stage
+	 *            the stage index of the new entry.
+	 */
+	public DirCacheEntry(final String newPath, final int stage) {
+		this(Constants.encode(newPath), stage);
+	}
+
+	/**
+	 * Create an empty entry at stage 0.
+	 * 
 	 * @param newPath
 	 *            name of the cache entry, in the standard encoding.
 	 */
 	public DirCacheEntry(final byte[] newPath) {
+		this(newPath, STAGE_0);
+	}
+
+	/**
+	 * Create an empty entry at the specified stage.
+	 * 
+	 * @param newPath
+	 *            name of the cache entry, in the standard encoding.
+	 * @param stage
+	 *            the stage index of the new entry.
+	 */
+	public DirCacheEntry(final byte[] newPath, final int stage) {
 		info = new byte[INFO_LEN];
 		infoOffset = 0;
-
 		path = newPath;
+
+		int flags = ((stage & 0x3) << 12);
 		if (path.length < NAME_MASK)
-			NB.encodeInt16(info, infoOffset + P_FLAGS, path.length);
+			flags |= path.length;
 		else
-			NB.encodeInt16(info, infoOffset + P_FLAGS, NAME_MASK);
+			flags |= NAME_MASK;
+		NB.encodeInt16(info, infoOffset + P_FLAGS, flags);
 	}
 
 	void write(final OutputStream os) throws IOException {
-- 
1.6.1.399.g0d272
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 9 of 12 in “Merge API v2”
  1. 00/10 Merge API v2Shawn O. Pearce, Jan 22, 2009
  2. 01/10 Fix TreeWalk.idEqual when both trees are missing the pathShawn O. Pearce, Jan 22, 2009
  3. 02/10 Expose the raw path for the current entry of a TreeWalkShawn O. Pearce, Jan 22, 2009
  4. 03/10 Expose DirCacheEntry.getFileMode as a utility functionShawn O. Pearce, Jan 22, 2009
  5. 04/10 Add writeTree support to DirCacheShawn O. Pearce, Jan 22, 2009
  6. 05/10 Allow a DirCache to be created with no backing store fileShawn O. Pearce, Jan 22, 2009
  7. 06/10 Allow CanonicalTreeParsers to be created with a UTF-8 path prefixShawn O. Pearce, Jan 22, 2009
  8. 07/10 Recursively load an entire tree into a DirCacheBuilderShawn O. Pearce, Jan 22, 2009
  9. 08/10 Allow DirCacheEntry instances to be created with stage > 0Shawn O. Pearce, Jan 22, 2009
  10. 09/10 Define a basic merge API, and a two-way tree merge strategyShawn O. Pearce, Jan 22, 2009
  11. 10/10 Add a few simple merge test casesShawn O. Pearce, Jan 22, 2009
  12. Robin RosenbergJan 23, 2009

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.