From 9bc17d16ea48a7978b198126d346828b1d24fe4e Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 18 Apr 2011 22:29:20 -0400 Subject: [PATCH] Color-coded change type indicator with tooltip for changed paths. Also fixed /dev/null reference due to deletion change. --- gitblit.properties | 4 +-- src/com/gitblit/tests/JGitUtilsTest.java | 4 +-- src/com/gitblit/utils/JGitUtils.java | 14 +++++++--- .../gitblit/wicket/GitBlitWebApp.properties | 6 ++++- src/com/gitblit/wicket/RepositoryPage.java | 20 ++++++++++++++ src/com/gitblit/wicket/WicketUtils.java | 21 ++++++++++++++- src/com/gitblit/wicket/models/PathModel.java | 14 ++++++++++ .../gitblit/wicket/pages/CommitDiffPage.html | 1 + .../gitblit/wicket/pages/CommitDiffPage.java | 17 +++++++----- src/com/gitblit/wicket/pages/CommitPage.html | 1 + src/com/gitblit/wicket/pages/CommitPage.java | 16 ++++++----- .../gitblit/wicket/panels/HistoryPanel.java | 5 ++-- src/com/gitblit/wicket/resources/gitblit.css | 27 ++++++++++++++++++- 13 files changed, 125 insertions(+), 25 deletions(-) diff --git a/gitblit.properties b/gitblit.properties index ecefedfb..a81e5f61 100644 --- a/gitblit.properties +++ b/gitblit.properties @@ -130,11 +130,11 @@ server.httpsPort = 443 # Specify the interface for Jetty to bind the standard connector. # You may specify an ip or an empty value to bind to all interfaces. -server.httpBindInterface = localhost +server.httpBindInterface = # Specify the interface for Jetty to bind the secure connector. # You may specify an ip or an empty value to bind to all interfaces. -server.httpsBindInterface = localhost +server.httpsBindInterface = # Password for SSL keystore (keystore password and certificate password must match) server.storePassword = dosomegit diff --git a/src/com/gitblit/tests/JGitUtilsTest.java b/src/com/gitblit/tests/JGitUtilsTest.java index b6b497f0..0ebcd71e 100644 --- a/src/com/gitblit/tests/JGitUtilsTest.java +++ b/src/com/gitblit/tests/JGitUtilsTest.java @@ -15,7 +15,7 @@ import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.storage.file.FileRepository; import com.gitblit.utils.JGitUtils; -import com.gitblit.wicket.models.PathModel; +import com.gitblit.wicket.models.PathModel.PathChangeModel; import com.gitblit.wicket.models.RefModel; import com.gitblit.wicket.models.TicketModel; @@ -82,7 +82,7 @@ public class JGitUtilsTest extends TestCase { public void testFilesInCommit() throws Exception { Repository r = getRepository(); RevCommit commit = JGitUtils.getCommit(r, Constants.HEAD); - List paths = JGitUtils.getFilesInCommit(r, commit); + List paths = JGitUtils.getFilesInCommit(r, commit); r.close(); assertTrue("No changed paths found!", paths.size() > 0); } diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index 49fbf1ef..b1267685 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -19,6 +19,7 @@ import java.util.Set; import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.RawTextComparator; +import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; @@ -49,6 +50,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.wicket.models.Metric; import com.gitblit.wicket.models.PathModel; +import com.gitblit.wicket.models.PathModel.PathChangeModel; import com.gitblit.wicket.models.RefModel; import com.gitblit.wicket.models.TicketModel; import com.gitblit.wicket.models.TicketModel.Comment; @@ -256,13 +258,13 @@ public class JGitUtils { return list; } - public static List getFilesInCommit(Repository r, String commitId) { + public static List getFilesInCommit(Repository r, String commitId) { RevCommit commit = getCommit(r, commitId); return getFilesInCommit(r, commit); } - public static List getFilesInCommit(Repository r, RevCommit commit) { - List list = new ArrayList(); + public static List getFilesInCommit(Repository r, RevCommit commit) { + List list = new ArrayList(); try { final RevWalk rw = new RevWalk(r); RevCommit parent = rw.parseCommit(commit.getParent(0).getId()); @@ -283,7 +285,11 @@ public class JGitUtils { df.setDetectRenames(true); List diffs = df.scan(parentTree, commitTree); for (DiffEntry diff : diffs) { - list.add(new PathModel(diff.getNewPath(), diff.getNewPath(), 0, diff.getNewMode().getBits(), commit.getId().getName())); + if (diff.getChangeType().equals(ChangeType.DELETE)) { + list.add(new PathChangeModel(diff.getOldPath(), diff.getOldPath(), 0, diff.getNewMode().getBits(), commit.getId().getName(), diff.getChangeType())); + } else { + list.add(new PathChangeModel(diff.getNewPath(), diff.getNewPath(), 0, diff.getNewMode().getBits(), commit.getId().getName(), diff.getChangeType())); + } } } catch (Throwable t) { LOGGER.error("failed to determine files in commit!", t); diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index ca757768..b8d31ae5 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -50,4 +50,8 @@ gb.moreHistory = more history... gb.difftocurrent = diff to current gb.search = search gb.searchForAuthor = Search for commits authored by -gb.searchForCommitter = Search for commits committed by \ No newline at end of file +gb.searchForCommitter = Search for commits committed by +gb.addition = addition +gb.modification = modification +gb.deletion = deletion +gb.rename = rename \ No newline at end of file diff --git a/src/com/gitblit/wicket/RepositoryPage.java b/src/com/gitblit/wicket/RepositoryPage.java index 6442bee8..979debda 100644 --- a/src/com/gitblit/wicket/RepositoryPage.java +++ b/src/com/gitblit/wicket/RepositoryPage.java @@ -11,6 +11,7 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.protocol.http.servlet.ServletWebRequest; +import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; @@ -146,6 +147,25 @@ public abstract class RepositoryPage extends BasePage { WicketUtils.setHtmlTitle(component, getString("gb.searchForCommitter") + " " + value); } } + + protected void setChangeTypeTooltip(Component container, ChangeType type) { + switch (type) { + case ADD: + WicketUtils.setHtmlTitle(container, getString("gb.addition")); + break; + case COPY: + case RENAME: + WicketUtils.setHtmlTitle(container, getString("gb.rename")); + break; + case DELETE: + WicketUtils.setHtmlTitle(container, getString("gb.deletion")); + break; + case MODIFY: + WicketUtils.setHtmlTitle(container, getString("gb.modification")); + break; + } + } + @Override protected void onBeforeRender() { // dispose of repository object diff --git a/src/com/gitblit/wicket/WicketUtils.java b/src/com/gitblit/wicket/WicketUtils.java index e4743257..c8d605ba 100644 --- a/src/com/gitblit/wicket/WicketUtils.java +++ b/src/com/gitblit/wicket/WicketUtils.java @@ -9,6 +9,7 @@ import org.apache.wicket.Component; import org.apache.wicket.PageParameters; import org.apache.wicket.behavior.SimpleAttributeModifier; import org.apache.wicket.markup.html.basic.Label; +import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.lib.Constants; import com.gitblit.GitBlit; @@ -31,6 +32,24 @@ public class WicketUtils { container.add(new SimpleAttributeModifier("title", value)); } + public static void setChangeTypeCssClass(Component container, ChangeType type) { + switch (type) { + case ADD: + setCssClass(container, "addition"); + break; + case COPY: + case RENAME: + setCssClass(container, "rename"); + break; + case DELETE: + setCssClass(container, "deletion"); + break; + case MODIFY: + setCssClass(container, "modification"); + break; + } + } + public static void setTicketCssClass(Component container, String state) { String css = null; if (state.equals("open")) { @@ -96,7 +115,7 @@ public class WicketUtils { public static PageParameters newSearchParameter(String repositoryName, String commitId, String search, SearchType type) { if (StringUtils.isEmpty(commitId)) { - return new PageParameters("r=" + repositoryName + ",s=" + search + ",st=" + type.name()); + return new PageParameters("r=" + repositoryName + ",s=" + search + ",st=" + type.name()); } return new PageParameters("r=" + repositoryName + ",h=" + commitId + ",s=" + search + ",st=" + type.name()); } diff --git a/src/com/gitblit/wicket/models/PathModel.java b/src/com/gitblit/wicket/models/PathModel.java index e2e463f9..2895d568 100644 --- a/src/com/gitblit/wicket/models/PathModel.java +++ b/src/com/gitblit/wicket/models/PathModel.java @@ -2,6 +2,8 @@ package com.gitblit.wicket.models; import java.io.Serializable; +import org.eclipse.jgit.diff.DiffEntry.ChangeType; + import com.gitblit.utils.JGitUtils; public class PathModel implements Serializable, Comparable { @@ -50,4 +52,16 @@ public class PathModel implements Serializable, Comparable { } return 1; } + + public static class PathChangeModel extends PathModel { + + private static final long serialVersionUID = 1L; + + public final ChangeType changeType; + + public PathChangeModel(String name, String path, long size, int mode, String commitId, ChangeType type) { + super(name, path, size, mode, commitId); + this.changeType = type; + } + } } diff --git a/src/com/gitblit/wicket/pages/CommitDiffPage.html b/src/com/gitblit/wicket/pages/CommitDiffPage.html index af731a0d..a3a480b5 100644 --- a/src/com/gitblit/wicket/pages/CommitDiffPage.html +++ b/src/com/gitblit/wicket/pages/CommitDiffPage.html @@ -21,6 +21,7 @@ +
[change type] [commit path] diff --git a/src/com/gitblit/wicket/pages/CommitDiffPage.java b/src/com/gitblit/wicket/pages/CommitDiffPage.java index 87e81102..d52b7a36 100644 --- a/src/com/gitblit/wicket/pages/CommitDiffPage.java +++ b/src/com/gitblit/wicket/pages/CommitDiffPage.java @@ -16,7 +16,7 @@ import com.gitblit.utils.JGitUtils; import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.PathModel; +import com.gitblit.wicket.models.PathModel.PathChangeModel; public class CommitDiffPage extends RepositoryPage { @@ -46,14 +46,19 @@ public class CommitDiffPage extends RepositoryPage { add(new LinkPanel("shortlog", "title", commit.getShortMessage(), CommitPage.class, newCommitParameter())); // changed paths list - List paths = JGitUtils.getFilesInCommit(r, commit); - ListDataProvider pathsDp = new ListDataProvider(paths); - DataView pathsView = new DataView("changedPath", pathsDp) { + List paths = JGitUtils.getFilesInCommit(r, commit); + ListDataProvider pathsDp = new ListDataProvider(paths); + DataView pathsView = new DataView("changedPath", pathsDp) { private static final long serialVersionUID = 1L; int counter = 0; - public void populateItem(final Item item) { - final PathModel entry = item.getModelObject(); + public void populateItem(final Item item) { + final PathChangeModel entry = item.getModelObject(); + Label changeType = new Label("changeType", ""); + WicketUtils.setChangeTypeCssClass(changeType, entry.changeType); + setChangeTypeTooltip(changeType, entry.changeType); + item.add(changeType); + if (entry.isTree()) { item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, newPathParameter(entry.path))); } else { diff --git a/src/com/gitblit/wicket/pages/CommitPage.html b/src/com/gitblit/wicket/pages/CommitPage.html index ec1b55df..87547fca 100644 --- a/src/com/gitblit/wicket/pages/CommitPage.html +++ b/src/com/gitblit/wicket/pages/CommitPage.html @@ -45,6 +45,7 @@ +
[change type] [commit path] diff --git a/src/com/gitblit/wicket/pages/CommitPage.java b/src/com/gitblit/wicket/pages/CommitPage.java index 064a7fe5..04065233 100644 --- a/src/com/gitblit/wicket/pages/CommitPage.java +++ b/src/com/gitblit/wicket/pages/CommitPage.java @@ -18,7 +18,7 @@ import com.gitblit.utils.JGitUtils.SearchType; import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.RepositoryPage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.PathModel; +import com.gitblit.wicket.models.PathModel.PathChangeModel; public class CommitPage extends RepositoryPage { @@ -78,14 +78,18 @@ public class CommitPage extends RepositoryPage { addFullText("fullMessage", c.getFullMessage(), true); // changed paths list - List paths = JGitUtils.getFilesInCommit(r, c); - ListDataProvider pathsDp = new ListDataProvider(paths); - DataView pathsView = new DataView("changedPath", pathsDp) { + List paths = JGitUtils.getFilesInCommit(r, c); + ListDataProvider pathsDp = new ListDataProvider(paths); + DataView pathsView = new DataView("changedPath", pathsDp) { private static final long serialVersionUID = 1L; int counter = 0; - public void populateItem(final Item item) { - final PathModel entry = item.getModelObject(); + public void populateItem(final Item item) { + final PathChangeModel entry = item.getModelObject(); + Label changeType = new Label("changeType", ""); + WicketUtils.setChangeTypeCssClass(changeType, entry.changeType); + setChangeTypeTooltip(changeType, entry.changeType); + item.add(changeType); if (entry.isTree()) { item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, newPathParameter(entry.path))); } else { diff --git a/src/com/gitblit/wicket/panels/HistoryPanel.java b/src/com/gitblit/wicket/panels/HistoryPanel.java index dd1395a7..e68fc1ab 100644 --- a/src/com/gitblit/wicket/panels/HistoryPanel.java +++ b/src/com/gitblit/wicket/panels/HistoryPanel.java @@ -18,11 +18,12 @@ import org.eclipse.jgit.revwalk.RevCommit; import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.utils.JGitUtils; -import com.gitblit.utils.StringUtils; import com.gitblit.utils.JGitUtils.SearchType; +import com.gitblit.utils.StringUtils; import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.models.PathModel; +import com.gitblit.wicket.models.PathModel.PathChangeModel; import com.gitblit.wicket.pages.BlobDiffPage; import com.gitblit.wicket.pages.BlobPage; import com.gitblit.wicket.pages.CommitDiffPage; @@ -47,7 +48,7 @@ public class HistoryPanel extends BasePanel { } RevCommit commit = JGitUtils.getCommit(r, objectId); - List paths = JGitUtils.getFilesInCommit(r, commit); + List paths = JGitUtils.getFilesInCommit(r, commit); PathModel matchingPath = null; for (PathModel p : paths) { diff --git a/src/com/gitblit/wicket/resources/gitblit.css b/src/com/gitblit/wicket/resources/gitblit.css index 8264cbb5..d3d68b7a 100644 --- a/src/com/gitblit/wicket/resources/gitblit.css +++ b/src/com/gitblit/wicket/resources/gitblit.css @@ -169,7 +169,7 @@ div.search { color:yellow; text-align:right; float:right; - padding:3px; + padding:3px 4px 3px 3px; } .repositories_message { @@ -281,6 +281,31 @@ span.diff.hunk_section { font-family: inherit; } +span.addition, span.modification, span.deletion, span.rename { + border: 1px solid #888; + float: left; + height: 0.8em; + margin: 0.2em 0.5em 0 0; + overflow: hidden; + width: 0.8em; +} + +span.addition { + background-color: #bbffbb; +} + +span.modification { + background-color: #ffdd88; +} + +span.deletion { + background-color: #ff8888; +} + +span.rename { + background-color: #8888ff; +} + a.list { text-decoration: none; color: #000000; -- 2.39.5