From 477412d32836c6a8821f17ff0c26a3c18843d815 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 5 May 2014 10:32:38 -0400 Subject: [PATCH] Add raw links to branches --- src/main/java/com/gitblit/servlet/RawServlet.java | 15 +++++++++++++-- .../java/com/gitblit/wicket/panels/BasePanel.java | 4 ++++ .../com/gitblit/wicket/panels/BranchesPanel.html | 6 +++--- .../com/gitblit/wicket/panels/BranchesPanel.java | 5 +++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index cde7b2e1..15e036ea 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -94,7 +94,17 @@ public class RawServlet extends DaggerServlet { if (baseURL.length() > 0 && baseURL.charAt(baseURL.length() - 1) == '/') { baseURL = baseURL.substring(0, baseURL.length() - 1); } - String encodedPath = path.replace(' ', '-'); + + if (branch != null) { + char fsc = '!'; + char c = GitblitContext.getManager(IRuntimeManager.class).getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); + if (c != '/') { + fsc = c; + } + branch = branch.replace('/', fsc); + } + + String encodedPath = path == null ? "" : path.replace(' ', '-'); try { encodedPath = URLEncoder.encode(encodedPath, "UTF-8"); } catch (UnsupportedEncodingException e) { @@ -109,7 +119,8 @@ public class RawServlet extends DaggerServlet { if (fs > -1) { branch = branch.substring(0, fs); } - return branch; + char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); + return branch.replace('!', '/').replace(c, '/'); } protected String getPath(String repository, String branch, HttpServletRequest request) { diff --git a/src/main/java/com/gitblit/wicket/panels/BasePanel.java b/src/main/java/com/gitblit/wicket/panels/BasePanel.java index dda57979..e8f8f6f2 100644 --- a/src/main/java/com/gitblit/wicket/panels/BasePanel.java +++ b/src/main/java/com/gitblit/wicket/panels/BasePanel.java @@ -44,6 +44,10 @@ public abstract class BasePanel extends Panel { return GitBlitWebApp.get(); } + protected String getContextUrl() { + return getRequest().getRelativePathPrefixToContextRoot(); + } + protected TimeZone getTimeZone() { return app().settings().getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get() .getTimezone() : app().getTimezone(); diff --git a/src/main/java/com/gitblit/wicket/panels/BranchesPanel.html b/src/main/java/com/gitblit/wicket/panels/BranchesPanel.html index e95b283a..05df23ea 100644 --- a/src/main/java/com/gitblit/wicket/panels/BranchesPanel.html +++ b/src/main/java/com/gitblit/wicket/panels/BranchesPanel.html @@ -29,21 +29,21 @@ - | | | + | | | | - | | | | + | | | | | - | + | | diff --git a/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java b/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java index 6a7873ea..4bf00f8a 100644 --- a/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java @@ -40,6 +40,7 @@ import com.gitblit.Constants; import com.gitblit.models.RefModel; import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel; +import com.gitblit.servlet.RawServlet; import com.gitblit.servlet.SyndicationServlet; import com.gitblit.utils.CommitCache; import com.gitblit.utils.JGitUtils; @@ -143,6 +144,8 @@ public class BranchesPanel extends BasePanel { .newObjectParameter(model.name, entry.getName()))); fragment.add(new BookmarkablePageLink("tree", TreePage.class, WicketUtils .newObjectParameter(model.name, entry.getName()))); + String rawUrl = RawServlet.asLink(getContextUrl(), model.name, Repository.shortenRefName(entry.getName()), null); + fragment.add(new ExternalLink("raw", rawUrl)); fragment.add(new BookmarkablePageLink("metrics", MetricsPage.class, WicketUtils.newObjectParameter(model.name, entry.getName()))); fragment.add(new ExternalLink("syndication", SyndicationServlet.asLink( @@ -158,6 +161,8 @@ public class BranchesPanel extends BasePanel { .newObjectParameter(model.name, entry.getName()))); fragment.add(new BookmarkablePageLink("tree", TreePage.class, WicketUtils .newObjectParameter(model.name, entry.getName()))); + String rawUrl = RawServlet.asLink(getContextUrl(), model.name, Repository.shortenRefName(entry.getName()), null); + fragment.add(new ExternalLink("raw", rawUrl)); item.add(fragment); } WicketUtils.setAlternatingBackground(item, counter); -- 2.39.5