summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorDave Borowitz <dborowitz@google.com>2016-04-25 13:36:46 -0400
committerDave Borowitz <dborowitz@google.com>2016-04-26 17:21:37 -0400
commitadff322a698b2f248180c0a2c81dbeaf50015420 (patch)
treeaedb49013427eda5c909318842671fbc5326c574 /org.eclipse.jgit.test/tst
parent8a26d0577f0c5eb391d82fefec1a52c2d69bdee6 (diff)
downloadjgit-adff322a698b2f248180c0a2c81dbeaf50015420.tar.gz
jgit-adff322a698b2f248180c0a2c81dbeaf50015420.zip
Expose the ObjectInserter that created an ObjectReader
We've found in Gerrit Code Review that it is common to pass around both an ObjectReader (or more commonly a RevWalk wrapping one) and an ObjectInserter. These code paths often assume that the ObjectReader can read back any objects created by the ObjectInserter without flushing. However, we previously had no way to enforce that constraint programmatically, leading to hard-to-spot problems. Provide a solution by exposing the ObjectInserter that created an ObjectReader, when known. Callers can either continue passing both objects and check: reader.getCreatedFromInserter() == inserter or they can just pass around ObjectReader and extract the inserter when it's needed (checking that it's not null at usage time). Change-Id: Ibbf5d1968b506f6b47030ab1b046ffccb47352ea
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java5
1 files changed, 5 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java
index 11a092468c..74790f72c5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java
@@ -45,6 +45,7 @@ package org.eclipse.jgit.internal.storage.dfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
@@ -97,6 +98,7 @@ public class DfsInserterTest {
assertEquals(0, db.getObjectDatabase().listPacks().size());
ObjectReader reader = ins.newReader();
+ assertSame(ins, reader.getCreatedFromInserter());
assertEquals("foo", readString(reader.open(id1)));
assertEquals("bar", readString(reader.open(id2)));
assertEquals(0, db.getObjectDatabase().listPacks().size());
@@ -118,6 +120,7 @@ public class DfsInserterTest {
assertEquals(0, db.getObjectDatabase().listPacks().size());
ObjectReader reader = ins.newReader();
+ assertSame(ins, reader.getCreatedFromInserter());
assertTrue(Arrays.equals(data, readStream(reader.open(id1))));
assertEquals(0, db.getObjectDatabase().listPacks().size());
ins.flush();
@@ -136,6 +139,7 @@ public class DfsInserterTest {
assertEquals(1, db.getObjectDatabase().listPacks().size());
ObjectReader reader = ins.newReader();
+ assertSame(ins, reader.getCreatedFromInserter());
assertEquals("foo", readString(reader.open(id1)));
assertEquals("bar", readString(reader.open(id2)));
assertEquals(1, db.getObjectDatabase().listPacks().size());
@@ -154,6 +158,7 @@ public class DfsInserterTest {
assertFalse(abbr1.equals(abbr2));
ObjectReader reader = ins.newReader();
+ assertSame(ins, reader.getCreatedFromInserter());
Collection<ObjectId> objs;
objs = reader.resolve(AbbreviatedObjectId.fromString(abbr1));
assertEquals(1, objs.size());