]> source.dussan.org Git - gitblit.git/commitdiff
Fix subdirectory links in pages servlet (issue-411)
authorJames Moger <james.moger@gitblit.com>
Wed, 23 Apr 2014 15:18:40 +0000 (11:18 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 23 Apr 2014 15:18:40 +0000 (11:18 -0400)
releases.moxie
src/main/java/com/gitblit/servlet/PagesServlet.java

index 8e183f7423f59a1ea001033093b9afe5730aac5a..53fc3ead4c2b96bf99b607d004a37bde1fe47c59 100644 (file)
@@ -9,7 +9,8 @@ r23: {
     html: ~
     text: ~
     security: ~
-    fixes: ~
+    fixes:
+    - Fix subdirectory links in pages servlet (issue-411)
     changes:
     - improve French translation (pr-176)
     - simplify current plugin release detection and ignore the currentRelease registry field 
@@ -20,6 +21,7 @@ r23: {
     - James Moger
     - Julien Kirch
     - Ralph Hoffman
+    - Olivier Rouits
 }
 
 #
index 74c1cb2d9077940abfd2868fa21a9f0d7fcf6670..5124b8caab03c4524525d0b571eeba8722cba1d3 100644 (file)
@@ -28,6 +28,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
+import org.eclipse.jgit.lib.FileMode;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 import org.eclipse.jgit.revwalk.RevTree;\r
@@ -228,11 +229,17 @@ public class PagesServlet extends DaggerServlet {
                                        response.getWriter().append("<thead><tr><th>path</th><th>mode</th><th>size</th></tr>");\r
                                        response.getWriter().append("</thead>");\r
                                        response.getWriter().append("<tbody>");\r
-                                       String pattern = "<tr><td><a href=\"{0}\">{0}</a></td><td>{1}</td><td>{2}</td></tr>";\r
+                                       String pattern = "<tr><td><a href=\"{0}\">{1}</a></td><td>{2}</td><td>{3}</td></tr>";\r
                                        final ByteFormat byteFormat = new ByteFormat();\r
                                        List<PathModel> entries = JGitUtils.getFilesInPath(r, resource, commit);\r
+                                       if (!entries.isEmpty()) {\r
+                                               if (entries.get(0).path.indexOf('/') > -1) {\r
+                                                       // we are in a subdirectory, add parent directory link\r
+                                                       entries.add(0, new PathModel("..", resource + "/..", 0, FileMode.TREE.getBits(), null, null));\r
+                                               }\r
+                                       }\r
                                        for (PathModel entry : entries) {\r
-                                               response.getWriter().append(MessageFormat.format(pattern, entry.name, JGitUtils.getPermissionsFromMode(entry.mode), byteFormat.format(entry.size)));\r
+                                               response.getWriter().append(MessageFormat.format(pattern, entry.path, entry.name, JGitUtils.getPermissionsFromMode(entry.mode), byteFormat.format(entry.size)));\r
                                        }\r
                                        response.getWriter().append("</tbody>");\r
                                        response.getWriter().append("</table>");\r