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;
}
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());
}
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;
}
}
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;
}
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);
}
Aggregations