Search in sources :

Example 11 with TreeWalk

use of org.eclipse.jgit.treewalk.TreeWalk in project gitiles by GerritCodeReview.

the class ReadmeHelper method scanTree.

void scanTree(RevTree tree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException {
    if (config.render) {
        try (TreeWalk tw = new TreeWalk(reader)) {
            tw.setRecursive(false);
            tw.addTree(tree);
            while (tw.next() && !isPresent()) {
                considerEntry(tw);
            }
        }
    }
}
Also used : TreeWalk(org.eclipse.jgit.treewalk.TreeWalk)

Example 12 with TreeWalk

use of org.eclipse.jgit.treewalk.TreeWalk in project gerrit by GerritCodeReview.

the class CreateProjectIT method assertEmptyCommit.

private void assertEmptyCommit(String projectName, String... refs) throws Exception {
    Project.NameKey projectKey = new Project.NameKey(projectName);
    try (Repository repo = repoManager.openRepository(projectKey);
        RevWalk rw = new RevWalk(repo);
        TreeWalk tw = new TreeWalk(rw.getObjectReader())) {
        for (String ref : refs) {
            RevCommit commit = rw.lookupCommit(repo.exactRef(ref).getObjectId());
            rw.parseBody(commit);
            tw.addTree(commit.getTree());
            assertThat(tw.next()).isFalse();
            tw.reset();
        }
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 13 with TreeWalk

use of org.eclipse.jgit.treewalk.TreeWalk in project gerrit by GerritCodeReview.

the class VersionedMetaData method getPathInfos.

public List<PathInfo> getPathInfos(boolean recursive) throws IOException {
    try (TreeWalk tw = new TreeWalk(reader)) {
        tw.addTree(revision.getTree());
        tw.setRecursive(recursive);
        List<PathInfo> paths = new ArrayList<>();
        while (tw.next()) {
            paths.add(new PathInfo(tw));
        }
        return paths;
    }
}
Also used : ArrayList(java.util.ArrayList) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk)

Example 14 with TreeWalk

use of org.eclipse.jgit.treewalk.TreeWalk in project gerrit by GerritCodeReview.

the class ListDashboards method scanDashboards.

private List<DashboardInfo> scanDashboards(Project definingProject, Repository git, RevWalk rw, Ref ref, String project, boolean setDefault) throws IOException {
    List<DashboardInfo> list = new ArrayList<>();
    try (TreeWalk tw = new TreeWalk(rw.getObjectReader())) {
        tw.addTree(rw.parseTree(ref.getObjectId()));
        tw.setRecursive(true);
        while (tw.next()) {
            if (tw.getFileMode(0) == FileMode.REGULAR_FILE) {
                try {
                    list.add(DashboardsCollection.parse(definingProject, ref.getName().substring(REFS_DASHBOARDS.length()), tw.getPathString(), new BlobBasedConfig(null, git, tw.getObjectId(0)), project, setDefault));
                } catch (ConfigInvalidException e) {
                    log.warn(String.format("Cannot parse dashboard %s:%s:%s: %s", definingProject.getName(), ref.getName(), tw.getPathString(), e.getMessage()));
                }
            }
        }
    }
    return list;
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ArrayList(java.util.ArrayList) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig) DashboardInfo(com.google.gerrit.server.project.DashboardsCollection.DashboardInfo)

Example 15 with TreeWalk

use of org.eclipse.jgit.treewalk.TreeWalk in project gitiles by GerritCodeReview.

the class ArchiveServlet method getTree.

private ObjectId getTree(GitilesView view, Repository repo, Revision rev) throws IOException {
    try (RevWalk rw = new RevWalk(repo)) {
        RevTree tree = rw.parseTree(rev.getId());
        if (Strings.isNullOrEmpty(view.getPathPart())) {
            return tree;
        }
        TreeWalk tw = TreeWalk.forPath(rw.getObjectReader(), view.getPathPart(), tree);
        if (tw == null || tw.getFileMode(0) != FileMode.TREE) {
            return ObjectId.zeroId();
        }
        return tw.getObjectId(0);
    } catch (IncorrectObjectTypeException e) {
        return ObjectId.zeroId();
    }
}
Also used : IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevTree(org.eclipse.jgit.revwalk.RevTree)

Aggregations

TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)31 RevWalk (org.eclipse.jgit.revwalk.RevWalk)19 RevCommit (org.eclipse.jgit.revwalk.RevCommit)14 ObjectId (org.eclipse.jgit.lib.ObjectId)11 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)9 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)9 ObjectReader (org.eclipse.jgit.lib.ObjectReader)6 Repository (org.eclipse.jgit.lib.Repository)6 FileMode (org.eclipse.jgit.lib.FileMode)5 RevTree (org.eclipse.jgit.revwalk.RevTree)5 PathFilter (org.eclipse.jgit.treewalk.filter.PathFilter)5 FilestoreModel (com.gitblit.models.FilestoreModel)4 PathModel (com.gitblit.models.PathModel)4 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)3 LargeObjectException (org.eclipse.jgit.errors.LargeObjectException)3 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)3 RefModel (com.gitblit.models.RefModel)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2