summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/servlet
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-04-23 16:09:03 -0400
committerJames Moger <james.moger@gitblit.com>2014-05-04 10:43:35 -0400
commit553e0f79c99e3c3b6e7fb5364c10cfc1bd3b9c80 (patch)
tree0eb1ee549a59e58e8560b2f0f13a9ce0ac7bceb3 /src/main/java/com/gitblit/servlet
parentca31f51855b39a179bdad9bb912da6aeadad866d (diff)
downloadgitblit-553e0f79c99e3c3b6e7fb5364c10cfc1bd3b9c80.tar.gz
gitblit-553e0f79c99e3c3b6e7fb5364c10cfc1bd3b9c80.zip
Stream directly from repo instead of loading into ram and streaming
Diffstat (limited to 'src/main/java/com/gitblit/servlet')
-rw-r--r--src/main/java/com/gitblit/servlet/BranchServlet.java47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/main/java/com/gitblit/servlet/BranchServlet.java b/src/main/java/com/gitblit/servlet/BranchServlet.java
index d6fbfe5b..7d0a5c12 100644
--- a/src/main/java/com/gitblit/servlet/BranchServlet.java
+++ b/src/main/java/com/gitblit/servlet/BranchServlet.java
@@ -35,8 +35,14 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.tika.Tika;
import org.eclipse.jgit.lib.FileMode;
+import org.eclipse.jgit.lib.MutableObjectId;
+import org.eclipse.jgit.lib.ObjectLoader;
+import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -252,10 +258,7 @@ public class BranchServlet extends DaggerServlet {
}
// send content
- byte [] content = JGitUtils.getByteContent(r, commit.getTree(), requestedPath, false);
- InputStream is = new ByteArrayInputStream(content);
- sendContent(response, JGitUtils.getCommitDate(commit), is);
-
+ streamFromRepo(response, r, commit, requestedPath);
return;
} catch (Exception e) {
logger.error(null, e);
@@ -368,6 +371,42 @@ public class BranchServlet extends DaggerServlet {
}
}
+ private void streamFromRepo(HttpServletResponse response, Repository repository,
+ RevCommit commit, String requestedPath) throws IOException {
+
+ response.setDateHeader("Last-Modified", JGitUtils.getCommitDate(commit).getTime());
+ response.setHeader("Cache-Control", "public, max-age=3600, must-revalidate");
+
+ RevWalk rw = new RevWalk(repository);
+ TreeWalk tw = new TreeWalk(repository);
+ try {
+ tw.reset();
+ tw.addTree(commit.getTree());
+ PathFilter f = PathFilter.create(requestedPath);
+ tw.setFilter(f);
+ tw.setRecursive(true);
+ MutableObjectId id = new MutableObjectId();
+ ObjectReader reader = tw.getObjectReader();
+ while (tw.next()) {
+ FileMode mode = tw.getFileMode(0);
+ if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
+ continue;
+ }
+ tw.getObjectId(id, 0);
+
+ long len = reader.getObjectSize(id, org.eclipse.jgit.lib.Constants.OBJ_BLOB);
+ response.setIntHeader("Content-Length", (int) len);
+ ObjectLoader ldr = repository.open(id);
+ ldr.copyTo(response.getOutputStream());
+ }
+ } finally {
+ tw.release();
+ rw.dispose();
+ }
+
+ response.flushBuffer();
+ }
+
private void sendContent(HttpServletResponse response, Date date, InputStream is) throws ServletException, IOException {
response.setDateHeader("Last-Modified", date.getTime());
response.setHeader("Cache-Control", "public, max-age=3600, must-revalidate");