Search in sources :

Example 1 with IgnoreNode

use of org.eclipse.jgit.ignore.IgnoreNode in project orgzly-android by orgzly.

the class GitRepo method getIgnores.

private IgnoreNode getIgnores() throws IOException {
    IgnoreNode ignores = new IgnoreNode();
    File ignoreFile = synchronizer.repoDirectoryFile(".orgzlyignore");
    if (ignoreFile.exists()) {
        FileInputStream in = new FileInputStream(ignoreFile);
        try {
            ignores.parse(in);
        } finally {
            in.close();
        }
    }
    return ignores;
}
Also used : File(java.io.File) FileInputStream(java.io.FileInputStream) IgnoreNode(org.eclipse.jgit.ignore.IgnoreNode)

Example 2 with IgnoreNode

use of org.eclipse.jgit.ignore.IgnoreNode 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

IgnoreNode (org.eclipse.jgit.ignore.IgnoreNode)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)1 MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)1 FileMode (org.eclipse.jgit.lib.FileMode)1 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)1 TreeFilter (org.eclipse.jgit.treewalk.filter.TreeFilter)1