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.RawText;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.iplog.Committer.ActiveRange;
import org.eclipse.jgit.lib.BlobBasedConfig;
import org.eclipse.jgit.lib.Constants;
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.Repository;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
@ -418,10 +416,7 @@ public class IpLogGenerator {
private byte[] openBlob(int side) throws IOException {
tw.getObjectId(idbuf, side);
ObjectLoader ldr = db.openObject(curs, idbuf);
if (ldr == null)
throw new MissingObjectException(idbuf.copy(), Constants.OBJ_BLOB);
return ldr.getCachedBytes();
return curs.openObject(idbuf, Constants.OBJ_BLOB).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
* 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.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
/** Base object type accessed during revision walking. */
public abstract class RevObject extends ObjectId {
@ -78,13 +77,7 @@ public abstract class RevObject extends ObjectId {
final byte[] loadCanonical(final RevWalk walk) throws IOException,
MissingObjectException, IncorrectObjectTypeException,
CorruptObjectException {
final ObjectLoader ldr = walk.db.openObject(walk.curs, this);
if (ldr == null)
throw new MissingObjectException(this, getType());
final byte[] data = ldr.getCachedBytes();
if (getType() != ldr.getType())
throw new IncorrectObjectTypeException(this, getType());
return data;
return walk.curs.openObject(this, getType()).getCachedBytes();
}
/**

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

@ -720,9 +720,7 @@ public class RevWalk implements Iterable<RevCommit> {
throws MissingObjectException, IOException {
RevObject r = objects.get(id);
if (r == null) {
final ObjectLoader ldr = db.openObject(curs, id);
if (ldr == null)
throw new MissingObjectException(id.toObjectId(), "unknown");
final ObjectLoader ldr = curs.openObject(id);
final byte[] data = ldr.getCachedBytes();
final int type = ldr.getType();
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)
throws IOException {
final ObjectLoader loader = db.openObject(reader, otp);
final ObjectLoader loader = reader.openObject(otp, otp.getType());
final byte[] data = loader.getCachedBytes();
out.writeHeader(otp, data.length);
deflater.reset();

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

@ -593,8 +593,10 @@ public class IndexPack {
continue;
if (needBaseObjectIds)
baseObjectIds.add(baseId);
final ObjectLoader ldr = repo.openObject(readCurs, baseId);
if (ldr == null) {
final ObjectLoader ldr;
try {
ldr = readCurs.openObject(baseId);
} catch (MissingObjectException notFound) {
missing.add(baseId);
continue;
}
@ -856,7 +858,7 @@ public class IndexPack {
try {
final ObjectLoader ldr = readCurs.openObject(id, type);
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()));
}
} 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.MutableObjectId;
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.Repository;
/** Parses raw Git trees from the canonical semi-text/semi-binary format. */
public class CanonicalTreeParser extends AbstractTreeIterator {
@ -199,17 +198,7 @@ public class CanonicalTreeParser extends AbstractTreeIterator {
public void reset(final Repository repo, final AnyObjectId id,
final ObjectReader curs)
throws IncorrectObjectTypeException, IOException {
final ObjectLoader ldr = repo.openObject(curs, id);
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);
reset(curs.openObject(id, Constants.OBJ_TREE).getCachedBytes());
}
@Override

Loading…
Cancel
Save