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>
This commit is contained in:
parent
9ba7bd4df4
commit
1ad2feb7b3
|
@ -78,15 +78,13 @@
|
|||
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 @@ private void scanProjectCommits(Project proj, RevCommit start)
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -238,27 +238,6 @@ public ObjectLoader openObject(final AnyObjectId id)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
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 @@ void parseBody(final RevWalk walk) throws MissingObjectException,
|
|||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -720,9 +720,7 @@ public RevObject parseAny(final AnyObjectId id)
|
|||
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) {
|
||||
|
|
|
@ -730,7 +730,7 @@ private void redoSearchForReuse(final ObjectToPack otp) throws IOException,
|
|||
|
||||
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();
|
||||
|
|
|
@ -593,8 +593,10 @@ private void fixThinPack(final ProgressMonitor progress) throws IOException {
|
|||
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 @@ private void verifySafeObject(final AnyObjectId id, final int type,
|
|||
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) {
|
||||
|
|
|
@ -54,9 +54,8 @@
|
|||
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 CanonicalTreeParser next() {
|
|||
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…
Reference in New Issue