Search in sources :

Example 21 with RevTree

use of org.eclipse.jgit.revwalk.RevTree in project gitblit by gitblit.

the class BranchTicketService method readTicketsFile.

/**
	 * Reads a file from the tickets branch.
	 *
	 * @param db
	 * @param file
	 * @return the file content or null
	 */
private String readTicketsFile(Repository db, String file) {
    RevWalk rw = null;
    try {
        ObjectId treeId = db.resolve(BRANCH + "^{tree}");
        if (treeId == null) {
            return null;
        }
        rw = new RevWalk(db);
        RevTree tree = rw.lookupTree(treeId);
        if (tree != null) {
            return JGitUtils.getStringContent(db, tree, file, Constants.ENCODING);
        }
    } catch (IOException e) {
        log.error("failed to read " + file, e);
    } finally {
        if (rw != null) {
            rw.close();
        }
    }
    return null;
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTree(org.eclipse.jgit.revwalk.RevTree)

Example 22 with RevTree

use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method assertTrees.

/** Assert that the given branches have the given tree ids. */
protected void assertTrees(Project.NameKey proj, Map<Branch.NameKey, ObjectId> trees) throws Exception {
    TestRepository<?> localRepo = cloneProject(proj);
    GitUtil.fetch(localRepo, "refs/*:refs/*");
    Map<String, Ref> refs = localRepo.getRepository().getAllRefs();
    Map<Branch.NameKey, RevTree> refValues = new HashMap<>();
    for (Branch.NameKey b : trees.keySet()) {
        if (!b.getParentKey().equals(proj)) {
            continue;
        }
        Ref r = refs.get(b.get());
        assertThat(r).isNotNull();
        RevWalk rw = localRepo.getRevWalk();
        RevCommit c = rw.parseCommit(r.getObjectId());
        refValues.put(b, c.getTree());
        assertThat(trees.get(b)).isEqualTo(refValues.get(b));
    }
    assertThat(refValues.keySet()).containsAnyIn(trees.keySet());
}
Also used : Ref(org.eclipse.jgit.lib.Ref) HashMap(java.util.HashMap) Branch(com.google.gerrit.reviewdb.client.Branch) IdString(com.google.gerrit.extensions.restapi.IdString) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 23 with RevTree

use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.

the class AbstractSubmoduleSubscription method hasSubmodule.

protected boolean hasSubmodule(TestRepository<?> repo, String branch, String submodule) throws Exception {
    submodule = name(submodule);
    Ref branchTip = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch);
    if (branchTip == null) {
        return false;
    }
    ObjectId commitId = branchTip.getObjectId();
    RevWalk rw = repo.getRevWalk();
    RevCommit c = rw.parseCommit(commitId);
    rw.parseBody(c.getTree());
    RevTree tree = c.getTree();
    try {
        repo.get(tree, submodule);
        return true;
    } catch (AssertionError e) {
        return false;
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 24 with RevTree

use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.

the class ConfigChangeIT method readProjectConfig.

private Config readProjectConfig() throws Exception {
    RevWalk rw = testRepo.getRevWalk();
    RevTree tree = rw.parseTree(testRepo.getRepository().resolve("HEAD"));
    RevObject obj = rw.parseAny(testRepo.get(tree, "project.config"));
    ObjectLoader loader = rw.getObjectReader().open(obj);
    String text = new String(loader.getCachedBytes(), UTF_8);
    Config cfg = new Config();
    cfg.fromText(text);
    return cfg;
}
Also used : RevObject(org.eclipse.jgit.revwalk.RevObject) Config(org.eclipse.jgit.lib.Config) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTree(org.eclipse.jgit.revwalk.RevTree)

Example 25 with RevTree

use of org.eclipse.jgit.revwalk.RevTree in project gitiles by GerritCodeReview.

the class TimeCacheTest method taggedTreeAndBlobTime.

@Test
public void taggedTreeAndBlobTime() throws Exception {
    RevBlob blob = repo.blob("contents");
    RevTree tree = repo.tree(repo.file("foo", blob));
    repo.tick(1);
    RevTag blobTag = repo.tag("blob", blob);
    repo.tick(1);
    RevTag treeTag = repo.tag("tree", tree);
    assertThat(getTime(blobTag)).isEqualTo(start + 1);
    assertThat(getTime(treeTag)).isEqualTo(start + 2);
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) RevBlob(org.eclipse.jgit.revwalk.RevBlob) RevTree(org.eclipse.jgit.revwalk.RevTree) Test(org.junit.Test)

Aggregations

RevTree (org.eclipse.jgit.revwalk.RevTree)34 RevWalk (org.eclipse.jgit.revwalk.RevWalk)23 ObjectId (org.eclipse.jgit.lib.ObjectId)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 ObjectReader (org.eclipse.jgit.lib.ObjectReader)10 DiffEntry (org.eclipse.jgit.diff.DiffEntry)8 IOException (java.io.IOException)7 Repository (org.eclipse.jgit.lib.Repository)7 RevObject (org.eclipse.jgit.revwalk.RevObject)6 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)5 File (java.io.File)4 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)4 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)4 ArrayList (java.util.ArrayList)3 DiffFormatter (org.eclipse.jgit.diff.DiffFormatter)3 RawTextComparator (org.eclipse.jgit.diff.RawTextComparator)3 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)3 Ref (org.eclipse.jgit.lib.Ref)3 RevBlob (org.eclipse.jgit.revwalk.RevBlob)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2