From 5d5e557f029aa9efe8e81cbc43e9e969fa750b80 Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 17 Sep 2014 12:20:22 -0400 Subject: [PATCH] Explicitly declare RepositoryPage subclasses that reference commits --- .../com/gitblit/wicket/GitBlitWebApp.java | 4 +-- .../com/gitblit/wicket/pages/BlamePage.java | 5 ++++ .../gitblit/wicket/pages/BlobDiffPage.java | 5 ++++ .../com/gitblit/wicket/pages/BlobPage.java | 5 ++++ .../gitblit/wicket/pages/CommitDiffPage.java | 5 ++++ .../com/gitblit/wicket/pages/CommitPage.java | 5 ++++ .../com/gitblit/wicket/pages/DocPage.java | 5 ++++ .../com/gitblit/wicket/pages/DocsPage.java | 6 +++++ .../com/gitblit/wicket/pages/HistoryPage.java | 5 ++++ .../com/gitblit/wicket/pages/LogPage.java | 6 +++++ .../com/gitblit/wicket/pages/MetricsPage.java | 27 +++++++++++-------- .../com/gitblit/wicket/pages/NoDocsPage.java | 5 ++++ .../gitblit/wicket/pages/RepositoryPage.java | 14 +++++++--- .../com/gitblit/wicket/pages/TagPage.java | 5 ++++ .../com/gitblit/wicket/pages/TreePage.java | 6 +++++ 15 files changed, 91 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java index 0c978618..d19630c2 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java @@ -175,9 +175,9 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp { // setup the standard gitweb-ish urls mount("/repositories", RepositoriesPage.class); - mount("/overview", OverviewPage.class, "r", "h"); + mount("/overview", OverviewPage.class, "r"); mount("/summary", SummaryPage.class, "r"); - mount("/reflog", ReflogPage.class, "r", "h"); + mount("/reflog", ReflogPage.class, "r"); mount("/commits", LogPage.class, "r", "h"); mount("/log", LogPage.class, "r", "h"); mount("/tags", TagsPage.class, "r"); diff --git a/src/main/java/com/gitblit/wicket/pages/BlamePage.java b/src/main/java/com/gitblit/wicket/pages/BlamePage.java index c2280a2e..3c850f29 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlamePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlamePage.java @@ -234,6 +234,11 @@ public class BlamePage extends RepositoryPage { return getString("gb.blame"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return TreePage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java index 27678ecd..9cc3eae1 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java @@ -81,6 +81,11 @@ public class BlobDiffPage extends RepositoryPage { return getString("gb.diff"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return TreePage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/BlobPage.java b/src/main/java/com/gitblit/wicket/pages/BlobPage.java index e84056b3..3c244f9a 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlobPage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlobPage.java @@ -223,6 +223,11 @@ public class BlobPage extends RepositoryPage { return getString("gb.view"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return TreePage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java index 71a5ea67..d827c449 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java +++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java @@ -196,6 +196,11 @@ public class CommitDiffPage extends RepositoryPage { return getString("gb.commitdiff"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return LogPage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/CommitPage.java b/src/main/java/com/gitblit/wicket/pages/CommitPage.java index 6fadec5b..072bb200 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitPage.java +++ b/src/main/java/com/gitblit/wicket/pages/CommitPage.java @@ -247,6 +247,11 @@ public class CommitPage extends RepositoryPage { return getString("gb.commit"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return LogPage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/DocPage.java b/src/main/java/com/gitblit/wicket/pages/DocPage.java index 567c6fbd..5ed9c400 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocPage.java @@ -101,6 +101,11 @@ public class DocPage extends RepositoryPage { return getString("gb.docs"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return DocsPage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/DocsPage.java b/src/main/java/com/gitblit/wicket/pages/DocsPage.java index 97b16049..8be9a573 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocsPage.java @@ -167,4 +167,10 @@ public class DocsPage extends RepositoryPage { protected String getPageName() { return getString("gb.docs"); } + + @Override + protected boolean isCommitPage() { + return true; + } + } diff --git a/src/main/java/com/gitblit/wicket/pages/HistoryPage.java b/src/main/java/com/gitblit/wicket/pages/HistoryPage.java index f7f188df..3021cb3c 100644 --- a/src/main/java/com/gitblit/wicket/pages/HistoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/HistoryPage.java @@ -66,6 +66,11 @@ public class HistoryPage extends RepositoryPage { return getString("gb.history"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return TreePage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/LogPage.java b/src/main/java/com/gitblit/wicket/pages/LogPage.java index 092f719a..411d7edd 100644 --- a/src/main/java/com/gitblit/wicket/pages/LogPage.java +++ b/src/main/java/com/gitblit/wicket/pages/LogPage.java @@ -69,4 +69,10 @@ public class LogPage extends RepositoryPage { protected String getPageName() { return getString("gb.log"); } + + @Override + protected boolean isCommitPage() { + return true; + } + } diff --git a/src/main/java/com/gitblit/wicket/pages/MetricsPage.java b/src/main/java/com/gitblit/wicket/pages/MetricsPage.java index 7ae4e4ed..96113b0f 100644 --- a/src/main/java/com/gitblit/wicket/pages/MetricsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/MetricsPage.java @@ -61,24 +61,24 @@ public class MetricsPage extends RepositoryPage { MessageFormat.format(getString("gb.branchStats"), metricsTotal.count, metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration)))); } - + Charts charts = new Flotr2Charts(); - + add(WicketUtils.newBlankImage("commitsChart")); add(WicketUtils.newBlankImage("dayOfWeekChart")); add(WicketUtils.newBlankImage("authorsChart")); - + createLineChart(charts, "commitsChart", metrics); createBarChart(charts, "dayOfWeekChart", getDayOfWeekMetrics(r, objectId)); createPieChart(charts, "authorsChart", getAuthorMetrics(r, objectId)); - + add(new HeaderContributor(charts)); } private void createLineChart(Charts charts, String id, List metrics) { if ((metrics != null) && (metrics.size() > 0)) { - + Chart chart = charts.createLineChart(id, "", "day", getString("gb.commits")); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); @@ -102,22 +102,22 @@ public class MetricsPage extends RepositoryPage { chart.addHighlight(date, (int)metric.count); } } - charts.addChart(chart); + charts.addChart(chart); } } - + private void createPieChart(Charts charts, String id, List metrics) { if ((metrics != null) && (metrics.size() > 0)) { - + Chart chart = charts.createPieChart(id, "", "day", getString("gb.commits")); for (Metric metric : metrics) { chart.addValue(metric.name, (int)metric.count); } - charts.addChart(chart); + charts.addChart(chart); } } - + private void createBarChart(Charts charts, String id, List metrics) { if ((metrics != null) && (metrics.size() > 0)) { Chart chart = charts.createBarChart(id, "", "day", @@ -125,7 +125,7 @@ public class MetricsPage extends RepositoryPage { for (Metric metric : metrics) { chart.addValue(metric.name, (int)metric.count); } - charts.addChart(chart); + charts.addChart(chart); } } @@ -178,6 +178,11 @@ public class MetricsPage extends RepositoryPage { return getString("gb.metrics"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return SummaryPage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/NoDocsPage.java b/src/main/java/com/gitblit/wicket/pages/NoDocsPage.java index 868e5d02..7dcc0227 100644 --- a/src/main/java/com/gitblit/wicket/pages/NoDocsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/NoDocsPage.java @@ -32,6 +32,11 @@ public class NoDocsPage extends RepositoryPage { return getString("gb.docs"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return DocsPage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java index b3250a6b..134ee044 100644 --- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java @@ -201,11 +201,13 @@ public abstract class RepositoryPage extends RootPage { objectParams = params; // preserve the objectid iff the objectid directly (or indirectly) refers to a ref - if (!StringUtils.isEmpty(objectId)) { + if (isCommitPage() && !StringUtils.isEmpty(objectId)) { RevCommit commit = JGitUtils.getCommit(r, objectId); - String bestId = getBestCommitId(commit); - if (!commit.getName().equals(bestId)) { - objectParams = WicketUtils.newObjectParameter(getRepositoryName(), bestId); + if (commit != null) { + String bestId = getBestCommitId(commit); + if (!commit.getName().equals(bestId)) { + objectParams = WicketUtils.newObjectParameter(getRepositoryName(), bestId); + } } } } @@ -574,6 +576,10 @@ public abstract class RepositoryPage extends RootPage { protected abstract String getPageName(); + protected boolean isCommitPage() { + return false; + } + protected Component createPersonPanel(String wicketId, PersonIdent identity, Constants.SearchType searchType) { String name = identity == null ? "" : identity.getName(); diff --git a/src/main/java/com/gitblit/wicket/pages/TagPage.java b/src/main/java/com/gitblit/wicket/pages/TagPage.java index afade81c..9eed2797 100644 --- a/src/main/java/com/gitblit/wicket/pages/TagPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TagPage.java @@ -100,6 +100,11 @@ public class TagPage extends RepositoryPage { return getString("gb.tag"); } + @Override + protected boolean isCommitPage() { + return true; + } + @Override protected Class getRepoNavPageClass() { return LogPage.class; diff --git a/src/main/java/com/gitblit/wicket/pages/TreePage.java b/src/main/java/com/gitblit/wicket/pages/TreePage.java index 722b824f..9ddbecf6 100644 --- a/src/main/java/com/gitblit/wicket/pages/TreePage.java +++ b/src/main/java/com/gitblit/wicket/pages/TreePage.java @@ -186,4 +186,10 @@ public class TreePage extends RepositoryPage { protected String getPageName() { return getString("gb.tree"); } + + @Override + protected boolean isCommitPage() { + return true; + } + } -- 2.39.5