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;
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());
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();
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());
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());
return ctx.getShallowCommits();
}
+ @Override
+ public ObjectInserter getCreatedFromInserter() {
+ return DfsInserter.this;
+ }
+
@Override
public void close() {
ctx.close();
@Override
public ObjectReader newReader() {
- return new WindowCursor(db);
+ return new WindowCursor(db, this);
}
@Override
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
+import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.InflaterCache;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.ProgressMonitor;
private DeltaBaseCache baseCache;
+ @Nullable
+ private final ObjectInserter createdFromInserter;
+
final FileObjectDatabase db;
WindowCursor(FileObjectDatabase db) {
this.db = db;
+ this.createdFromInserter = null;
+ }
+
+ WindowCursor(FileObjectDatabase db,
+ @Nullable ObjectDirectoryInserter createdFromInserter) {
+ this.db = db;
+ this.createdFromInserter = createdFromInserter;
}
DeltaBaseCache getDeltaBaseCache() {
return WindowCache.getStreamFileThreshold();
}
+ @Override
+ @Nullable
+ public ObjectInserter getCreatedFromInserter() {
+ return createdFromInserter;
+ }
+
/** Release the current window cursor. */
@Override
public void close() {
}
public ObjectReader newReader() {
- return delegate().newReader();
+ final ObjectReader dr = delegate().newReader();
+ return new ObjectReader.Filter() {
+ @Override
+ protected ObjectReader delegate() {
+ return dr;
+ }
+
+ @Override
+ public ObjectInserter getCreatedFromInserter() {
+ return ObjectInserter.Filter.this;
+ }
+ };
}
public void flush() throws IOException {
* visible to the repository. The returned reader should only be used from
* the same thread as the inserter. Objects written by this inserter may not
* be visible to {@code this.newReader().newReader()}.
+ * <p>
+ * The returned reader should return this inserter instance from {@link
+ * ObjectReader#getCreatedFromInserter()}.
*
* @since 3.5
* @return reader for any object, including an object recently inserted by
import java.util.List;
import java.util.Set;
+import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs;
return null;
}
+ /**
+ * @return the {@link ObjectInserter} from which this reader was created
+ * using {@code inserter.newReader()}, or null if this reader was not
+ * created from an inserter.
+ * @since 4.4
+ */
+ @Nullable
+ public ObjectInserter getCreatedFromInserter() {
+ return null;
+ }
+
/**
* Release any resources used by this reader.
* <p>
return delegate().getBitmapIndex();
}
+ @Override
+ @Nullable
+ public ObjectInserter getCreatedFromInserter() {
+ return delegate().getCreatedFromInserter();
+ }
+
@Override
public void close() {
delegate().close();