| | |
| | | import java.util.TreeSet;
|
| | |
|
| | | import javax.imageio.ImageIO;
|
| | | import javax.inject.Inject;
|
| | | import javax.inject.Singleton;
|
| | | import javax.servlet.ServletException;
|
| | | import javax.servlet.http.HttpServlet;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
| | | 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
|
| | | * |
| | | *
|
| | | */
|
| | | @Singleton
|
| | | public class BranchGraphServlet extends HttpServlet {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
| | |
|
| | | private final Stroke[] strokeCache;
|
| | |
|
| | | public BranchGraphServlet() {
|
| | | private final IStoredSettings settings;
|
| | |
|
| | | private final IRepositoryManager repositoryManager;
|
| | |
|
| | | @Inject
|
| | | public BranchGraphServlet(
|
| | | IRuntimeManager runtimeManager,
|
| | | IRepositoryManager repositoryManager) {
|
| | |
|
| | | super();
|
| | | this.settings = runtimeManager.getSettings();
|
| | | this.repositoryManager = repositoryManager;
|
| | |
|
| | | strokeCache = new Stroke[4];
|
| | | for (int i = 1; i < strokeCache.length; i++)
|
| | |
| | |
|
| | | /**
|
| | | * Returns an url to this servlet for the specified parameters.
|
| | | * |
| | | *
|
| | | * @param baseURL
|
| | | * @param repository
|
| | | * @param objectId
|
| | |
| | | String objectId = req.getParameter("h");
|
| | | Repository r = null;
|
| | | try {
|
| | | r = GitBlit.self().getRepository(repository);
|
| | | r = repositoryManager.getRepository(repository);
|
| | | if (StringUtils.isEmpty(objectId)) {
|
| | | objectId = JGitUtils.getHEADRef(r);
|
| | | }
|
| | |
| | | String objectId = request.getParameter("h");
|
| | | String length = request.getParameter("l");
|
| | |
|
| | | r = GitBlit.self().getRepository(repository);
|
| | | r = repositoryManager.getRepository(repository);
|
| | |
|
| | | rw = new PlotWalk(r);
|
| | | if (StringUtils.isEmpty(objectId)) {
|
| | |
| | | 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);
|
| | |
| | | }
|
| | |
|
| | | // 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*Math.max(requestedCommits, maxCommits));
|
| | |
|
| | | // determine the appropriate width for the image
|
| | | int numLanes = 0;
|
| | | int numLanes = 1;
|
| | | int numCommits = Math.min(requestedCommits, commitList.size());
|
| | | 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());
|
| | | 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;
|
| | | }
|
| | | } 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);
|
| | |
|
| | | if (checkLane) {
|
| | | int pos = commit.getLane().getPosition();
|
| | | numLanes = Math.max(numLanes, pos + 1);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | |
|
| | | // 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();
|
| | |
| | |
|
| | | // 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());
|
| | | }
|