From 9ac4c24771de067611edd3631dc71de0c2f5ecd8 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 22 Jan 2009 15:28:05 -0800 Subject: [PATCH] Allow a DirCache to be created with no backing store file 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 Signed-off-by: Robin Rosenberg --- .../src/org/spearce/jgit/dircache/DirCache.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 5c13902c..8eb4022e 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 @@ public class DirCache { } /** + * 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. *

* The new index will be read before it is returned to the caller. Read @@ -297,6 +308,8 @@ public class DirCache { * 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 @@ public class DirCache { * 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 class DirCache { } 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."); -- 2.11.4.GIT