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

[JGIT PATCH 4/8] Allow a DirCache to be created with no backing store file

From
Shawn O. Pearce <spearce@spearce.org>
Date
Oct 13, 2008, 21:10 UTC
Message-ID
<1223932217-4771-5-git-send-email-spearce@spearce.org>
In-Reply-To
<1223932217-4771-4-git-send-email-spearce@spearce.org>

This permits using a DirCache as a temporary storage area in memory only, with no chance of it being written out to disk.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/dircache/DirCache.java    |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
index b3c57ad..c5a4f91 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
@@ -111,6 +111,17 @@ static int cmp(final byte[] aPath, final int aLen, final byte[] bPath,
 	}
 
 	/**
+	 * Create a new empty index which is never stored on disk.
+	 * 
+	 * @return an empty cache which has no backing store file. The cache may not
+	 *         be read or written, but it may be queried and updated (in
+	 *         memory).
+	 */
+	public static DirCache newInCore() {
+		return new DirCache(null);
+	}
+
+	/**
 	 * Create a new in-core index representation and read an index from disk.
 	 * <p>
 	 * The new index will be read before it is returned to the caller. Read
@@ -297,6 +308,8 @@ void replace(final DirCacheEntry[] e, final int cnt) {
 	 *             library does not support.
 	 */
 	public void read() throws IOException, CorruptObjectException {
+		if (liveFile == null)
+			throw new IOException("DirCache does not have a backing file");
 		if (!liveFile.exists())
 			clear();
 		else if (liveFile.lastModified() != lastModified) {
@@ -407,6 +420,8 @@ private static boolean is_DIRC(final byte[] hdr) {
 	 *             hold the lock.
 	 */
 	public boolean lock() throws IOException {
+		if (liveFile == null)
+			throw new IOException("DirCache does not have a backing file");
 		final LockFile tmp = new LockFile(liveFile);
 		if (tmp.lock()) {
 			tmp.setNeedStatInformation(true);
@@ -515,6 +530,8 @@ public boolean commit() {
 	}
 
 	private void requireLocked(final LockFile tmp) {
+		if (liveFile == null)
+			throw new IllegalStateException("DirCache is not locked");
 		if (tmp == null)
 			throw new IllegalStateException("DirCache "
 					+ liveFile.getAbsolutePath() + " not locked.");
-- 
1.6.0.2.706.g340fc
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 5 of 16 in “Crude merge support”
  1. 0/8 Crude merge supportShawn O. Pearce, Oct 13, 2008
  2. 1/8 Expose the raw path for the current entry of a TreeWalkShawn O. Pearce, Oct 13, 2008
  3. 2/8 Expose DirCacheEntry.getFileMode as a utility functionShawn O. Pearce, Oct 13, 2008
  4. 3/8 Add writeTree support to DirCacheShawn O. Pearce, Oct 13, 2008
  5. 4/8 Allow a DirCache to be created with no backing store fileShawn O. Pearce, Oct 13, 2008
  6. 5/8 Allow CanonicalTreeParsers to be created with a UTF-8 path prefixShawn O. Pearce, Oct 13, 2008
  7. 6/8 Recursively load an entire tree into a DirCacheBuilderShawn O. Pearce, Oct 13, 2008
  8. 7/8 Allow DirCacheEntry instances to be created with stage > 0Shawn O. Pearce, Oct 13, 2008
  9. 8/8 Define a basic merge API, and a two-way tree merge strategyShawn O. Pearce, Oct 13, 2008
  10. Robin RosenbergOct 23, 2008
  11. Robin RosenbergJan 15, 2009
  12. Shawn O. PearceJan 15, 2009
  13. Tomi PakarinenJan 17, 2009
  14. Robin RosenbergJan 18, 2009
  15. Shawn O. PearceJan 19, 2009
  16. Shawn O. PearceJan 19, 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.