From f602a2f552e1389ee465307723b492b1af378fd5 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 16 Apr 2011 16:28:19 -0400 Subject: [PATCH] Working history feature. Tweak to paging. --- .classpath | 4 +- src/com/gitblit/utils/JGitUtils.java | 11 ++ src/com/gitblit/wicket/GitBlitWebApp.java | 2 + .../gitblit/wicket/GitBlitWebApp.properties | 4 +- src/com/gitblit/wicket/WicketUtils.java | 7 + .../gitblit/wicket/pages/CommitDiffPage.java | 2 +- src/com/gitblit/wicket/pages/CommitPage.java | 2 +- src/com/gitblit/wicket/pages/HistoryPage.html | 28 ++++ src/com/gitblit/wicket/pages/HistoryPage.java | 38 +++++ src/com/gitblit/wicket/pages/LogPage.java | 13 +- src/com/gitblit/wicket/pages/TreePage.java | 16 +-- .../gitblit/wicket/panels/HistoryPanel.html | 35 +++++ .../gitblit/wicket/panels/HistoryPanel.java | 130 ++++++++++++++++++ src/com/gitblit/wicket/panels/LogPanel.java | 10 ++ 14 files changed, 283 insertions(+), 19 deletions(-) create mode 100644 src/com/gitblit/wicket/pages/HistoryPage.html create mode 100644 src/com/gitblit/wicket/pages/HistoryPage.java create mode 100644 src/com/gitblit/wicket/panels/HistoryPanel.html create mode 100644 src/com/gitblit/wicket/panels/HistoryPanel.java diff --git a/.classpath b/.classpath index 4f9e926b..f4a6cb60 100644 --- a/.classpath +++ b/.classpath @@ -3,8 +3,6 @@ - - @@ -15,5 +13,7 @@ + + diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index fa313911..7128f722 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -35,6 +35,7 @@ import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.treewalk.filter.AndTreeFilter; import org.eclipse.jgit.treewalk.filter.PathFilter; import org.eclipse.jgit.treewalk.filter.PathFilterGroup; import org.eclipse.jgit.treewalk.filter.TreeFilter; @@ -436,6 +437,10 @@ public class JGitUtils { } public static List getRevLog(Repository r, String objectId, int offset, int maxCount) { + return getRevLog(r, objectId, null, offset, maxCount); + } + + public static List getRevLog(Repository r, String objectId, String path, int offset, int maxCount) { List list = new ArrayList(); try { if (objectId == null || objectId.trim().length() == 0) { @@ -444,6 +449,12 @@ public class JGitUtils { RevWalk walk = new RevWalk(r); ObjectId object = r.resolve(objectId); walk.markStart(walk.parseCommit(object)); + if (!StringUtils.isEmpty(path)) { + TreeFilter filter = AndTreeFilter.create(PathFilterGroup + .createFromStrings(Collections.singleton(path)), + TreeFilter.ANY_DIFF); + walk.setTreeFilter(filter); + } Iterable revlog = walk; if (offset > 0) { int count = 0; diff --git a/src/com/gitblit/wicket/GitBlitWebApp.java b/src/com/gitblit/wicket/GitBlitWebApp.java index 29d6b515..28f62625 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.java +++ b/src/com/gitblit/wicket/GitBlitWebApp.java @@ -17,6 +17,7 @@ import com.gitblit.wicket.pages.BlobPage; import com.gitblit.wicket.pages.BranchesPage; import com.gitblit.wicket.pages.CommitDiffPage; import com.gitblit.wicket.pages.CommitPage; +import com.gitblit.wicket.pages.HistoryPage; import com.gitblit.wicket.pages.LogPage; import com.gitblit.wicket.pages.PatchPage; import com.gitblit.wicket.pages.RawPage; @@ -60,6 +61,7 @@ public class GitBlitWebApp extends WebApplication { mount(new MixedParamUrlCodingStrategy("/blobdiff", BlobDiffPage.class, new String[] { "r", "h", "f" })); mount(new MixedParamUrlCodingStrategy("/commitdiff", CommitDiffPage.class, new String[] { "r", "h" })); mount(new MixedParamUrlCodingStrategy("/patch", PatchPage.class, new String[] { "r", "h", "f" })); + mount(new MixedParamUrlCodingStrategy("/history", HistoryPage.class, new String[] { "r", "h", "f" })); // setup ticgit urls mount(new MixedParamUrlCodingStrategy("/ticgit", TicGitPage.class, new String[] { "r" })); diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index a5583c7a..033742eb 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -45,4 +45,6 @@ gb.login = Login gb.logout = Logout gb.username = Username gb.password = Password -gb.tagger = tagger \ No newline at end of file +gb.tagger = tagger +gb.moreHistory = more history... +gb.difftocurrent = diff to current \ No newline at end of file diff --git a/src/com/gitblit/wicket/WicketUtils.java b/src/com/gitblit/wicket/WicketUtils.java index 3288498f..3bc55f1b 100644 --- a/src/com/gitblit/wicket/WicketUtils.java +++ b/src/com/gitblit/wicket/WicketUtils.java @@ -80,6 +80,13 @@ public class WicketUtils { } return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",page=" + pageNumber); } + + public static PageParameters newHistoryPageParameter(String repositoryName, String objectId, String path, int pageNumber) { + if (pageNumber <= 1) { + return newObjectParameter(repositoryName, objectId); + } + return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",f=" + path + ",page=" + pageNumber); + } public static String getRepositoryName(PageParameters params) { return params.getString("r", ""); diff --git a/src/com/gitblit/wicket/pages/CommitDiffPage.java b/src/com/gitblit/wicket/pages/CommitDiffPage.java index 7218cf81..87e81102 100644 --- a/src/com/gitblit/wicket/pages/CommitDiffPage.java +++ b/src/com/gitblit/wicket/pages/CommitDiffPage.java @@ -63,7 +63,7 @@ public class CommitDiffPage extends RepositoryPage { item.add(new BookmarkablePageLink("patch", PatchPage.class, newPathParameter(entry.path))); item.add(new BookmarkablePageLink("view", BlobPage.class, newPathParameter(entry.path))); item.add(new BookmarkablePageLink("blame", BlobPage.class).setEnabled(false)); - item.add(new BookmarkablePageLink("history", BlobPage.class).setEnabled(false)); + item.add(new BookmarkablePageLink("history", HistoryPage.class, newPathParameter(entry.path))); WicketUtils.setAlternatingBackground(item, counter); counter++; diff --git a/src/com/gitblit/wicket/pages/CommitPage.java b/src/com/gitblit/wicket/pages/CommitPage.java index 9cc6df85..63817ca3 100644 --- a/src/com/gitblit/wicket/pages/CommitPage.java +++ b/src/com/gitblit/wicket/pages/CommitPage.java @@ -92,7 +92,7 @@ public class CommitPage extends RepositoryPage { item.add(new BookmarkablePageLink("diff", BlobDiffPage.class, newPathParameter(entry.path))); item.add(new BookmarkablePageLink("view", BlobPage.class, newPathParameter(entry.path))); item.add(new BookmarkablePageLink("blame", BlobPage.class).setEnabled(false)); - item.add(new BookmarkablePageLink("history", BlobPage.class).setEnabled(false)); + item.add(new BookmarkablePageLink("history", HistoryPage.class, newPathParameter(entry.path))); WicketUtils.setAlternatingBackground(item, counter); counter++; diff --git a/src/com/gitblit/wicket/pages/HistoryPage.html b/src/com/gitblit/wicket/pages/HistoryPage.html new file mode 100644 index 00000000..a77933eb --- /dev/null +++ b/src/com/gitblit/wicket/pages/HistoryPage.html @@ -0,0 +1,28 @@ + + + + + + + +
[page links]
+ + +
+ | | +
+ + +
[history panel]
+ + +
+ | | +
+ +
+ + \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/HistoryPage.java b/src/com/gitblit/wicket/pages/HistoryPage.java new file mode 100644 index 00000000..8b7075a3 --- /dev/null +++ b/src/com/gitblit/wicket/pages/HistoryPage.java @@ -0,0 +1,38 @@ +package com.gitblit.wicket.pages; + +import org.apache.wicket.PageParameters; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; + +import com.gitblit.wicket.RepositoryPage; +import com.gitblit.wicket.WicketUtils; +import com.gitblit.wicket.panels.HistoryPanel; + +public class HistoryPage extends RepositoryPage { + + public HistoryPage(PageParameters params) { + super(params); + + String path = WicketUtils.getPath(params); + int pageNumber = WicketUtils.getPage(params); + int prevPage = Math.max(0, pageNumber - 1); + int nextPage = pageNumber + 1; + + HistoryPanel history = new HistoryPanel("historyPanel", repositoryName, objectId, path, getRepository(), -1, pageNumber - 1); + boolean hasMore = history.hasMore(); + add(history); + + add(new BookmarkablePageLink("firstPageTop", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, objectId, path)).setEnabled(pageNumber > 1)); + add(new BookmarkablePageLink("prevPageTop", HistoryPage.class, WicketUtils.newHistoryPageParameter(repositoryName, objectId, path, prevPage)).setEnabled(pageNumber > 1)); + add(new BookmarkablePageLink("nextPageTop", HistoryPage.class, WicketUtils.newHistoryPageParameter(repositoryName, objectId, path, nextPage)).setEnabled(hasMore)); + + add(new BookmarkablePageLink("firstPageBottom", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, objectId, path)).setEnabled(pageNumber > 1)); + add(new BookmarkablePageLink("prevPageBottom", HistoryPage.class, WicketUtils.newHistoryPageParameter(repositoryName, objectId, path, prevPage)).setEnabled(pageNumber > 1)); + add(new BookmarkablePageLink("nextPageBottom", HistoryPage.class, WicketUtils.newHistoryPageParameter(repositoryName, objectId, path, nextPage)).setEnabled(hasMore)); + + } + + @Override + protected String getPageName() { + return getString("gb.history"); + } +} diff --git a/src/com/gitblit/wicket/pages/LogPage.java b/src/com/gitblit/wicket/pages/LogPage.java index cd75df9c..38148f5a 100644 --- a/src/com/gitblit/wicket/pages/LogPage.java +++ b/src/com/gitblit/wicket/pages/LogPage.java @@ -15,16 +15,17 @@ public class LogPage extends RepositoryPage { int pageNumber = WicketUtils.getPage(params); int prevPage = Math.max(0, pageNumber - 1); int nextPage = pageNumber + 1; + LogPanel logPanel = new LogPanel("logPanel", repositoryName, objectId, getRepository(), -1, pageNumber - 1); + boolean hasMore = logPanel.hasMore(); + add(logPanel); - add(new BookmarkablePageLink("firstPageTop", LogPage.class, WicketUtils.newObjectParameter(repositoryName, objectId))); + add(new BookmarkablePageLink("firstPageTop", LogPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)).setEnabled(pageNumber > 1)); add(new BookmarkablePageLink("prevPageTop", LogPage.class, WicketUtils.newLogPageParameter(repositoryName, objectId, prevPage)).setEnabled(pageNumber > 1)); - add(new BookmarkablePageLink("nextPageTop", LogPage.class, WicketUtils.newLogPageParameter(repositoryName, objectId, nextPage))); + add(new BookmarkablePageLink("nextPageTop", LogPage.class, WicketUtils.newLogPageParameter(repositoryName, objectId, nextPage)).setEnabled(hasMore)); - add(new LogPanel("logPanel", repositoryName, objectId, getRepository(), -1, pageNumber - 1)); - - add(new BookmarkablePageLink("firstPageBottom", LogPage.class, WicketUtils.newObjectParameter(repositoryName, objectId))); + add(new BookmarkablePageLink("firstPageBottom", LogPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)).setEnabled(pageNumber > 1)); add(new BookmarkablePageLink("prevPageBottom", LogPage.class, WicketUtils.newLogPageParameter(repositoryName, objectId, prevPage)).setEnabled(pageNumber > 1)); - add(new BookmarkablePageLink("nextPageBottom", LogPage.class, WicketUtils.newLogPageParameter(repositoryName, objectId, nextPage))); + add(new BookmarkablePageLink("nextPageBottom", LogPage.class, WicketUtils.newLogPageParameter(repositoryName, objectId, nextPage)).setEnabled(hasMore)); } @Override diff --git a/src/com/gitblit/wicket/pages/TreePage.java b/src/com/gitblit/wicket/pages/TreePage.java index 5ebb1b65..2ab164da 100644 --- a/src/com/gitblit/wicket/pages/TreePage.java +++ b/src/com/gitblit/wicket/pages/TreePage.java @@ -26,22 +26,22 @@ public class TreePage extends RepositoryPage { public TreePage(PageParameters params) { super(params); - final String basePath = WicketUtils.getPath(params); + final String path = WicketUtils.getPath(params); Repository r = getRepository(); RevCommit commit = JGitUtils.getCommit(r, objectId); - List paths = JGitUtils.getFilesInPath(r, basePath, commit); + List paths = JGitUtils.getFilesInPath(r, path, commit); // tree page links add(new Label("historyLink", getString("gb.history"))); - add(new BookmarkablePageLink("headLink", TreePage.class, WicketUtils.newPathParameter(repositoryName, Constants.HEAD, basePath))); + add(new BookmarkablePageLink("headLink", TreePage.class, WicketUtils.newPathParameter(repositoryName, Constants.HEAD, path))); add(new LinkPanel("shortlog", "title", commit.getShortMessage(), CommitPage.class, newCommitParameter())); // breadcrumbs - add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, basePath, objectId)); - if (basePath != null && basePath.trim().length() > 0) { - paths.add(0, PathModel.getParentPath(basePath, objectId)); + add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId)); + if (path != null && path.trim().length() > 0) { + paths.add(0, PathModel.getParentPath(path, objectId)); } final ByteFormat byteFormat = new ByteFormat(); @@ -69,7 +69,7 @@ public class TreePage extends RepositoryPage { // links Fragment links = new Fragment("pathLinks", "treeLinks", this); links.add(new BookmarkablePageLink("tree", TreePage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))); - links.add(new BookmarkablePageLink("history", TreePage.class).setEnabled(false)); + links.add(new BookmarkablePageLink("history", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))); item.add(links); } else { // blob link @@ -81,7 +81,7 @@ public class TreePage extends RepositoryPage { links.add(new BookmarkablePageLink("view", BlobPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))); links.add(new BookmarkablePageLink("raw", RawPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))); links.add(new BookmarkablePageLink("blame", BlobPage.class).setEnabled(false)); - links.add(new BookmarkablePageLink("history", BlobPage.class).setEnabled(false)); + links.add(new BookmarkablePageLink("history", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))); item.add(links); } } diff --git a/src/com/gitblit/wicket/panels/HistoryPanel.html b/src/com/gitblit/wicket/panels/HistoryPanel.html new file mode 100644 index 00000000..9ba95de4 --- /dev/null +++ b/src/com/gitblit/wicket/panels/HistoryPanel.html @@ -0,0 +1,35 @@ + + + + + + + +
[history header]
+ + +
[breadcrumbs]
+ + + + + + + + + + + +
[commit date][commit author]
[commit short message]
[commit refs]
+ + | | + +
+
[more...]
+ +
+ + \ No newline at end of file diff --git a/src/com/gitblit/wicket/panels/HistoryPanel.java b/src/com/gitblit/wicket/panels/HistoryPanel.java new file mode 100644 index 00000000..236e077b --- /dev/null +++ b/src/com/gitblit/wicket/panels/HistoryPanel.java @@ -0,0 +1,130 @@ +package com.gitblit.wicket.panels; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.markup.repeater.data.DataView; +import org.apache.wicket.markup.repeater.data.ListDataProvider; +import org.apache.wicket.model.StringResourceModel; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; +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.wicket.LinkPanel; +import com.gitblit.wicket.WicketUtils; +import com.gitblit.wicket.pages.BlobDiffPage; +import com.gitblit.wicket.pages.CommitDiffPage; +import com.gitblit.wicket.pages.CommitPage; +import com.gitblit.wicket.pages.HistoryPage; +import com.gitblit.wicket.pages.LogPage; + +public class HistoryPanel extends BasePanel { + + private static final long serialVersionUID = 1L; + + private boolean hasMore = false; + + public HistoryPanel(String wicketId, final String repositoryName, String objectId, final String path, Repository r, int limit, int pageOffset) { + super(wicketId); + boolean pageResults = limit <= 0; + int itemsPerPage = GitBlit.self().settings().getInteger(Keys.web.logPageCommitCount, 50); + if (itemsPerPage <= 1) { + itemsPerPage = 50; + } + + RevCommit commit = JGitUtils.getCommit(r, objectId); + final Map> allRefs = JGitUtils.getAllRefs(r); + List commits; + if (pageResults) { + // Paging result set + commits = JGitUtils.getRevLog(r, objectId, path, pageOffset * itemsPerPage, itemsPerPage); + } else { + // Fixed size result set + commits = JGitUtils.getRevLog(r, objectId, path, 0, limit); + } + + // inaccurate way to determine if there are more commits. + // works unless commits.size() represents the exact end. + hasMore = commits.size() >= itemsPerPage; + + // header + if (pageResults) { + // history page + // show commit page link + add(new LinkPanel("header", "title", commit.getShortMessage(), CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName()))); + } else { + // summary page + // show history page link + add(new LinkPanel("header", "title", new StringResourceModel("gb.history", this, null), LogPage.class, WicketUtils.newRepositoryParameter(repositoryName))); + } + + // breadcrumbs + add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId)); + + ListDataProvider dp = new ListDataProvider(commits); + DataView logView = new DataView("commit", dp) { + private static final long serialVersionUID = 1L; + int counter = 0; + + public void populateItem(final Item item) { + final RevCommit entry = item.getModelObject(); + final Date date = JGitUtils.getCommitDate(entry); + + item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone())); + + String author = entry.getAuthorIdent().getName(); + item.add(WicketUtils.createAuthorLabel("commitAuthor", author)); + + String shortMessage = entry.getShortMessage(); + String trimmedMessage = StringUtils.trimShortLog(shortMessage); + LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject", trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())); + if (!shortMessage.equals(trimmedMessage)) { + WicketUtils.setHtmlTitle(shortlog, shortMessage); + } + item.add(shortlog); + + item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs)); + + item.add(new BookmarkablePageLink("view", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName()))); + item.add(new BookmarkablePageLink("commitdiff", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName()))); + item.add(new BookmarkablePageLink("difftocurrent", BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, entry.getName(), path)).setEnabled(counter > 0)); + + WicketUtils.setAlternatingBackground(item, counter); + counter++; + } + }; + add(logView); + + // determine to show pager, more, or neither + if (limit <= 0) { + // no display limit + add(new Label("moreHistory", "").setVisible(false)); + } else { + if (pageResults) { + // paging + add(new Label("moreHistory", "").setVisible(false)); + } else { + // more + if (commits.size() == limit) { + // show more + add(new LinkPanel("moreHistory", "link", new StringResourceModel("gb.moreHistory", this, null), HistoryPage.class, WicketUtils.newPathParameter(repositoryName, objectId, path))); + } else { + // no more + add(new Label("moreHistory", "").setVisible(false)); + } + } + } + } + + public boolean hasMore() { + return hasMore; + } +} diff --git a/src/com/gitblit/wicket/panels/LogPanel.java b/src/com/gitblit/wicket/panels/LogPanel.java index 20754108..954af757 100644 --- a/src/com/gitblit/wicket/panels/LogPanel.java +++ b/src/com/gitblit/wicket/panels/LogPanel.java @@ -29,6 +29,8 @@ import com.gitblit.wicket.pages.TreePage; public class LogPanel extends BasePanel { private static final long serialVersionUID = 1L; + + private boolean hasMore = false; public LogPanel(String wicketId, final String repositoryName, String objectId, Repository r, int limit, int pageOffset) { super(wicketId); @@ -48,6 +50,10 @@ public class LogPanel extends BasePanel { commits = JGitUtils.getRevLog(r, objectId, 0, limit); } + // inaccurate way to determine if there are more commits. + // works unless commits.size() represents the exact end. + hasMore = commits.size() >= itemsPerPage; + // header if (pageResults) { // shortlog page @@ -113,4 +119,8 @@ public class LogPanel extends BasePanel { } } } + + public boolean hasMore() { + return hasMore; + } } -- 2.39.5