]> source.dussan.org Git - gitblit.git/commitdiff
Fix width calculation in branch graph when there are 0 or 1 commits
authorJames Moger <james.moger@gitblit.com>
Fri, 27 Sep 2013 18:28:27 +0000 (14:28 -0400)
committerJames Moger <james.moger@gitblit.com>
Sat, 28 Sep 2013 01:33:34 +0000 (21:33 -0400)
Change-Id: I68ed7e4db32fa69a13979b544e80edf3212555cd

src/main/java/com/gitblit/BranchGraphServlet.java

index f46b8e6f2dde9ce1915331ffc7ffeaa806439d28..05c3c658610f1f8b9e95c36eae42c3552a72e154 100644 (file)
@@ -154,31 +154,34 @@ public class BranchGraphServlet extends HttpServlet {
                        commitList.fillTo(2*Math.max(requestedCommits, maxCommits));\r
 \r
                        // determine the appropriate width for the image\r
-                       int numLanes = 0;\r
+                       int numLanes = 1;\r
                        int numCommits = Math.min(requestedCommits, commitList.size());\r
-                       Set<String> parents = new TreeSet<String>();\r
-                       for (int i = 0; i < commitList.size(); i++) {\r
-                               PlotCommit<Lane> commit = commitList.get(i);\r
-                               boolean checkLane = false;\r
-                               \r
-                               if (i < numCommits) {\r
-                                       // commit in visible list\r
-                                       checkLane = true;\r
-                                       \r
-                                       // remember parents\r
-                                       for (RevCommit p : commit.getParents()) {\r
-                                               parents.add(p.getName());\r
+                       if (numCommits > 1) {\r
+                               // determine graph width\r
+                               Set<String> parents = new TreeSet<String>();\r
+                               for (int i = 0; i < commitList.size(); i++) {\r
+                                       PlotCommit<Lane> commit = commitList.get(i);\r
+                                       boolean checkLane = false;\r
+\r
+                                       if (i < numCommits) {\r
+                                               // commit in visible list\r
+                                               checkLane = true;\r
+\r
+                                               // remember parents\r
+                                               for (RevCommit p : commit.getParents()) {\r
+                                                       parents.add(p.getName());\r
+                                               }\r
+                                       } else if (parents.contains(commit.getName())) {\r
+                                               // commit outside visible list, but it is a parent of a\r
+                                               // commit in the visible list so we need to know it's lane\r
+                                               // assignment\r
+                                               checkLane = true;\r
+                                       }\r
+\r
+                                       if (checkLane) {\r
+                                               int pos = commit.getLane().getPosition();\r
+                                               numLanes = Math.max(numLanes, pos + 1);\r
                                        }\r
-                               } else if (parents.contains(commit.getName())) {\r
-                                       // commit outside visible list, but it is a parent of a\r
-                                       // commit in the visible list so we need to know it's lane\r
-                                       // assignment\r
-                                       checkLane = true;\r
-                               }\r
-                               \r
-                               if (checkLane) {\r
-                                       int pos = commit.getLane().getPosition();\r
-                                       numLanes = Math.max(numLanes, pos + 1);\r
                                }\r
                        }\r
 \r
@@ -187,6 +190,7 @@ public class BranchGraphServlet extends HttpServlet {
 \r
                        // create an image buffer and render the lanes\r
                        BufferedImage image = new BufferedImage(graphWidth, rowHeight*numCommits, BufferedImage.TYPE_INT_ARGB);\r
+                       \r
                        Graphics2D g = null;\r
                        try {\r
                                g = image.createGraphics();\r
@@ -211,7 +215,7 @@ public class BranchGraphServlet extends HttpServlet {
 \r
                        // write the image buffer to the client\r
                        response.setContentType("image/png");\r
-                       if (numCommits > 0) {\r
+                       if (numCommits > 1) {\r
                                response.setHeader("Cache-Control", "public, max-age=60, must-revalidate");\r
                                response.setDateHeader("Last-Modified", JGitUtils.getCommitDate(commitList.get(0)).getTime());\r
                        }\r