use of org.eclipse.jgit.revwalk.RevTree in project gitblit by gitblit.
the class LuceneService method getTree.
/**
* Get the tree associated with the given commit.
*
* @param walk
* @param commit
* @return tree
* @throws IOException
*/
private RevTree getTree(final RevWalk walk, final RevCommit commit) throws IOException {
final RevTree tree = commit.getTree();
if (tree != null) {
return tree;
}
walk.parseHeaders(commit);
return commit.getTree();
}
use of org.eclipse.jgit.revwalk.RevTree in project gitblit by gitblit.
the class BranchTicketService method getAttachment.
/**
* Retrieves the specified attachment from a ticket.
*
* @param repository
* @param ticketId
* @param filename
* @return an attachment, if found, null otherwise
*/
@Override
public Attachment getAttachment(RepositoryModel repository, long ticketId, String filename) {
if (ticketId <= 0L) {
return null;
}
// deserialize the ticket model so that we have the attachment metadata
TicketModel ticket = getTicket(repository, ticketId);
Attachment attachment = ticket.getAttachment(filename);
// attachment not found
if (attachment == null) {
return null;
}
// retrieve the attachment content
Repository db = repositoryManager.getRepository(repository.name);
try {
String attachmentPath = toAttachmentPath(ticketId, attachment.name);
RevTree tree = JGitUtils.getCommit(db, BRANCH).getTree();
byte[] content = JGitUtils.getByteContent(db, tree, attachmentPath, false);
attachment.content = content;
attachment.size = content.length;
return attachment;
} finally {
db.close();
}
}
use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.
the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.
protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, ObjectId expectedId) throws Exception {
submodule = name(submodule);
ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
RevWalk rw = repo.getRevWalk();
RevCommit c = rw.parseCommit(commitId);
rw.parseBody(c.getTree());
RevTree tree = c.getTree();
RevObject actualId = repo.get(tree, submodule);
assertThat(actualId).isEqualTo(expectedId);
}
use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.
the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.
protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, TestRepository<?> subRepo, String subBranch) throws Exception {
submodule = name(submodule);
ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
ObjectId subHead = subRepo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + subBranch).getObjectId();
RevWalk rw = repo.getRevWalk();
RevCommit c = rw.parseCommit(commitId);
rw.parseBody(c.getTree());
RevTree tree = c.getTree();
RevObject actualId = repo.get(tree, submodule);
assertThat(actualId).isEqualTo(subHead);
}
use of org.eclipse.jgit.revwalk.RevTree in project gitiles by GerritCodeReview.
the class RevisionServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
GitilesAccess access = getAccess(req);
Config cfg = getAccess(req).getConfig();
try (RevWalk walk = new RevWalk(repo)) {
DateFormatter df = new DateFormatter(access, Format.DEFAULT);
List<RevObject> objects = listObjects(walk, view.getRevision());
List<Map<String, ?>> soyObjects = Lists.newArrayListWithCapacity(objects.size());
boolean hasBlob = false;
boolean hasReadme = false;
// TODO(sop): Allow caching commits by SHA-1 when no S cookie is sent.
for (RevObject obj : objects) {
try {
switch(obj.getType()) {
case OBJ_COMMIT:
soyObjects.add(ImmutableMap.of("type", Constants.TYPE_COMMIT, "data", new CommitSoyData().setLinkifier(linkifier).setRevWalk(walk).setArchiveFormat(getArchiveFormat(access)).toSoyData(req, (RevCommit) obj, COMMIT_SOY_FIELDS, df)));
break;
case OBJ_TREE:
Map<String, Object> tree = new TreeSoyData(walk.getObjectReader(), view, cfg, (RevTree) obj, req.getRequestURI()).toSoyData(obj);
soyObjects.add(ImmutableMap.of("type", Constants.TYPE_TREE, "data", tree));
hasReadme = tree.containsKey("readmeHtml");
break;
case OBJ_BLOB:
soyObjects.add(ImmutableMap.of("type", Constants.TYPE_BLOB, "data", new BlobSoyData(walk.getObjectReader(), view).toSoyData(obj)));
hasBlob = true;
break;
case OBJ_TAG:
soyObjects.add(ImmutableMap.of("type", Constants.TYPE_TAG, "data", new TagSoyData(linkifier, req).toSoyData((RevTag) obj, df)));
break;
default:
log.warn("Bad object type for {}: {}", ObjectId.toString(obj.getId()), obj.getType());
res.setStatus(SC_NOT_FOUND);
return;
}
} catch (MissingObjectException e) {
log.warn("Missing object " + ObjectId.toString(obj.getId()), e);
res.setStatus(SC_NOT_FOUND);
return;
} catch (IncorrectObjectTypeException e) {
log.warn("Incorrect object type for " + ObjectId.toString(obj.getId()), e);
res.setStatus(SC_NOT_FOUND);
return;
}
}
renderHtml(req, res, "gitiles.revisionDetail", ImmutableMap.of("title", view.getRevision().getName(), "objects", soyObjects, "hasBlob", hasBlob, "hasReadme", hasReadme));
}
}
Aggregations