if (o == null)
break;
- final byte[] bin = db.openObject(o).getCachedBytes();
+ final byte[] bin = db.open(o, o.getType()).getCachedBytes();
oc.checkCommit(bin);
assertHash(o, bin);
}
if (o == null)
break;
- final byte[] bin = db.openObject(o).getCachedBytes();
+ final byte[] bin = db.open(o, o.getType()).getCachedBytes();
oc.check(o.getType(), bin);
assertHash(o, bin);
}
import java.util.ArrayList;
import java.util.List;
-import org.kohsuke.args4j.Argument;
-import org.kohsuke.args4j.Option;
-
import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.diff.MyersDiff;
import org.eclipse.jgit.diff.RawText;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_ShowDiffs")
class Diff extends TextBuiltin {
private RawText getRawText(ObjectId id) throws IOException {
if (id.equals(ObjectId.zeroId()))
return new RawText(new byte[] { });
- return new RawText(db.openBlob(id).getCachedBytes());
+ return new RawText(db.open(id, Constants.OBJ_BLOB).getCachedBytes());
}
}
import java.text.MessageFormat;
-import org.kohsuke.args4j.Argument;
-import org.kohsuke.args4j.Option;
-import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.PersonIdent;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_CreateATag")
class Tag extends TextBuiltin {
, tagName.substring(Constants.R_TAGS.length())));
}
- final ObjectLoader ldr = db.openObject(object);
- if (ldr == null)
- throw new MissingObjectException(object, "any");
+ final ObjectLoader ldr = db.open(object);
org.eclipse.jgit.lib.Tag tag = new org.eclipse.jgit.lib.Tag(db);
tag.setObjId(object);
final File[] out1 = pack(eden, o1);
assertEquals(o1.name(), parse(o1).name());
- final ObjectLoader load1 = db.openBlob(o1);
+ final ObjectLoader load1 = db.open(o1, Constants.OBJ_BLOB);
assertNotNull(load1);
final RevObject o2 = writeBlob(eden, "o2");
// earlier still resolve the object, even though its underlying
// pack is gone, but the object still exists.
//
- final ObjectLoader load2 = db.openBlob(o1);
+ final ObjectLoader load2 = db.open(o1, Constants.OBJ_BLOB);
assertNotNull(load2);
assertNotSame(load1, load2);
final ObjectLoader or;
id = ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259");
- or = db.openObject(id);
+ or = db.open(id);
assertNotNull(or);
assertTrue(or instanceof PackedObjectLoader);
assertEquals(Constants.OBJ_BLOB, or.getType());
private void doCacheTests() throws IOException {
for (final TestObject o : toLoad) {
- final ObjectLoader or = db.openObject(o.id);
+ final ObjectLoader or = db.open(o.id, o.type);
assertNotNull(or);
assertTrue(or instanceof PackedObjectLoader);
assertEquals(o.type, or.getType());
//
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
packHeader(pack, 2);
- copy(pack, src.openObject(N));
- copy(pack,src.openObject(s.parseBody(N).getTree()));
+ copy(pack, src.open(N));
+ copy(pack,src.open(s.parseBody(N).getTree()));
digest(pack);
final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(256);
//
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
packHeader(pack, 2);
- copy(pack, src.openObject(N));
- copy(pack,src.openObject(s.parseBody(N).getTree()));
+ copy(pack, src.open(N));
+ copy(pack,src.open(s.parseBody(N).getTree()));
digest(pack);
final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(256);
//
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
packHeader(pack, 1);
- copy(pack, src.openObject(N));
+ copy(pack, src.open(N));
digest(pack);
final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(256);
public BlobBasedConfig(Config base, final Repository r,
final ObjectId objectId) throws IOException, ConfigInvalidException {
super(base);
- final ObjectLoader loader = r.openBlob(objectId);
- if (loader == null)
- throw new IOException(MessageFormat.format(JGitText.get().blobNotFound, objectId));
- fromText(RawParseUtils.decode(loader.getBytes()));
+ ObjectLoader loader = r.open(objectId, Constants.OBJ_BLOB);
+ fromText(RawParseUtils.decode(loader.getCachedBytes()));
}
/**
if (tree == null)
throw new FileNotFoundException(MessageFormat.format(JGitText.get().entryNotFoundByPath, path));
final ObjectId blobId = tree.getObjectId(0);
- final ObjectLoader loader = tree.getRepository().openBlob(blobId);
- if (loader == null)
- throw new IOException(MessageFormat.format(JGitText.get().blobNotFoundForPath
- , blobId, path));
- fromText(RawParseUtils.decode(loader.getBytes()));
+ ObjectLoader loader = r.open(blobId,Constants.OBJ_BLOB);
+ fromText(RawParseUtils.decode(loader.getCachedBytes()));
}
}
* @throws IOException
*/
public ObjectLoader openReader() throws IOException {
- return getRepository().openBlob(getId());
+ return getRepository().open(getId(), Constants.OBJ_BLOB);
}
public void accept(final TreeVisitor tv, final int flags)
uid = -1;
gid = -1;
try {
- size = (int) db.openBlob(f.getId()).getSize();
+ size = (int) db.open(f.getId(), Constants.OBJ_BLOB).getSize();
} catch (IOException e) {
e.printStackTrace();
size = -1;
* @throws IOException
*/
public void checkoutEntry(File wd, Entry e) throws IOException {
- ObjectLoader ol = db.openBlob(e.sha1);
+ ObjectLoader ol = db.open(e.sha1, Constants.OBJ_BLOB);
byte[] bytes = ol.getBytes();
File file = new File(wd, e.getName());
file.delete();
import java.io.IOException;
+import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
/**
*/
public ObjectLoader openObject(final AnyObjectId objectId)
throws IOException {
+ return openObject(objectId, ObjectReader.OBJ_ANY);
+ }
+
+ /**
+ * Open an object from this database.
+ * <p>
+ * This is a one-shot call interface which may be faster than allocating a
+ * {@link #newReader()} to perform the lookup.
+ *
+ * @param objectId
+ * identity of the object to open.
+ * @param typeHint
+ * hint about the type of object being requested;
+ * {@link ObjectReader#OBJ_ANY} if the object type is not known,
+ * or does not matter to the caller.
+ * @return a {@link ObjectLoader} for accessing the object.
+ * @throws MissingObjectException
+ * the object does not exist.
+ * @throws IncorrectObjectTypeException
+ * typeHint was not OBJ_ANY, and the object's actual type does
+ * not match typeHint.
+ * @throws IOException
+ * the object store cannot be accessed.
+ */
+ public ObjectLoader openObject(AnyObjectId objectId, int typeHint)
+ throws MissingObjectException, IncorrectObjectTypeException,
+ IOException {
final ObjectReader or = newReader();
try {
- return or.openObject(objectId);
+ return or.openObject(objectId, typeHint);
} finally {
or.release();
}
* @throws MissingObjectException
* the object does not exist.
* @throws IOException
+ * the object store cannot be accessed.
*/
public ObjectLoader openObject(AnyObjectId objectId)
throws MissingObjectException, IOException {
*
* @param objectId
* identity of the object to open.
- *@param typeHint
+ * @param typeHint
* hint about the type of object being requested;
* {@link #OBJ_ANY} if the object type is not known, or does not
* matter to the caller.
* typeHint was not OBJ_ANY, and the object's actual type does
* not match typeHint.
* @throws IOException
+ * the object store cannot be accessed.
*/
public abstract ObjectLoader openObject(AnyObjectId objectId, int typeHint)
- throws MissingObjectException, IncorrectObjectTypeException, IOException;
+ throws MissingObjectException, IncorrectObjectTypeException,
+ IOException;
/**
* Release any resources used by this reader.
}
/**
- * @param id
- * SHA-1 of an object.
+ * Open an object from this repository.
+ * <p>
+ * This is a one-shot call interface which may be faster than allocating a
+ * {@link #newObjectReader()} to perform the lookup.
*
- * @return a {@link ObjectLoader} for accessing the data of the named
- * object, or null if the object does not exist.
- * @throws IOException
- */
- public ObjectLoader openObject(final AnyObjectId id)
- throws IOException {
- try {
- return getObjectDatabase().openObject(id);
- } catch (MissingObjectException notFound) {
- // Legacy API, return null
- return null;
- }
- }
-
- /**
- * @param id
- * SHA'1 of a blob
- * @return an {@link ObjectLoader} for accessing the data of a named blob
+ * @param objectId
+ * identity of the object to open.
+ * @return a {@link ObjectLoader} for accessing the object.
+ * @throws MissingObjectException
+ * the object does not exist.
* @throws IOException
+ * the object store cannot be accessed.
*/
- public ObjectLoader openBlob(final ObjectId id) throws IOException {
- return openObject(id);
+ public ObjectLoader open(final AnyObjectId objectId)
+ throws MissingObjectException, IOException {
+ return getObjectDatabase().openObject(objectId);
}
/**
- * @param id
- * SHA'1 of a tree
- * @return an {@link ObjectLoader} for accessing the data of a named tree
+ * Open an object from this repository.
+ * <p>
+ * This is a one-shot call interface which may be faster than allocating a
+ * {@link #newObjectReader()} to perform the lookup.
+ *
+ * @param objectId
+ * identity of the object to open.
+ * @param typeHint
+ * hint about the type of object being requested;
+ * {@link ObjectReader#OBJ_ANY} if the object type is not known,
+ * or does not matter to the caller.
+ * @return a {@link ObjectLoader} for accessing the object.
+ * @throws MissingObjectException
+ * the object does not exist.
+ * @throws IncorrectObjectTypeException
+ * typeHint was not OBJ_ANY, and the object's actual type does
+ * not match typeHint.
* @throws IOException
+ * the object store cannot be accessed.
*/
- public ObjectLoader openTree(final ObjectId id) throws IOException {
- return openObject(id);
+ public ObjectLoader open(AnyObjectId objectId, int typeHint)
+ throws MissingObjectException, IncorrectObjectTypeException,
+ IOException {
+ return getObjectDatabase().openObject(objectId, typeHint);
}
/**
* @throws IOException
*/
public Object mapObject(final ObjectId id, final String refName) throws IOException {
- final ObjectLoader or = openObject(id);
- if (or == null)
+ final ObjectLoader or;
+ try {
+ or = open(id);
+ } catch (MissingObjectException notFound) {
return null;
- final byte[] raw = or.getBytes();
+ }
+ final byte[] raw = or.getCachedBytes();
switch (or.getType()) {
case Constants.OBJ_TREE:
- return makeTree(id, raw);
+ return new Tree(this, id, raw);
case Constants.OBJ_COMMIT:
- return makeCommit(id, raw);
+ return new Commit(this, id, raw);
case Constants.OBJ_TAG:
- return makeTag(id, refName, raw);
+ return new Tag(this, id, refName, raw);
case Constants.OBJ_BLOB:
return raw;
* @throws IOException for I/O error or unexpected object type.
*/
public Commit mapCommit(final ObjectId id) throws IOException {
- final ObjectLoader or = openObject(id);
- if (or == null)
+ final ObjectLoader or;
+ try {
+ or = open(id, Constants.OBJ_COMMIT);
+ } catch (MissingObjectException notFound) {
return null;
- final byte[] raw = or.getBytes();
- if (Constants.OBJ_COMMIT == or.getType())
- return new Commit(this, id, raw);
- throw new IncorrectObjectTypeException(id, Constants.TYPE_COMMIT);
- }
-
- private Commit makeCommit(final ObjectId id, final byte[] raw) {
- Commit ret = new Commit(this, id, raw);
- return ret;
+ }
+ return new Commit(this, id, or.getCachedBytes());
}
/**
* @throws IOException for I/O error or unexpected object type.
*/
public Tree mapTree(final ObjectId id) throws IOException {
- final ObjectLoader or = openObject(id);
- if (or == null)
+ final ObjectLoader or;
+ try {
+ or = open(id);
+ } catch (MissingObjectException notFound) {
return null;
- final byte[] raw = or.getBytes();
+ }
+ final byte[] raw = or.getCachedBytes();
switch (or.getType()) {
case Constants.OBJ_TREE:
return new Tree(this, id, raw);
}
}
- private Tree makeTree(final ObjectId id, final byte[] raw) throws IOException {
- Tree ret = new Tree(this, id, raw);
- return ret;
- }
-
- private Tag makeTag(final ObjectId id, final String refName, final byte[] raw) {
- Tag ret = new Tag(this, id, refName, raw);
- return ret;
- }
-
/**
* Access a tag by symbolic name.
*
* @throws IOException for I/O error or unexpected object type.
*/
public Tag mapTag(final String refName, final ObjectId id) throws IOException {
- final ObjectLoader or = openObject(id);
- if (or == null)
+ final ObjectLoader or;
+ try {
+ or = open(id);
+ } catch (MissingObjectException notFound) {
return null;
- final byte[] raw = or.getBytes();
- if (Constants.OBJ_TAG == or.getType())
- return new Tag(this, id, refName, raw);
+ }
+ if (or.getType() == Constants.OBJ_TAG)
+ return new Tag(this, id, refName, or.getCachedBytes());
return new Tag(this, id, refName, null);
}
private void ensureLoaded() throws IOException, MissingObjectException {
if (!isLoaded()) {
- final ObjectLoader or = db.openTree(getId());
- if (or == null)
- throw new MissingObjectException(getId(), Constants.TYPE_TREE);
- readTree(or.getBytes());
+ ObjectLoader ldr = db.open(getId(), Constants.OBJ_TREE);
+ readTree(ldr.getCachedBytes());
}
}