Browse Source

Remove Repository.openObject(ObjectReader, AnyObjectId)

Going through ObjectReader.openObject(AnyObjectId) is faster, but
also produces cleaner application level code.  The error checking
is done inside of the openObject method, which means it can be
removed from the application code.

Change-Id: Ia927b448d128005e1640362281585023582b1a3a
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
1ad2feb7b3
  1. 9
      org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogGenerator.java
  2. 21
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
  3. 9
      org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObject.java
  4. 4
      org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
  5. 2
      org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java
  6. 8
      org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java
  7. 15
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java

9
org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogGenerator.java

@ -78,15 +78,13 @@ import org.eclipse.jgit.diff.EditList;
import org.eclipse.jgit.diff.MyersDiff; import org.eclipse.jgit.diff.MyersDiff;
import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.iplog.Committer.ActiveRange; import org.eclipse.jgit.iplog.Committer.ActiveRange;
import org.eclipse.jgit.lib.BlobBasedConfig; import org.eclipse.jgit.lib.BlobBasedConfig;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.lib.MutableObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
@ -418,10 +416,7 @@ public class IpLogGenerator {
private byte[] openBlob(int side) throws IOException { private byte[] openBlob(int side) throws IOException {
tw.getObjectId(idbuf, side); tw.getObjectId(idbuf, side);
ObjectLoader ldr = db.openObject(curs, idbuf); return curs.openObject(idbuf, Constants.OBJ_BLOB).getCachedBytes();
if (ldr == null)
throw new MissingObjectException(idbuf.copy(), Constants.OBJ_BLOB);
return ldr.getCachedBytes();
} }
/** /**

21
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

@ -238,27 +238,6 @@ public abstract class Repository {
} }
} }
/**
* @param curs
* temporary working space associated with the calling thread.
* @param id
* SHA-1 of an object.
*
* @return a {@link ObjectLoader} for accessing the data of the named
* object, or null if the object does not exist.
* @throws IOException
* @deprecated Use {code newObjectReader().open(id)}.
*/
@Deprecated
public ObjectLoader openObject(ObjectReader curs, AnyObjectId id)
throws IOException {
try {
return curs.openObject(id);
} catch (MissingObjectException notFound) {
return null;
}
}
/** /**
* @param id * @param id
* SHA'1 of a blob * SHA'1 of a blob

9
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObject.java

@ -51,7 +51,6 @@ import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
/** Base object type accessed during revision walking. */ /** Base object type accessed during revision walking. */
public abstract class RevObject extends ObjectId { public abstract class RevObject extends ObjectId {
@ -78,13 +77,7 @@ public abstract class RevObject extends ObjectId {
final byte[] loadCanonical(final RevWalk walk) throws IOException, final byte[] loadCanonical(final RevWalk walk) throws IOException,
MissingObjectException, IncorrectObjectTypeException, MissingObjectException, IncorrectObjectTypeException,
CorruptObjectException { CorruptObjectException {
final ObjectLoader ldr = walk.db.openObject(walk.curs, this); return walk.curs.openObject(this, getType()).getCachedBytes();
if (ldr == null)
throw new MissingObjectException(this, getType());
final byte[] data = ldr.getCachedBytes();
if (getType() != ldr.getType())
throw new IncorrectObjectTypeException(this, getType());
return data;
} }
/** /**

4
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java

@ -720,9 +720,7 @@ public class RevWalk implements Iterable<RevCommit> {
throws MissingObjectException, IOException { throws MissingObjectException, IOException {
RevObject r = objects.get(id); RevObject r = objects.get(id);
if (r == null) { if (r == null) {
final ObjectLoader ldr = db.openObject(curs, id); final ObjectLoader ldr = curs.openObject(id);
if (ldr == null)
throw new MissingObjectException(id.toObjectId(), "unknown");
final byte[] data = ldr.getCachedBytes(); final byte[] data = ldr.getCachedBytes();
final int type = ldr.getType(); final int type = ldr.getType();
switch (type) { switch (type) {

2
org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java

@ -730,7 +730,7 @@ public class PackWriter {
private void writeWholeObjectDeflate(final ObjectToPack otp) private void writeWholeObjectDeflate(final ObjectToPack otp)
throws IOException { throws IOException {
final ObjectLoader loader = db.openObject(reader, otp); final ObjectLoader loader = reader.openObject(otp, otp.getType());
final byte[] data = loader.getCachedBytes(); final byte[] data = loader.getCachedBytes();
out.writeHeader(otp, data.length); out.writeHeader(otp, data.length);
deflater.reset(); deflater.reset();

8
org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java

@ -593,8 +593,10 @@ public class IndexPack {
continue; continue;
if (needBaseObjectIds) if (needBaseObjectIds)
baseObjectIds.add(baseId); baseObjectIds.add(baseId);
final ObjectLoader ldr = repo.openObject(readCurs, baseId); final ObjectLoader ldr;
if (ldr == null) { try {
ldr = readCurs.openObject(baseId);
} catch (MissingObjectException notFound) {
missing.add(baseId); missing.add(baseId);
continue; continue;
} }
@ -856,7 +858,7 @@ public class IndexPack {
try { try {
final ObjectLoader ldr = readCurs.openObject(id, type); final ObjectLoader ldr = readCurs.openObject(id, type);
final byte[] existingData = ldr.getCachedBytes(); final byte[] existingData = ldr.getCachedBytes();
if (ldr.getType() != type || !Arrays.equals(data, existingData)) { if (!Arrays.equals(data, existingData)) {
throw new IOException(MessageFormat.format(JGitText.get().collisionOn, id.name())); throw new IOException(MessageFormat.format(JGitText.get().collisionOn, id.name()));
} }
} catch (MissingObjectException notLocal) { } catch (MissingObjectException notLocal) {

15
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java

@ -54,9 +54,8 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.lib.MutableObjectId;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
/** Parses raw Git trees from the canonical semi-text/semi-binary format. */ /** Parses raw Git trees from the canonical semi-text/semi-binary format. */
public class CanonicalTreeParser extends AbstractTreeIterator { public class CanonicalTreeParser extends AbstractTreeIterator {
@ -199,17 +198,7 @@ public class CanonicalTreeParser extends AbstractTreeIterator {
public void reset(final Repository repo, final AnyObjectId id, public void reset(final Repository repo, final AnyObjectId id,
final ObjectReader curs) final ObjectReader curs)
throws IncorrectObjectTypeException, IOException { throws IncorrectObjectTypeException, IOException {
final ObjectLoader ldr = repo.openObject(curs, id); reset(curs.openObject(id, Constants.OBJ_TREE).getCachedBytes());
if (ldr == null) {
final ObjectId me = id.toObjectId();
throw new MissingObjectException(me, Constants.TYPE_TREE);
}
final byte[] subtreeData = ldr.getCachedBytes();
if (ldr.getType() != Constants.OBJ_TREE) {
final ObjectId me = id.toObjectId();
throw new IncorrectObjectTypeException(me, Constants.TYPE_TREE);
}
reset(subtreeData);
} }
@Override @Override

Loading…
Cancel
Save