Search in sources :

Example 16 with ObjectLoader

use of org.eclipse.jgit.lib.ObjectLoader in project gitiles by GerritCodeReview.

the class RevisionServlet method doGetText.

@Override
protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException {
    GitilesView view = ViewFilter.getView(req);
    Repository repo = ServletUtils.getRepository(req);
    try (ObjectReader reader = repo.newObjectReader()) {
        ObjectLoader loader = reader.open(view.getRevision().getId());
        if (loader.getType() != OBJ_COMMIT) {
            res.setStatus(SC_NOT_FOUND);
        } else {
            PathServlet.setTypeHeader(res, loader.getType());
            try (Writer writer = startRenderText(req, res);
                OutputStream out = BaseEncoding.base64().encodingStream(writer)) {
                loader.copyTo(out);
            }
        }
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) OutputStream(java.io.OutputStream) ObjectReader(org.eclipse.jgit.lib.ObjectReader) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) Writer(java.io.Writer)

Aggregations

ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)11 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 ObjectId (org.eclipse.jgit.lib.ObjectId)7 ObjectReader (org.eclipse.jgit.lib.ObjectReader)6 IOException (java.io.IOException)5 LargeObjectException (org.eclipse.jgit.errors.LargeObjectException)5 FileMode (org.eclipse.jgit.lib.FileMode)5 MutableObjectId (org.eclipse.jgit.lib.MutableObjectId)3 PathFilter (org.eclipse.jgit.treewalk.filter.PathFilter)3 FilestoreModel (com.gitblit.models.FilestoreModel)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)2 Repository (org.eclipse.jgit.lib.Repository)2 RevObject (org.eclipse.jgit.revwalk.RevObject)2 RevTree (org.eclipse.jgit.revwalk.RevTree)2