Example usage for org.eclipse.jgit.errors MissingObjectException MissingObjectException

List of usage examples for org.eclipse.jgit.errors MissingObjectException MissingObjectException

Introduction

In this page you can find the example usage for org.eclipse.jgit.errors MissingObjectException MissingObjectException.

Prototype

public MissingObjectException(AbbreviatedObjectId id, int type) 

Source Link

Document

Construct a MissingObjectException for the specified object id.

Usage

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

private byte[] open(DiffEntry.Side side, DiffEntry entry) throws IOException {
    if (entry.getMode(side) == FileMode.MISSING)
        return EMPTY;

    if (entry.getMode(side).getObjectType() != Constants.OBJ_BLOB)
        return EMPTY;

    AbbreviatedObjectId id = entry.getId(side);
    if (!id.isComplete()) {
        Collection<ObjectId> ids = reader.resolve(id);
        if (ids.size() == 1) {
            throw new IllegalStateException();
            //                id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
            //                switch (side) {
            //                    case OLD:
            //                        entry.oldId = id;
            //                        break;
            //                    case NEW:
            //                        entry.newId = id;
            //                        break;
            //                }
        } else if (ids.size() == 0)
            throw new MissingObjectException(id, Constants.OBJ_BLOB);
        else//  w ww  .j a  v a 2  s.co  m
            throw new AmbiguousObjectException(id, ids);
    }

    try {
        ObjectLoader ldr = source.open(side, entry);
        int binaryFileThreshold = DEFAULT_BINARY_FILE_THRESHOLD;
        return ldr.getBytes(binaryFileThreshold);

    } catch (LargeObjectException.ExceedsLimit overLimit) {
        return BINARY;

    } catch (LargeObjectException.ExceedsByteArrayLimit overLimit) {
        return BINARY;

    } catch (LargeObjectException.OutOfMemory tooBig) {
        return BINARY;

    } catch (LargeObjectException tooBig) {
        tooBig.setObjectId(id.toObjectId());
        throw tooBig;
    }
}

From source file:com.madgag.agit.diff.LineContextDiffer.java

License:Open Source License

private byte[] open(ObjectReader reader, FileMode mode, AbbreviatedObjectId id) throws IOException {
    if (mode == FileMode.MISSING)
        return new byte[] {};

    if (mode.getObjectType() != Constants.OBJ_BLOB)
        return new byte[] {};

    if (!id.isComplete()) {
        Collection<ObjectId> ids = reader.resolve(id);
        if (ids.size() == 1)
            id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
        else if (ids.size() == 0)
            throw new MissingObjectException(id, Constants.OBJ_BLOB);
        else//from w w  w.j av a  2  s .c o  m
            throw new AmbiguousObjectException(id, ids);
    }

    ObjectLoader ldr = reader.open(id.toObjectId());
    return ldr.getCachedBytes(bigFileThreshold);
}

From source file:com.tasktop.c2c.server.scm.service.GitBrowseUtil.java

License:Open Source License

private static TreeWalk getTreeOnPath(MutableObjectId id, Repository repo, ObjectId rev, String path)
        throws MissingObjectException, IOException {

    RevTree tree = new RevWalk(repo).parseTree(rev);

    TreeWalk tw = new TreeWalk(repo);
    tw.reset(tree);/*from   w  w w .j a v  a 2s  . co  m*/
    tw.setRecursive(false);

    if (path == null || path.isEmpty() || "/".equals(path)) {
        id.fromObjectId(tree.getId());
        return tw;
    }

    PathFilter f = PathFilter.create(path);
    tw.setFilter(f);

    while (tw.next()) {
        if (f.isDone(tw)) {
            id.fromObjectId(tw.getObjectId(0));
            if (tw.isSubtree()) {
                tw.enterSubtree();
                return tw;
            } else {
                throw new MissingObjectException(tw.getObjectId(0), Constants.OBJ_TREE);
            }

        } else if (tw.isSubtree()) {
            tw.enterSubtree();
        }
    }
    return null;

}

From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java

License:Eclipse Distribution License

private void processBlob(final RevObject obj) throws TransportException {
    try {/*from   w  w  w  .  jav  a  2  s.  c  o m*/
        if (reader.has(obj, Constants.OBJ_BLOB))
            obj.add(COMPLETE);
        else
            throw new TransportException(MessageFormat.format(JGitText.get().cannotReadBlob, obj.name()),
                    new MissingObjectException(obj, Constants.TYPE_BLOB));
    } catch (IOException error) {
        throw new TransportException(MessageFormat.format(JGitText.get().cannotReadBlob, obj.name()), error);
    }
}

From source file:jbenchmarker.trace.git.GitExtraction.java

License:Open Source License

byte[] open(DiffEntry.Side side, DiffEntry entry) throws IOException {
    if (entry.getMode(side) == FileMode.MISSING) {
        return EMPTY;
    }/*from  www.ja v  a 2s  .c o  m*/

    if (entry.getMode(side).getObjectType() != Constants.OBJ_BLOB) {
        return EMPTY;
    }

    AbbreviatedObjectId id = entry.getId(side);
    if (!id.isComplete()) {
        Collection<ObjectId> ids = reader.resolve(id);
        if (ids.size() == 1) {
            //                id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
            //                switch (side) {
            //                    case OLD:
            //                        entry.oldId = id;
            //                        break;
            //                    case NEW:
            //                        entry.newId = id;
            //                        break;
            //                }
        } else if (ids.isEmpty()) {
            throw new MissingObjectException(id, Constants.OBJ_BLOB);
        } else {
            throw new AmbiguousObjectException(id, ids);
        }
    }
    ObjectLoader ldr = pairSource.open(side, entry);
    return getBytes(ldr, id.toObjectId());
}