git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 4/8] Allow a DirCache to be created with no backing store file
Date: Mon, 13 Oct 2008 14:10:13 -0700	[thread overview]
Message-ID: <1223932217-4771-5-git-send-email-spearce@spearce.org> (raw)
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

  reply	other threads:[~2008-10-13 21:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-13 21:10 [JGIT PATCH 0/8] Crude merge support Shawn O. Pearce
2008-10-13 21:10 ` [JGIT PATCH 1/8] Expose the raw path for the current entry of a TreeWalk Shawn O. Pearce
2008-10-13 21:10   ` [JGIT PATCH 2/8] Expose DirCacheEntry.getFileMode as a utility function Shawn O. Pearce
2008-10-13 21:10     ` [JGIT PATCH 3/8] Add writeTree support to DirCache Shawn O. Pearce
2008-10-13 21:10       ` Shawn O. Pearce [this message]
2008-10-13 21:10         ` [JGIT PATCH 5/8] Allow CanonicalTreeParsers to be created with a UTF-8 path prefix Shawn O. Pearce
2008-10-13 21:10           ` [JGIT PATCH 6/8] Recursively load an entire tree into a DirCacheBuilder Shawn O. Pearce
2008-10-13 21:10             ` [JGIT PATCH 7/8] Allow DirCacheEntry instances to be created with stage > 0 Shawn O. Pearce
2008-10-13 21:10               ` [JGIT PATCH 8/8] Define a basic merge API, and a two-way tree merge strategy Shawn O. Pearce
2008-10-23 21:14                 ` Robin Rosenberg
2009-01-15 21:05                   ` Robin Rosenberg
2009-01-15 21:09                     ` Shawn O. Pearce
2009-01-17 19:16                       ` Tomi Pakarinen
2009-01-18 20:21                         ` Robin Rosenberg
2009-01-19 17:42                         ` Shawn O. Pearce
2009-01-19 17:51                           ` Shawn O. Pearce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1223932217-4771-5-git-send-email-spearce@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).