summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-10-17 23:10:47 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-10-17 23:10:47 -0700
commite51e06946f4ca70b6f3286593cc1406037b628a9 (patch)
tree2457680d6575ea3ddf134175758363e3ca2c8d6e
parentf5e5b98c3a993873bfbdd19ef28d14f8ccca4b0c (diff)
downloadjgit-e51e06946f4ca70b6f3286593cc1406037b628a9.tar.gz
jgit-e51e06946f4ca70b6f3286593cc1406037b628a9.zip
Update CachedObjectDirectory when inserting objects
If an ObjectInserter is created from a CachedObjectDirectory, we need to ensure the cache is updated whenever a new loose object is actually added to the loose objects directory, otherwise a future read from an ObjectReader on the CachedObjectDirectory might not be able to open the newly created object. We mostly had the infrastructure in place to implement this due to the injection of unpacked large deltas, but we didn't have a way to pass the ObjectId from ObjectDirectoryInserter to CachedObjectDirectory, because the inserter was using the underlying ObjectDirectory and not the CachedObjectDirectory. Redirecting to CachedObjectDirectory ensures the cache is updated. Change-Id: I1f7bdfacc7ad77ebdb885f655e549cc570652225 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java11
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java24
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java13
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java4
4 files changed, 37 insertions, 15 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java
index 9bad71d8d7..9e137be8ba 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java
@@ -50,6 +50,7 @@ import java.util.Set;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.AnyObjectId;
+import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectId;
@@ -112,11 +113,6 @@ class CachedObjectDirectory extends FileObjectDatabase {
}
@Override
- public ObjectDirectoryInserter newInserter() {
- return wrapped.newInserter();
- }
-
- @Override
public ObjectDatabase newCachedDatabase() {
return this;
}
@@ -132,6 +128,11 @@ class CachedObjectDirectory extends FileObjectDatabase {
}
@Override
+ Config getConfig() {
+ return wrapped.getConfig();
+ }
+
+ @Override
AlternateHandle[] myAlternates() {
if (alts == null) {
AlternateHandle[] src = wrapped.myAlternates();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java
index 8bd3751010..4e9f5e9823 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java
@@ -49,6 +49,7 @@ import java.util.Set;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.AnyObjectId;
+import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
@@ -67,7 +68,9 @@ abstract class FileObjectDatabase extends ObjectDatabase {
}
@Override
- public abstract ObjectDirectoryInserter newInserter();
+ public ObjectDirectoryInserter newInserter() {
+ return new ObjectDirectoryInserter(this, getConfig());
+ }
/**
* Does the requested object exist in this database?
@@ -83,6 +86,23 @@ abstract class FileObjectDatabase extends ObjectDatabase {
return hasObjectImpl1(objectId) || hasObjectImpl2(objectId.name());
}
+ /**
+ * Compute the location of a loose object file.
+ *
+ * @param objectId
+ * identity of the loose object to map to the directory.
+ * @return location of the object, if it were to exist as a loose object.
+ */
+ File fileFor(final AnyObjectId objectId) {
+ return fileFor(objectId.name());
+ }
+
+ File fileFor(final String objectName) {
+ final String d = objectName.substring(0, 2);
+ final String f = objectName.substring(2);
+ return new File(new File(getDirectory(), d), f);
+ }
+
final boolean hasObjectImpl1(final AnyObjectId objectId) {
if (hasObject1(objectId))
return true;
@@ -110,6 +130,8 @@ abstract class FileObjectDatabase extends ObjectDatabase {
abstract void resolve(Set<ObjectId> matches, AbbreviatedObjectId id)
throws IOException;
+ abstract Config getConfig();
+
/**
* Open an object from this database.
* <p>
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java
index e7ccba0820..86e19f4c5d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java
@@ -204,14 +204,9 @@ public class ObjectDirectory extends FileObjectDatabase {
* identity of the loose object to map to the directory.
* @return location of the object, if it were to exist as a loose object.
*/
+ @Override
public File fileFor(final AnyObjectId objectId) {
- return fileFor(objectId.name());
- }
-
- private File fileFor(final String objectName) {
- final String d = objectName.substring(0, 2);
- final String f = objectName.substring(2);
- return new File(new File(objects, d), f);
+ return super.fileFor(objectId);
}
/**
@@ -515,6 +510,10 @@ public class ObjectDirectory extends FileObjectDatabase {
return false;
}
+ Config getConfig() {
+ return config;
+ }
+
private void insertPack(final PackFile pf) {
PackList o, n;
do {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java
index 074ebb9617..16cb8aa35c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java
@@ -66,13 +66,13 @@ import org.eclipse.jgit.lib.ObjectInserter;
/** Creates loose objects in a {@link ObjectDirectory}. */
class ObjectDirectoryInserter extends ObjectInserter {
- private final ObjectDirectory db;
+ private final FileObjectDatabase db;
private final Config config;
private Deflater deflate;
- ObjectDirectoryInserter(final ObjectDirectory dest, final Config cfg) {
+ ObjectDirectoryInserter(final FileObjectDatabase dest, final Config cfg) {
db = dest;
config = cfg;
}