James Moger
2014-04-23 1cfce55191f8ae63b1830892fc0883506fd8507d
src/main/java/com/gitblit/servlet/PagesServlet.java
@@ -28,6 +28,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree;
@@ -109,6 +110,10 @@
      if (path.charAt(0) == '/') {
         // strip leading /
         path = path.substring(1);
      }
      if (path.charAt(path.length() - 1) == '/') {
         // strip trailing slash
         path = path.substring(0, path.length() - 1);
      }
      // determine repository and resource from url
@@ -228,11 +233,24 @@
               response.getWriter().append("<thead><tr><th>path</th><th>mode</th><th>size</th></tr>");
               response.getWriter().append("</thead>");
               response.getWriter().append("<tbody>");
               String pattern = "<tr><td><a href=\"{0}\">{0}</a></td><td>{1}</td><td>{2}</td></tr>";
               String pattern = "<tr><td><a href=\"{0}/{1}\">{1}</a></td><td>{2}</td><td>{3}</td></tr>";
               final ByteFormat byteFormat = new ByteFormat();
               List<PathModel> entries = JGitUtils.getFilesInPath(r, resource, commit);
               if (!entries.isEmpty()) {
                  if (entries.get(0).path.indexOf('/') > -1) {
                     // we are in a subdirectory, add parent directory link
                     entries.add(0, new PathModel("..", resource + "/..", 0, FileMode.TREE.getBits(), null, null));
                  }
               }
               String basePath = request.getServletPath() + request.getPathInfo();
               if (basePath.charAt(basePath.length() - 1) == '/') {
                  // strip trailing slash
                  basePath = basePath.substring(0, basePath.length() - 1);
               }
               for (PathModel entry : entries) {
                  response.getWriter().append(MessageFormat.format(pattern, entry.name, JGitUtils.getPermissionsFromMode(entry.mode), byteFormat.format(entry.size)));
                  response.getWriter().append(MessageFormat.format(pattern, basePath, entry.name,
                        JGitUtils.getPermissionsFromMode(entry.mode), byteFormat.format(entry.size)));
               }
               response.getWriter().append("</tbody>");
               response.getWriter().append("</table>");