From 79cad53bba094cffa1d25581edbf4972a5158cd4 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 29 Nov 2013 11:03:01 -0500
Subject: [PATCH] Update to Moxie 0.9.1
---
src/main/java/com/gitblit/BranchGraphServlet.java | 67 +++++++++++++++++++++++++--------
1 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/src/main/java/com/gitblit/BranchGraphServlet.java b/src/main/java/com/gitblit/BranchGraphServlet.java
index 8fca455..986560c 100644
--- a/src/main/java/com/gitblit/BranchGraphServlet.java
+++ b/src/main/java/com/gitblit/BranchGraphServlet.java
@@ -32,6 +32,8 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
@@ -48,14 +50,16 @@
import org.eclipse.jgit.revplot.PlotWalk;
import org.eclipse.jgit.revwalk.RevCommit;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
/**
* Handles requests for branch graphs
- *
+ *
* @author James Moger
- *
+ *
*/
public class BranchGraphServlet extends HttpServlet {
@@ -80,7 +84,7 @@
/**
* Returns an url to this servlet for the specified parameters.
- *
+ *
* @param baseURL
* @param repository
* @param objectId
@@ -100,9 +104,10 @@
protected long getLastModified(HttpServletRequest req) {
String repository = req.getParameter("r");
String objectId = req.getParameter("h");
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
Repository r = null;
try {
- r = GitBlit.self().getRepository(repository);
+ r = repositoryManager.getRepository(repository);
if (StringUtils.isEmpty(objectId)) {
objectId = JGitUtils.getHEADRef(r);
}
@@ -126,7 +131,10 @@
String objectId = request.getParameter("h");
String length = request.getParameter("l");
- r = GitBlit.self().getRepository(repository);
+ IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
+
+ r = repositoryManager.getRepository(repository);
rw = new PlotWalk(r);
if (StringUtils.isEmpty(objectId)) {
@@ -136,27 +144,51 @@
rw.markStart(rw.lookupCommit(r.resolve(objectId)));
// default to the items-per-page setting, unless specified
- int maxCommits = GitBlit.getInteger(Keys.web.itemsPerPage, 50);
+ int maxCommits = settings.getInteger(Keys.web.itemsPerPage, 50);
+ int requestedCommits = maxCommits;
if (!StringUtils.isEmpty(length)) {
int l = Integer.parseInt(length);
if (l > 0) {
- maxCommits = l;
+ requestedCommits = l;
}
}
// fetch the requested commits plus some extra so that the last
- // commit displayed *likely* has correct lane assignments
+ // commit displayed *likely* has correct lane assignments
CommitList commitList = new CommitList();
commitList.source(rw);
- commitList.fillTo(2*maxCommits);
+ commitList.fillTo(2*Math.max(requestedCommits, maxCommits));
// determine the appropriate width for the image
- int numLanes = 0;
- int numCommits = Math.min(maxCommits, commitList.size());
- for (int i = 0; i < numCommits; i++) {
- PlotCommit<Lane> commit = commitList.get(i);
- int pos = commit.getLane().getPosition();
- numLanes = Math.max(numLanes, pos + 1);
+ int numLanes = 1;
+ int numCommits = Math.min(requestedCommits, commitList.size());
+ if (numCommits > 1) {
+ // determine graph width
+ Set<String> parents = new TreeSet<String>();
+ for (int i = 0; i < commitList.size(); i++) {
+ PlotCommit<Lane> commit = commitList.get(i);
+ boolean checkLane = false;
+
+ if (i < numCommits) {
+ // commit in visible list
+ checkLane = true;
+
+ // remember parents
+ for (RevCommit p : commit.getParents()) {
+ parents.add(p.getName());
+ }
+ } else if (parents.contains(commit.getName())) {
+ // commit outside visible list, but it is a parent of a
+ // commit in the visible list so we need to know it's lane
+ // assignment
+ checkLane = true;
+ }
+
+ if (checkLane) {
+ int pos = commit.getLane().getPosition();
+ numLanes = Math.max(numLanes, pos + 1);
+ }
+ }
}
int graphWidth = numLanes * LANE_WIDTH + RIGHT_PAD;
@@ -164,12 +196,13 @@
// create an image buffer and render the lanes
BufferedImage image = new BufferedImage(graphWidth, rowHeight*numCommits, BufferedImage.TYPE_INT_ARGB);
+
Graphics2D g = null;
try {
g = image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
LanesRenderer renderer = new LanesRenderer();
- for (int i = 0; i < numCommits; i++) {
+ for (int i = 0; i < commitList.size(); i++) {
PlotCommit<Lane> commit = commitList.get(i);
Graphics row = g.create(0, i*rowHeight, graphWidth, rowHeight);
try {
@@ -188,7 +221,7 @@
// write the image buffer to the client
response.setContentType("image/png");
- if (numCommits > 0) {
+ if (numCommits > 1) {
response.setHeader("Cache-Control", "public, max-age=60, must-revalidate");
response.setDateHeader("Last-Modified", JGitUtils.getCommitDate(commitList.get(0)).getTime());
}
--
Gitblit v1.9.1