Search in sources :

Example 1 with CorruptObjectException

use of org.eclipse.jgit.errors.CorruptObjectException in project jwt by emweb.

the class Git method treeGetObject.

public Object treeGetObject(ObjectId treeObject, int childIndex) {
    try {
        RevWalk walk = new RevWalk(repository, 0);
        RevTree tree = walk.parseTree(treeObject.id);
        TreeWalk treeWalk = new TreeWalk(repository);
        treeWalk.addTree(tree);
        treeWalk.setRecursive(false);
        for (int i = 0; i <= childIndex; ++i) if (!treeWalk.next())
            throw new RuntimeException("No object " + childIndex + " in tree " + treeObject.id.toString());
        Object object = new Object();
        object.id = new ObjectId(treeWalk.getObjectId(0));
        object.type = treeWalk.getFileMode(0) == FileMode.TREE ? ObjectType.Tree : ObjectType.Blob;
        object.name = treeWalk.getNameString();
        return object;
    } catch (MissingObjectException e) {
        throw new RuntimeException(e);
    } catch (IncorrectObjectTypeException e) {
        throw new RuntimeException(e);
    } catch (CorruptObjectException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : CorruptObjectException(org.eclipse.jgit.errors.CorruptObjectException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.DepthWalk.RevWalk) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException)

Example 2 with CorruptObjectException

use of org.eclipse.jgit.errors.CorruptObjectException in project jwt by emweb.

the class Git method treeSize.

public int treeSize(ObjectId treeId) {
    if (treeId.id == null)
        return 0;
    try {
        RevWalk walk = new RevWalk(repository, 0);
        RevTree tree = walk.parseTree(treeId.id);
        TreeWalk treeWalk = new TreeWalk(repository);
        treeWalk.addTree(tree);
        treeWalk.setRecursive(false);
        int count = 0;
        while (treeWalk.next()) ++count;
        return count;
    } catch (MissingObjectException e) {
        throw new RuntimeException(e);
    } catch (IncorrectObjectTypeException e) {
        throw new RuntimeException(e);
    } catch (CorruptObjectException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : CorruptObjectException(org.eclipse.jgit.errors.CorruptObjectException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.DepthWalk.RevWalk) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException)

Aggregations

IOException (java.io.IOException)2 CorruptObjectException (org.eclipse.jgit.errors.CorruptObjectException)2 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)2 MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)2 RevWalk (org.eclipse.jgit.revwalk.DepthWalk.RevWalk)2 RevTree (org.eclipse.jgit.revwalk.RevTree)2 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)2