Search in sources :

Example 31 with MissingObjectException

use of org.eclipse.jgit.errors.MissingObjectException in project orgzly-android by orgzly.

the class GitRepo method getBooks.

public List<VersionedRook> getBooks() throws IOException {
    synchronizer.setBranchAndGetLatest();
    List<VersionedRook> result = new ArrayList<>();
    if (synchronizer.currentHead() == null) {
        return result;
    }
    TreeWalk walk = new TreeWalk(git.getRepository());
    walk.reset();
    walk.setRecursive(true);
    walk.addTree(synchronizer.currentHead().getTree());
    final IgnoreNode ignores = getIgnores();
    walk.setFilter(new TreeFilter() {

        @Override
        public boolean include(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException {
            final FileMode mode = walker.getFileMode(0);
            final String filePath = walker.getPathString();
            final boolean isDirectory = mode == FileMode.TREE;
            return !(ignores.isIgnored(filePath, isDirectory) == IgnoreNode.MatchResult.IGNORED);
        }

        @Override
        public boolean shouldBeRecursive() {
            return true;
        }

        @Override
        public TreeFilter clone() {
            return this;
        }
    });
    while (walk.next()) {
        final FileMode mode = walk.getFileMode(0);
        final boolean isDirectory = mode == FileMode.TREE;
        final String filePath = walk.getPathString();
        if (isDirectory)
            continue;
        if (BookName.isSupportedFormatFileName(filePath))
            result.add(currentVersionedRook(Uri.withAppendedPath(Uri.EMPTY, walk.getPathString())));
    }
    return result;
}
Also used : FileMode(org.eclipse.jgit.lib.FileMode) ArrayList(java.util.ArrayList) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) TreeFilter(org.eclipse.jgit.treewalk.filter.TreeFilter) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) IgnoreNode(org.eclipse.jgit.ignore.IgnoreNode)

Aggregations

MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)31 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)22 ObjectId (org.eclipse.jgit.lib.ObjectId)17 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)16 IOException (java.io.IOException)13 Repository (org.eclipse.jgit.lib.Repository)12 ArrayList (java.util.ArrayList)7 Ref (org.eclipse.jgit.lib.Ref)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)5 Map (java.util.Map)5 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Iterables (com.google.common.collect.Iterables)3 Nullable (com.google.gerrit.common.Nullable)3 Change (com.google.gerrit.entities.Change)3 PatchSet (com.google.gerrit.entities.PatchSet)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 InvalidObjectIdException (org.eclipse.jgit.errors.InvalidObjectIdException)3