summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/wicket
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-09-27 20:25:06 -0400
committerJames Moger <james.moger@gitblit.com>2013-09-27 21:33:34 -0400
commit319342c09152c61af13930e79777e1396f9c397f (patch)
tree5918ec46da2814872c05d8b665ad6538af600caf /src/main/java/com/gitblit/wicket
parentb384a9923314ef0ab7ec0e9f506c8d52cc31f5fc (diff)
downloadgitblit-319342c09152c61af13930e79777e1396f9c397f.tar.gz
gitblit-319342c09152c61af13930e79777e1396f9c397f.zip
Add normalized diffstats to the commit, commitdiff, and compare pages
Change-Id: I8f26746a611e9ab955efe8b2597cc81db48fb085
Diffstat (limited to 'src/main/java/com/gitblit/wicket')
-rw-r--r--src/main/java/com/gitblit/wicket/GitBlitWebApp.properties3
-rw-r--r--src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html3
-rw-r--r--src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java24
-rw-r--r--src/main/java/com/gitblit/wicket/pages/CommitPage.html3
-rw-r--r--src/main/java/com/gitblit/wicket/pages/CommitPage.java14
-rw-r--r--src/main/java/com/gitblit/wicket/pages/ComparePage.html3
-rw-r--r--src/main/java/com/gitblit/wicket/pages/ComparePage.java22
-rw-r--r--src/main/java/com/gitblit/wicket/panels/DiffStatPanel.html12
-rw-r--r--src/main/java/com/gitblit/wicket/panels/DiffStatPanel.java88
10 files changed, 156 insertions, 20 deletions
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
index 1f1a5840..4b19f9b2 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
@@ -502,4 +502,5 @@ gb.todaysActivityStats = today / {1} commits by {2} authors
gb.todaysActivityNone = today / none
gb.noActivityToday = there has been no activity today
gb.anonymousUser= anonymous
-gb.commitMessageRenderer = commit message renderer \ No newline at end of file
+gb.commitMessageRenderer = commit message renderer
+gb.diffStat = {0} insertions & {1} deletions \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java
index 8dc9d840..f8f88188 100644
--- a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java
@@ -46,13 +46,13 @@ public class BlobDiffPage extends RepositoryPage {
String diff;
if (StringUtils.isEmpty(baseObjectId)) {
// use first parent
- diff = DiffUtils.getDiff(r, commit, blobPath, DiffOutputType.HTML);
+ diff = DiffUtils.getDiff(r, commit, blobPath, DiffOutputType.HTML).content;
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
} else {
// base commit specified
RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
- diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, DiffOutputType.HTML);
+ diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, DiffOutputType.HTML).content;
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId,
blobPath)));
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html
index 7fd3857f..71d7f64d 100644
--- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html
+++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html
@@ -38,13 +38,14 @@
<div class="hidden-phone" style="text-align:right;" wicket:id="commitLegend"></div>
<!-- changed paths -->
- <div class="header"><i class="icon-file"></i> <wicket:message key="gb.changedFiles">[changed files]</wicket:message></div>
+ <div class="header"><span wicket:id="diffStat"></span><span style="padding-left:5px;"><wicket:message key="gb.changedFiles">[changed files]</wicket:message></span></div>
<table class="pretty">
<tr wicket:id="changedPath">
<td class="changeType"><span wicket:id="changeType">[change type]</span></td>
<td class="path"><span wicket:id="pathName">[commit path]</span></td>
<td class="hidden-phone rightAlign">
+ <span class="hidden-tablet" style="padding-right:20px;" wicket:id="diffStat"></span>
<span class="link">
<a wicket:id="patch"><wicket:message key="gb.patch"></wicket:message></a> | <a wicket:id="view"><wicket:message key="gb.view"></wicket:message></a> | <a wicket:id="blame"><wicket:message key="gb.blame"></wicket:message></a> | <a wicket:id="history"><wicket:message key="gb.history"></wicket:message></a>
</span>
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
index eb672164..3bd759dc 100644
--- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
@@ -32,10 +32,11 @@ import org.eclipse.jgit.revwalk.RevCommit;
import com.gitblit.Constants;
import com.gitblit.GitBlit;
-import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.GitNote;
+import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.SubmoduleModel;
import com.gitblit.utils.DiffUtils;
+import com.gitblit.utils.DiffUtils.DiffOutput;
import com.gitblit.utils.DiffUtils.DiffOutputType;
import com.gitblit.utils.JGitUtils;
import com.gitblit.wicket.CacheControl;
@@ -43,6 +44,7 @@ import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.CommitLegendPanel;
+import com.gitblit.wicket.panels.DiffStatPanel;
import com.gitblit.wicket.panels.GravatarImage;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.RefsPanel;
@@ -57,7 +59,7 @@ public class CommitDiffPage extends RepositoryPage {
RevCommit commit = getCommit();
- String diff = DiffUtils.getCommitDiff(r, commit, DiffOutputType.HTML);
+ final DiffOutput diff = DiffUtils.getCommitDiff(r, commit, DiffOutputType.HTML);
List<String> parents = new ArrayList<String>();
if (commit.getParentCount() > 0) {
@@ -80,6 +82,15 @@ public class CommitDiffPage extends RepositoryPage {
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
+ // add commit diffstat
+ int insertions = 0;
+ int deletions = 0;
+ for (PathChangeModel pcm : diff.stat.paths) {
+ insertions += pcm.insertions;
+ deletions += pcm.deletions;
+ }
+ add(new DiffStatPanel("diffStat", insertions, deletions));
+
addFullText("fullMessage", commit.getFullMessage());
// git notes
@@ -103,10 +114,8 @@ public class CommitDiffPage extends RepositoryPage {
add(notesView.setVisible(notes.size() > 0));
// changed paths list
- List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, commit);
-
- add(new CommitLegendPanel("commitLegend", paths));
- ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
+ add(new CommitLegendPanel("commitLegend", diff.stat.paths));
+ ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(diff.stat.paths);
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
private static final long serialVersionUID = 1L;
int counter;
@@ -117,6 +126,7 @@ public class CommitDiffPage extends RepositoryPage {
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
setChangeTypeTooltip(changeType, entry.changeType);
item.add(changeType);
+ item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
boolean hasSubmodule = false;
String submodulePath = null;
@@ -172,7 +182,7 @@ public class CommitDiffPage extends RepositoryPage {
}
};
add(pathsView);
- add(new Label("diffText", diff).setEscapeModelStrings(false));
+ add(new Label("diffText", diff.content).setEscapeModelStrings(false));
}
@Override
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitPage.html b/src/main/java/com/gitblit/wicket/pages/CommitPage.html
index 1ec541c6..8d169255 100644
--- a/src/main/java/com/gitblit/wicket/pages/CommitPage.html
+++ b/src/main/java/com/gitblit/wicket/pages/CommitPage.html
@@ -71,7 +71,7 @@
<div class="hidden-phone" style="text-align:right;" wicket:id="commitLegend"></div>
<!-- header -->
- <div class="header"><i class="icon-file"></i> <wicket:message key="gb.changedFiles">[changed files]</wicket:message></div>
+ <div class="header"><span wicket:id="diffStat"></span><span style="padding-left:5px;"><wicket:message key="gb.changedFiles">[changed files]</wicket:message></span></div>
<!-- changed paths -->
<table class="pretty">
@@ -79,6 +79,7 @@
<td class="changeType"><span wicket:id="changeType">[change type]</span></td>
<td class="path"><span wicket:id="pathName">[commit path]</span></td>
<td class="hidden-phone rightAlign">
+ <span class="hidden-tablet" style="padding-right:20px;" wicket:id="diffStat"></span>
<span class="link">
<a wicket:id="diff"><wicket:message key="gb.diff"></wicket:message></a> | <a wicket:id="view"><wicket:message key="gb.view"></wicket:message></a> | <a wicket:id="blame"><wicket:message key="gb.blame"></wicket:message></a> | <a wicket:id="history"><wicket:message key="gb.history"></wicket:message></a>
</span>
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitPage.java b/src/main/java/com/gitblit/wicket/pages/CommitPage.java
index 1a1d5987..8e001bc2 100644
--- a/src/main/java/com/gitblit/wicket/pages/CommitPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/CommitPage.java
@@ -43,6 +43,7 @@ import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.CommitLegendPanel;
import com.gitblit.wicket.panels.CompressedDownloadsPanel;
+import com.gitblit.wicket.panels.DiffStatPanel;
import com.gitblit.wicket.panels.GravatarImage;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.RefsPanel;
@@ -141,6 +142,16 @@ public class CommitPage extends RepositoryPage {
// changed paths list
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, c);
+
+ // add commit diffstat
+ int insertions = 0;
+ int deletions = 0;
+ for (PathChangeModel pcm : paths) {
+ insertions += pcm.insertions;
+ deletions += pcm.deletions;
+ }
+ add(new DiffStatPanel("diffStat", insertions, deletions));
+
add(new CommitLegendPanel("commitLegend", paths));
ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
@@ -153,7 +164,8 @@ public class CommitPage extends RepositoryPage {
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
setChangeTypeTooltip(changeType, entry.changeType);
item.add(changeType);
-
+ item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
+
boolean hasSubmodule = false;
String submodulePath = null;
if (entry.isTree()) {
diff --git a/src/main/java/com/gitblit/wicket/pages/ComparePage.html b/src/main/java/com/gitblit/wicket/pages/ComparePage.html
index 5716c5d4..494d0b5b 100644
--- a/src/main/java/com/gitblit/wicket/pages/ComparePage.html
+++ b/src/main/java/com/gitblit/wicket/pages/ComparePage.html
@@ -55,13 +55,14 @@
<div>
<!-- commit legend -->
<div class="hidden-phone" style="text-align:right;" wicket:id="commitLegend"></div>
- <div class="header"><i class="icon-file"></i> <wicket:message key="gb.changedFiles">[changed files]</wicket:message></div>
+ <div class="header"><span wicket:id="diffStat"></span><span style="padding-left:5px;"><wicket:message key="gb.changedFiles">[changed files]</wicket:message></span></div>
</div>
<table class="pretty">
<tr wicket:id="changedPath">
<td class="changeType"><span wicket:id="changeType">[change type]</span></td>
<td class="path"><span wicket:id="pathName">[commit path]</span></td>
<td class="hidden-phone rightAlign">
+ <span class="hidden-tablet" style="padding-right:20px;" wicket:id="diffStat"></span>
<span class="link">
<a wicket:id="patch"><wicket:message key="gb.patch"></wicket:message></a> | <a wicket:id="view"><wicket:message key="gb.view"></wicket:message></a> | <a wicket:id="blame"><wicket:message key="gb.blame"></wicket:message></a> | <a wicket:id="history"><wicket:message key="gb.history"></wicket:message></a>
</span>
diff --git a/src/main/java/com/gitblit/wicket/pages/ComparePage.java b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
index a513f00e..1efb9b6b 100644
--- a/src/main/java/com/gitblit/wicket/pages/ComparePage.java
+++ b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
@@ -42,12 +42,14 @@ import com.gitblit.models.RefModel;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.SubmoduleModel;
import com.gitblit.utils.DiffUtils;
+import com.gitblit.utils.DiffUtils.DiffOutput;
import com.gitblit.utils.DiffUtils.DiffOutputType;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.SessionlessForm;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitLegendPanel;
+import com.gitblit.wicket.panels.DiffStatPanel;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.LogPanel;
@@ -108,7 +110,16 @@ public class ComparePage extends RepositoryPage {
fromCommitId.setObject(startId);
toCommitId.setObject(endId);
- String diff = DiffUtils.getDiff(r, fromCommit, toCommit, DiffOutputType.HTML);
+ final DiffOutput diff = DiffUtils.getDiff(r, fromCommit, toCommit, DiffOutputType.HTML);
+
+ // add compare diffstat
+ int insertions = 0;
+ int deletions = 0;
+ for (PathChangeModel pcm : diff.stat.paths) {
+ insertions += pcm.insertions;
+ deletions += pcm.deletions;
+ }
+ comparison.add(new DiffStatPanel("diffStat", insertions, deletions));
// compare page links
// comparison.add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
@@ -118,10 +129,8 @@ public class ComparePage extends RepositoryPage {
comparison.add(new LogPanel("commitList", repositoryName, objectId, r, 0, 0, repository.showRemoteBranches));
// changed paths list
- List<PathChangeModel> paths = JGitUtils.getFilesInRange(r, fromCommit, toCommit);
-
- comparison.add(new CommitLegendPanel("commitLegend", paths));
- ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
+ comparison.add(new CommitLegendPanel("commitLegend", diff.stat.paths));
+ ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(diff.stat.paths);
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
private static final long serialVersionUID = 1L;
int counter;
@@ -132,6 +141,7 @@ public class ComparePage extends RepositoryPage {
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
setChangeTypeTooltip(changeType, entry.changeType);
item.add(changeType);
+ item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
boolean hasSubmodule = false;
String submodulePath = null;
@@ -185,7 +195,7 @@ public class ComparePage extends RepositoryPage {
}
};
comparison.add(pathsView);
- comparison.add(new Label("diffText", diff).setEscapeModelStrings(false));
+ comparison.add(new Label("diffText", diff.content).setEscapeModelStrings(false));
}
//
diff --git a/src/main/java/com/gitblit/wicket/panels/DiffStatPanel.html b/src/main/java/com/gitblit/wicket/panels/DiffStatPanel.html
new file mode 100644
index 00000000..032cc361
--- /dev/null
+++ b/src/main/java/com/gitblit/wicket/panels/DiffStatPanel.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
+ xml:lang="en"
+ lang="en">
+<wicket:panel>
+<span class="hidden-phone hidden-tablet diffstat-total" wicket:id="total">[total]</span>
+<span class="diffstat-segments">
+ <i class="diffstat-add" wicket:id="insertions"></i><i class="diffstat-delete" wicket:id="deletions"></i><i wicket:id="blank"></i>
+</span>
+</wicket:panel>
+</html> \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/DiffStatPanel.java b/src/main/java/com/gitblit/wicket/panels/DiffStatPanel.java
new file mode 100644
index 00000000..e1f0af92
--- /dev/null
+++ b/src/main/java/com/gitblit/wicket/panels/DiffStatPanel.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2013 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import java.text.MessageFormat;
+
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.Panel;
+
+import com.gitblit.utils.DiffUtils;
+import com.gitblit.utils.DiffUtils.NormalizedDiffStat;
+import com.gitblit.wicket.WicketUtils;
+
+/**
+ * Display a diffstat.
+ *
+ * @author James Moger
+ *
+ */
+public class DiffStatPanel extends Panel {
+
+ private static final long serialVersionUID = 1L;
+
+ final int total;
+
+ final int insertions;
+
+ final int deletions;
+
+ final boolean inline;
+
+ public DiffStatPanel(String wicketId, int insertions, int deletions) {
+ this(wicketId, insertions, deletions, false);
+ }
+
+ public DiffStatPanel(String wicketId, int insertions, int deletions, boolean inline) {
+ super(wicketId);
+ this.insertions = insertions;
+ this.deletions = deletions;
+ this.total = insertions + deletions;
+ this.inline = inline;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ final String diffStat = MessageFormat.format(getString("gb.diffStat"), "" + insertions, "" + deletions);
+ WicketUtils.setHtmlTooltip(this, diffStat);
+
+ final NormalizedDiffStat n = DiffUtils.normalizeDiffStat(5, insertions, deletions);
+
+ final String square = "&#9632;";
+ add(new Label("total", String.valueOf(total)));
+ add(new Label("insertions", timesRepeat(n.insertions, square)).setEscapeModelStrings(false).setVisible(n.insertions > 0));
+ add(new Label("deletions", timesRepeat(n.deletions, square)).setEscapeModelStrings(false).setVisible(n.deletions > 0));
+ add(new Label("blank", timesRepeat(n.blanks, square)).setEscapeModelStrings(false).setVisible(n.blanks > 0));
+
+ if (inline) {
+ WicketUtils.setCssClass(this, "diffstat-inline");
+ } else {
+ WicketUtils.setCssClass(this, "diffstat");
+ }
+
+ setVisible(total > 0);
+ }
+
+ String timesRepeat(int cnt, String s) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < cnt; i++) {
+ sb.append(s);
+ }
+ return sb.toString();
+ }
+}