]> source.dussan.org Git - gitblit.git/commitdiff
Preserve refs in commits, tree, & docs navbar links 76/176/1
authorJames Moger <james.moger@gitblit.com>
Thu, 11 Sep 2014 14:48:03 +0000 (10:48 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 11 Sep 2014 14:48:03 +0000 (10:48 -0400)
src/main/java/com/gitblit/wicket/GitBlitWebApp.java
src/main/java/com/gitblit/wicket/pages/DocsPage.java
src/main/java/com/gitblit/wicket/pages/RepositoryPage.java

index 38dbf57d73870eb62dcfaed81e2ba5cd66f22f6a..0c978618e54884d7994d9f6ba553dac8830cd04e 100644 (file)
@@ -208,7 +208,7 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp {
                mount("/mytickets", MyTicketsPage.class, "r", "h");
 
                // setup the markup document urls
-               mount("/docs", DocsPage.class, "r");
+               mount("/docs", DocsPage.class, "r", "h");
                mount("/doc", DocPage.class, "r", "h", "f");
 
                // federation urls
index a3d0f214e843480cb56b04cfd93394010c2882d9..97b160499ee7d9e3e57972f0df3dba6664618165 100644 (file)
@@ -49,11 +49,14 @@ public class DocsPage extends RepositoryPage {
        public DocsPage(PageParameters params) {\r
                super(params);\r
 \r
+               String objectId = WicketUtils.getObject(params);\r
+\r
                MarkupProcessor processor = new MarkupProcessor(app().settings(), app().xssFilter());\r
 \r
                Repository r = getRepository();\r
-               RevCommit head = JGitUtils.getCommit(r, null);\r
+               RevCommit head = JGitUtils.getCommit(r, objectId);\r
                final String commitId = getBestCommitId(head);\r
+\r
                List<String> extensions = processor.getAllExtensions();\r
                List<PathModel> paths = JGitUtils.getDocuments(r, extensions);\r
 \r
@@ -127,7 +130,6 @@ public class DocsPage extends RepositoryPage {
                }\r
 \r
                // document list\r
-               final String id = getBestCommitId(head);\r
                final ByteFormat byteFormat = new ByteFormat();\r
                Fragment docs = new Fragment("documents", "documentsFragment", this);\r
                ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);\r
@@ -141,17 +143,17 @@ public class DocsPage extends RepositoryPage {
                                item.add(WicketUtils.newImage("docIcon", "file_world_16x16.png"));\r
                                item.add(new Label("docSize", byteFormat.format(entry.size)));\r
                                item.add(new LinkPanel("docName", "list", StringUtils.stripFileExtension(entry.name),\r
-                                               DocPage.class, WicketUtils.newPathParameter(repositoryName, id, entry.path)));\r
+                                               DocPage.class, WicketUtils.newPathParameter(repositoryName, commitId, entry.path)));\r
 \r
                                // links\r
                                item.add(new BookmarkablePageLink<Void>("view", DocPage.class, WicketUtils\r
-                                               .newPathParameter(repositoryName, id, entry.path)));\r
-                               String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, id, entry.path);\r
+                                               .newPathParameter(repositoryName, commitId, entry.path)));\r
+                               String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, commitId, entry.path);\r
                                item.add(new ExternalLink("raw", rawUrl));\r
                                item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils\r
-                                               .newPathParameter(repositoryName, id, entry.path)));\r
+                                               .newPathParameter(repositoryName, commitId, entry.path)));\r
                                item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils\r
-                                               .newPathParameter(repositoryName, id, entry.path)));\r
+                                               .newPathParameter(repositoryName, commitId, entry.path)));\r
                                WicketUtils.setAlternatingBackground(item, counter);\r
                                counter++;\r
                        }\r
index 2bd9dc6c946071b256eb5e43cada69de0e715731..b3250a6b5a0f53f4f7d9a15682a543c858e990a4 100644 (file)
@@ -191,14 +191,26 @@ public abstract class RepositoryPage extends RootPage {
        }\r
 \r
        private List<NavLink> registerNavLinks() {\r
+               Repository r = getRepository();\r
+               RepositoryModel model = getRepositoryModel();\r
+\r
                PageParameters params = null;\r
+               PageParameters objectParams = null;\r
                if (!StringUtils.isEmpty(repositoryName)) {\r
                        params = WicketUtils.newRepositoryParameter(getRepositoryName());\r
+                       objectParams = params;\r
+\r
+                       // preserve the objectid iff the objectid directly (or indirectly) refers to a ref\r
+                       if (!StringUtils.isEmpty(objectId)) {\r
+                               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+                               String bestId = getBestCommitId(commit);\r
+                               if (!commit.getName().equals(bestId)) {\r
+                                       objectParams = WicketUtils.newObjectParameter(getRepositoryName(), bestId);\r
+                               }\r
+                       }\r
                }\r
                List<NavLink> navLinks = new ArrayList<NavLink>();\r
 \r
-               Repository r = getRepository();\r
-               RepositoryModel model = getRepositoryModel();\r
 \r
                // standard links\r
                if (RefLogUtils.getRefLogBranch(r) == null) {\r
@@ -213,13 +225,13 @@ public abstract class RepositoryPage extends RootPage {
                        return navLinks;\r
                }\r
 \r
-               navLinks.add(new PageNavLink("gb.commits", LogPage.class, params));\r
-               navLinks.add(new PageNavLink("gb.tree", TreePage.class, params));\r
+               navLinks.add(new PageNavLink("gb.commits", LogPage.class, objectParams));\r
+               navLinks.add(new PageNavLink("gb.tree", TreePage.class, objectParams));\r
                if (app().tickets().isReady() && (app().tickets().isAcceptingNewTickets(model) || app().tickets().hasTickets(model))) {\r
                        PageParameters tParams = WicketUtils.newOpenTicketsParameter(getRepositoryName());\r
                        navLinks.add(new PageNavLink("gb.tickets", TicketsPage.class, tParams));
                }
-               navLinks.add(new PageNavLink("gb.docs", DocsPage.class, params, true));\r
+               navLinks.add(new PageNavLink("gb.docs", DocsPage.class, objectParams, true));\r
                if (app().settings().getBoolean(Keys.web.allowForking, true)) {\r
                        navLinks.add(new PageNavLink("gb.forks", ForksPage.class, params, true));\r
                }\r
@@ -453,7 +465,7 @@ public abstract class RepositoryPage extends RootPage {
                // find first branch match\r
                for (RefModel ref : JGitUtils.getLocalBranches(r, false, -1)) {\r
                        if (ref.getObjectId().getName().equals(id)) {\r
-                               return ref.getName();\r
+                               return Repository.shortenRefName(ref.getName());\r
                        }\r
                }\r
 \r