diff options
-rw-r--r-- | releases.moxie | 3 | ||||
-rw-r--r-- | src/main/distrib/data/gitblit.properties | 14 | ||||
-rw-r--r-- | src/main/java/com/gitblit/models/PushLogEntry.java | 106 | ||||
-rw-r--r-- | src/main/java/com/gitblit/utils/PushLogUtils.java | 97 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/GitBlitWebApp.java | 2 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/GitBlitWebApp.properties | 15 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/OverviewPage.java | 3 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/PushesPage.html | 25 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/PushesPage.java | 55 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/RepositoryPage.java | 3 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/panels/PushesPanel.html | 35 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/panels/PushesPanel.java | 219 |
12 files changed, 464 insertions, 113 deletions
diff --git a/releases.moxie b/releases.moxie index 114424e6..1b595340 100644 --- a/releases.moxie +++ b/releases.moxie @@ -39,6 +39,7 @@ r17: { - Updated Japanese translation
additions:
+ - Added a ui for the push log introduced in 1.2.1 (issue-177)
- Added client application menus for Git, SourceTree, Tower, GitHub for Windows, GitHub for Mac, and SparkleShare
- Added GO http/https connector thread pool size setting
- Added a server setting to force a particular translation/Locale for all sessions
@@ -92,6 +93,8 @@ r17: { - { name: 'git.defaultIncrementalPushTagPrefix', defaultValue: 'r' }
- { name: 'web.allowAppCloneLinks', defaultValue: true }
- { name: 'web.forceDefaultLocale', defaultValue: ' ' }
+ - { name: 'web.overviewPushCount', defaultValue: 5 }
+ - { name: 'web.pushesPerPage', defaultValue: 10 }
- { name: 'server.nioThreadPoolSize', defaultValue: 50 }
}
diff --git a/src/main/distrib/data/gitblit.properties b/src/main/distrib/data/gitblit.properties index 2912bfe2..0fc1780f 100644 --- a/src/main/distrib/data/gitblit.properties +++ b/src/main/distrib/data/gitblit.properties @@ -834,11 +834,23 @@ web.summaryCommitCount = 16 web.summaryRefsCount = 5
# The number of items to show on a page before showing the first, prev, next
-# pagination links. A default if 50 is used for any invalid value.
+# pagination links. A default of 50 is used for any invalid value.
#
# SINCE 0.5.0
web.itemsPerPage = 50
+# The number of pushes to display on the overview page
+# Value must exceed 0 else default of 5 is used
+#
+# SINCE 1.3.0
+web.overviewPushCount = 5
+
+# The number of pushes to show on a push page before show the first, prev, next
+# pagination links. A default of 10 is used for any invalid value.
+#
+# SINCE 1.3.0
+web.pushesPerPage = 10
+
# Registered file extensions to ignore during Lucene indexing
#
# SPACE-DELIMITED
diff --git a/src/main/java/com/gitblit/models/PushLogEntry.java b/src/main/java/com/gitblit/models/PushLogEntry.java index 83230737..d8f0b091 100644 --- a/src/main/java/com/gitblit/models/PushLogEntry.java +++ b/src/main/java/com/gitblit/models/PushLogEntry.java @@ -32,6 +32,8 @@ import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.ReceiveCommand;
+import com.gitblit.utils.StringUtils;
+
/**
* Model class to represent a push into a repository.
*
@@ -50,6 +52,8 @@ public class PushLogEntry implements Serializable, Comparable<PushLogEntry> { private final Set<RepositoryCommit> commits;
private final Map<String, ReceiveCommand.Type> refUpdates;
+
+ private final Map<String, String> refIdChanges;
/**
* Constructor for specified duration of push from start date.
@@ -67,6 +71,7 @@ public class PushLogEntry implements Serializable, Comparable<PushLogEntry> { this.user = user;
this.commits = new LinkedHashSet<RepositoryCommit>();
this.refUpdates = new HashMap<String, ReceiveCommand.Type>();
+ this.refIdChanges = new HashMap<String, String>();
}
/**
@@ -80,6 +85,60 @@ public class PushLogEntry implements Serializable, Comparable<PushLogEntry> { refUpdates.put(ref, type);
}
}
+
+ /**
+ * Tracks the change type for the specified ref.
+ *
+ * @param ref
+ * @param type
+ * @param oldId
+ * @param newId
+ */
+ public void updateRef(String ref, ReceiveCommand.Type type, String oldId, String newId) {
+ if (!refUpdates.containsKey(ref)) {
+ refUpdates.put(ref, type);
+ refIdChanges.put(ref, oldId + "-" + newId);
+ }
+ }
+
+ /**
+ * Returns the old id of a ref.
+ *
+ * @param ref
+ * @return the old id
+ */
+ public String getOldId(String ref) {
+ String change = refIdChanges.get(ref);
+ if (StringUtils.isEmpty(change)) {
+ return null;
+ }
+ return change.split("-")[0];
+ }
+
+ /**
+ * Returns the new id of a ref
+ *
+ * @param ref
+ * @return the new id
+ */
+ public String getNewId(String ref) {
+ String change = refIdChanges.get(ref);
+ if (StringUtils.isEmpty(change)) {
+ return null;
+ }
+ return change.split("-")[1];
+ }
+
+ /**
+ * Returns the change type of the ref change.
+ *
+ * @param ref
+ * @return the change type for the ref
+ */
+ public ReceiveCommand.Type getChangeType(String ref) {
+ ReceiveCommand.Type type = refUpdates.get(ref);
+ return type;
+ }
/**
* Adds a commit to the push entry object as long as the commit is not a
@@ -99,6 +158,16 @@ public class PushLogEntry implements Serializable, Comparable<PushLogEntry> { }
/**
+ * Adds a a list of repository commits. This is used to construct discrete
+ * ref push log entries
+ *
+ * @param commits
+ */
+ public void addCommits(List<RepositoryCommit> list) {
+ commits.addAll(list);
+ }
+
+ /**
* Returns true if this push contains a non-fastforward ref update.
*
* @return true if this is a non-fastforward push
@@ -113,6 +182,43 @@ public class PushLogEntry implements Serializable, Comparable<PushLogEntry> { }
/**
+ * Returns true if this ref has been rewound.
+ *
+ * @param ref
+ * @return true if this is a non-fastforward ref update
+ */
+ public boolean isNonFastForward(String ref) {
+ ReceiveCommand.Type type = refUpdates.get(ref);
+ if (type == null) {
+ return false;
+ }
+ return ReceiveCommand.Type.UPDATE_NONFASTFORWARD.equals(type);
+ }
+
+ /**
+ * Returns true if this ref has been deleted.
+ *
+ * @param ref
+ * @return true if this is a delete ref update
+ */
+ public boolean isDelete(String ref) {
+ ReceiveCommand.Type type = refUpdates.get(ref);
+ if (type == null) {
+ return false;
+ }
+ return ReceiveCommand.Type.DELETE.equals(type);
+ }
+
+ /**
+ * Returns the list of refs changed by the push.
+ *
+ * @return a list of refs
+ */
+ public List<String> getChangedRefs() {
+ return new ArrayList<String>(refUpdates.keySet());
+ }
+
+ /**
* Returns the list of branches changed by the push.
*
* @return a list of branches
diff --git a/src/main/java/com/gitblit/utils/PushLogUtils.java b/src/main/java/com/gitblit/utils/PushLogUtils.java index 5b065061..e9605724 100644 --- a/src/main/java/com/gitblit/utils/PushLogUtils.java +++ b/src/main/java/com/gitblit/utils/PushLogUtils.java @@ -21,7 +21,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -51,6 +53,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.models.PathModel.PathChangeModel; import com.gitblit.models.PushLogEntry; import com.gitblit.models.RefModel; +import com.gitblit.models.RepositoryCommit; import com.gitblit.models.UserModel; /** @@ -283,28 +286,50 @@ public class PushLogUtils { } return inCoreIndex; } - + public static List<PushLogEntry> getPushLog(String repositoryName, Repository repository) { - return getPushLog(repositoryName, repository, null, -1); + return getPushLog(repositoryName, repository, null, 0, -1); } public static List<PushLogEntry> getPushLog(String repositoryName, Repository repository, int maxCount) { - return getPushLog(repositoryName, repository, null, maxCount); + return getPushLog(repositoryName, repository, null, 0, maxCount); + } + + public static List<PushLogEntry> getPushLog(String repositoryName, Repository repository, int offset, int maxCount) { + return getPushLog(repositoryName, repository, null, offset, maxCount); } public static List<PushLogEntry> getPushLog(String repositoryName, Repository repository, Date minimumDate) { - return getPushLog(repositoryName, repository, minimumDate, -1); + return getPushLog(repositoryName, repository, minimumDate, 0, -1); } - public static List<PushLogEntry> getPushLog(String repositoryName, Repository repository, Date minimumDate, int maxCount) { + /** + * Returns the list of push log entries as they were recorded by Gitblit. + * Each PushLogEntry may represent multiple ref updates. + * + * @param repositoryName + * @param repository + * @param minimumDate + * @param offset + * @param maxCount + * if < 0, all pushes are returned. + * @return a list of push log entries + */ + public static List<PushLogEntry> getPushLog(String repositoryName, Repository repository, + Date minimumDate, int offset, int maxCount) { List<PushLogEntry> list = new ArrayList<PushLogEntry>(); RefModel ref = getPushLogBranch(repository); if (ref == null) { return list; } + if (maxCount == 0) { + return list; + } + + Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository); List<RevCommit> pushes; if (minimumDate == null) { - pushes = JGitUtils.getRevLog(repository, GB_PUSHES, 0, maxCount); + pushes = JGitUtils.getRevLog(repository, GB_PUSHES, offset, maxCount); } else { pushes = JGitUtils.getRevLog(repository, GB_PUSHES, minimumDate); } @@ -344,12 +369,15 @@ public class PushLogUtils { default: String content = JGitUtils.getStringContent(repository, push.getTree(), change.path); String [] fields = content.split(" "); - log.updateRef(change.path, ReceiveCommand.Type.valueOf(fields[0])); String oldId = fields[1]; String newId = fields[2]; + log.updateRef(change.path, ReceiveCommand.Type.valueOf(fields[0]), oldId, newId); List<RevCommit> pushedCommits = JGitUtils.getRevLog(repository, oldId, newId); for (RevCommit pushedCommit : pushedCommits) { - log.addCommit(change.path, pushedCommit); + RepositoryCommit repoCommit = log.addCommit(change.path, pushedCommit); + if (repoCommit != null) { + repoCommit.setRefs(allRefs.get(pushedCommit.getId())); + } } } } @@ -357,4 +385,57 @@ public class PushLogUtils { Collections.sort(list); return list; } + + /** + * Returns the list of pushes separated by ref (e.g. each ref has it's own + * PushLogEntry object). + * + * @param repositoryName + * @param repository + * @param maxCount + * @return a list of push log entries separated by ref + */ + public static List<PushLogEntry> getPushLogByRef(String repositoryName, Repository repository, int maxCount) { + return getPushLogByRef(repositoryName, repository, 0, maxCount); + } + + /** + * Returns the list of pushes separated by ref (e.g. each ref has it's own + * PushLogEntry object). + * + * @param repositoryName + * @param repository + * @param offset + * @param maxCount + * @return a list of push log entries separated by ref + */ + public static List<PushLogEntry> getPushLogByRef(String repositoryName, Repository repository, int offset, + int maxCount) { + // break the push log into ref push logs and then merge them back into a list + Map<String, List<PushLogEntry>> refMap = new HashMap<String, List<PushLogEntry>>(); + for (PushLogEntry push : getPushLog(repositoryName, repository, offset, maxCount)) { + for (String ref : push.getChangedRefs()) { + if (!refMap.containsKey(ref)) { + refMap.put(ref, new ArrayList<PushLogEntry>()); + } + + // construct new ref-specific push log entry + PushLogEntry refPush = new PushLogEntry(push.repository, push.date, push.user); + refPush.updateRef(ref, push.getChangeType(ref), push.getOldId(ref), push.getNewId(ref)); + refPush.addCommits(push.getCommits(ref)); + refMap.get(ref).add(refPush); + } + } + + // merge individual ref pushes into master list + List<PushLogEntry> refPushLog = new ArrayList<PushLogEntry>(); + for (List<PushLogEntry> refPush : refMap.values()) { + refPushLog.addAll(refPush); + } + + // sort ref push log + Collections.sort(refPushLog); + + return refPushLog; + } } diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java index dcae53ef..bdb4d455 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java @@ -53,6 +53,7 @@ import com.gitblit.wicket.pages.OverviewPage; import com.gitblit.wicket.pages.PatchPage;
import com.gitblit.wicket.pages.ProjectPage;
import com.gitblit.wicket.pages.ProjectsPage;
+import com.gitblit.wicket.pages.PushesPage;
import com.gitblit.wicket.pages.RawPage;
import com.gitblit.wicket.pages.RepositoriesPage;
import com.gitblit.wicket.pages.ReviewProposalPage;
@@ -96,6 +97,7 @@ public class GitBlitWebApp extends WebApplication { // mount("/repositories", RepositoriesPage.class);
mount("/overview", OverviewPage.class, "r", "h");
mount("/summary", SummaryPage.class, "r");
+ mount("/pushes", PushesPage.class, "r", "h");
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/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties index bec8b35b..eaf07c4c 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties @@ -458,4 +458,17 @@ gb.myProfile = my profile gb.compare = compare
gb.manual = manual
gb.from = from
-gb.to = to
\ No newline at end of file +gb.to = to
+gb.at = at
+gb.morePushes = all pushes...
+gb.pushes = pushes
+gb.pushedNCommitsTo = pushed {0} commits to
+gb.pushedOneCommitTo = pushed 1 commit to
+gb.viewComparison = view comparison of these {0} commits \u00bb
+gb.nMoreCommits = {0} more commits \u00bb
+gb.oneMoreCommit = 1 more commit \u00bb
+gb.pushedNewTag = pushed new tag
+gb.deletedTag = deleted tag
+gb.pushedNewBranch = pushed new branch
+gb.deletedBranch = deleted branch
+gb.rewind = REWIND
\ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/OverviewPage.java b/src/main/java/com/gitblit/wicket/pages/OverviewPage.java index 3f5eaa2c..aea07bfe 100644 --- a/src/main/java/com/gitblit/wicket/pages/OverviewPage.java +++ b/src/main/java/com/gitblit/wicket/pages/OverviewPage.java @@ -109,7 +109,8 @@ public class OverviewPage extends RepositoryPage { add(new RepositoryUrlPanel("repositoryUrlPanel", false, user, model));
- PushesPanel pushes = new PushesPanel("pushesPanel", getRepositoryModel(), r, 10, 0);
+ int pushCount = GitBlit.getInteger(Keys.web.overviewPushCount, 5);
+ PushesPanel pushes = new PushesPanel("pushesPanel", getRepositoryModel(), r, pushCount, 0);
add(pushes);
add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());
diff --git a/src/main/java/com/gitblit/wicket/pages/PushesPage.html b/src/main/java/com/gitblit/wicket/pages/PushesPage.html new file mode 100644 index 00000000..145db6f5 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/pages/PushesPage.html @@ -0,0 +1,25 @@ +<!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">
+
+<body>
+<wicket:extend>
+
+ <!-- pager links -->
+ <div class="page_nav2">
+ <a wicket:id="firstPage"><wicket:message key="gb.pageFirst"></wicket:message></a> | <a wicket:id="prevPage">« <wicket:message key="gb.pagePrevious"></wicket:message></a> | <a wicket:id="nextPage"><wicket:message key="gb.pageNext"></wicket:message> »</a>
+ </div>
+
+ <!-- push log -->
+ <div style="margin-top:5px;" wicket:id="pushesPanel">[push log panel]</div>
+
+ <!-- pager links -->
+ <div style="padding-bottom:5px;">
+ <a wicket:id="firstPage"><wicket:message key="gb.pageFirst"></wicket:message></a> | <a wicket:id="prevPage">« <wicket:message key="gb.pagePrevious"></wicket:message></a> | <a wicket:id="nextPage"><wicket:message key="gb.pageNext"></wicket:message> »</a>
+ </div>
+
+</wicket:extend>
+</body>
+</html>
\ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/PushesPage.java b/src/main/java/com/gitblit/wicket/pages/PushesPage.java new file mode 100644 index 00000000..a0e7c973 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/pages/PushesPage.java @@ -0,0 +1,55 @@ +/*
+ * 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.pages;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+
+import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.panels.PushesPanel;
+
+public class PushesPage extends RepositoryPage {
+
+ public PushesPage(PageParameters params) {
+ super(params);
+
+ addSyndicationDiscoveryLink();
+
+ int pageNumber = WicketUtils.getPage(params);
+ int prevPage = Math.max(0, pageNumber - 1);
+ int nextPage = pageNumber + 1;
+
+ PushesPanel pushesPanel = new PushesPanel("pushesPanel", getRepositoryModel(), getRepository(), -1,
+ pageNumber - 1);
+ boolean hasMore = pushesPanel.hasMore();
+ add(pushesPanel);
+
+ add(new BookmarkablePageLink<Void>("firstPage", PushesPage.class,
+ WicketUtils.newObjectParameter(repositoryName, objectId))
+ .setEnabled(pageNumber > 1));
+ add(new BookmarkablePageLink<Void>("prevPage", PushesPage.class,
+ WicketUtils.newLogPageParameter(repositoryName, objectId, prevPage))
+ .setEnabled(pageNumber > 1));
+ add(new BookmarkablePageLink<Void>("nextPage", PushesPage.class,
+ WicketUtils.newLogPageParameter(repositoryName, objectId, nextPage))
+ .setEnabled(hasMore));
+ }
+
+ @Override
+ protected String getPageName() {
+ return getString("gb.pushes");
+ }
+}
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java index 072475a0..94adf564 100644 --- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java @@ -166,7 +166,8 @@ public abstract class RepositoryPage extends RootPage { } else {
pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
// pages.put("overview", new PageRegistration("gb.overview", OverviewPage.class, params));
- }
+ pages.put("pushes", new PageRegistration("gb.pushes", PushesPage.class, params));
+ }
pages.put("commits", new PageRegistration("gb.commits", LogPage.class, params));
pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params));
pages.put("compare", new PageRegistration("gb.compare", ComparePage.class, params));
diff --git a/src/main/java/com/gitblit/wicket/panels/PushesPanel.html b/src/main/java/com/gitblit/wicket/panels/PushesPanel.html index 5bdc30a5..e8f16e9e 100644 --- a/src/main/java/com/gitblit/wicket/panels/PushesPanel.html +++ b/src/main/java/com/gitblit/wicket/panels/PushesPanel.html @@ -6,32 +6,33 @@ <body>
<wicket:panel>
-<div wicket:id="push">
+<div wicket:id="push" style="border-bottom: 1px solid #ddd;margin-bottom: 15px;">
<table style="padding: 3px 0px;">
<tr>
<td class="hidden-phone" style="vertical-align: top;"><span wicket:id="whoAvatar"></span></td>
<td style="padding-left: 7px;">
- <div><span wicket:id="whoPushed">[pusher]</span> <span wicket:id="whatPushed"></span><span wicket:id="wherePushed"></span></div>
- <div wicket:id="whenPushed"></div>
- <button type="button" class="btn btn-mini" style="padding: 1px 3px;line-height: 12px;" data-toggle="collapse" data-target="#demo"><span class="caret"></span></button>
- <div id="demo" class="collapse">
- <div style="padding: 10px 0px;">
- <table>
- <tr wicket:id="commit" style="border-left: 1px solid #ddd;">
- <td style="vertical-align:top;"><span wicket:id="hashLink" style="padding-left: 10px;">[hash link]</span></td>
- <td><img wicket:id="commitIcon" /></td>
- <td style="vertical-align:top;">
- <div wicket:id="commitShortMessage">[commit short message]</div>
- <div wicket:id="commitRefs">[commit refs]</div>
- </td>
- </tr>
- </table>
- </div>
+ <div>
+ <span wicket:id="whenPushed"></span> <span wicket:id="refRewind" class="alert alert-error" style="padding: 1px 5px;font-size: 10px;font-weight: bold;margin-left: 10px;">[rewind]</span>
+ </div>
+ <div style="font-weight:bold;"><span wicket:id="whoPushed">[pusher]</span> <span wicket:id="whatPushed"></span><span wicket:id="refPushed"></span> <span wicket:id="repoPreposition"></span> <span wicket:id="repoPushed"></span></div>
+ <div style="padding: 10px 0px 5px;">
+ <table>
+ <tr wicket:id="commit">
+ <td style="vertical-align:top;"><span wicket:id="commitAuthor"></span></td>
+ <td style="vertical-align:top;"><span wicket:id="hashLink" style="padding-left: 5px;">[hash link]</span></td>
+ <td style="vertical-align:top;"><img wicket:id="commitIcon" /></td>
+ <td style="vertical-align:top;">
+ <span wicket:id="commitShortMessage">[commit short message]</span>
+ </td>
+ </tr>
+ </table>
+ <span class="link" wicket:id="compareLink"></span>
</div>
</td>
</tr>
</table>
</div>
+<div wicket:id="morePushes">[more...]</div>
</wicket:panel>
</body>
</html>
\ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/panels/PushesPanel.java b/src/main/java/com/gitblit/wicket/panels/PushesPanel.java index bab9c9e9..4b3cfb24 100644 --- a/src/main/java/com/gitblit/wicket/panels/PushesPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/PushesPanel.java @@ -1,5 +1,5 @@ /*
- * Copyright 2011 gitblit.com.
+ * 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.
@@ -16,14 +16,14 @@ package com.gitblit.wicket.panels;
import java.text.MessageFormat;
-import java.util.HashMap;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import org.apache.wicket.markup.html.basic.Label;
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.Repository;
import com.gitblit.Constants;
@@ -32,13 +32,15 @@ import com.gitblit.Keys; import com.gitblit.models.PushLogEntry;
import com.gitblit.models.RepositoryCommit;
import com.gitblit.models.RepositoryModel;
-import com.gitblit.models.UserModel;
import com.gitblit.utils.PushLogUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.pages.CommitPage;
-import com.gitblit.wicket.pages.GitSearchPage;
+import com.gitblit.wicket.pages.ComparePage;
+import com.gitblit.wicket.pages.PushesPage;
import com.gitblit.wicket.pages.SummaryPage;
+import com.gitblit.wicket.pages.TagPage;
+import com.gitblit.wicket.pages.TreePage;
import com.gitblit.wicket.pages.UserPage;
public class PushesPanel extends BasePanel {
@@ -52,79 +54,136 @@ public class PushesPanel extends BasePanel { public PushesPanel(String wicketId, final RepositoryModel model, Repository r, int limit, int pageOffset) {
super(wicketId);
boolean pageResults = limit <= 0;
- int itemsPerPage = GitBlit.getInteger(Keys.web.itemsPerPage, 50);
- if (itemsPerPage <= 1) {
- itemsPerPage = 50;
+ int pushesPerPage = GitBlit.getInteger(Keys.web.pushesPerPage, 10);
+ if (pushesPerPage <= 1) {
+ pushesPerPage = 10;
}
- final Map<String, String> usernameLookup = new HashMap<String, String>();
final int hashLen = GitBlit.getInteger(Keys.web.shortCommitIdLength, 6);
- List<PushLogEntry> entries = PushLogUtils.getPushLog(model.name, r, limit);
- // establish pusher identities
- for (PushLogEntry push : entries) {
- // handle push logs with email address instead of account name
- String username = push.user.username;
- if (push.user.username.indexOf('@') > -1) {
- // push username is an email address, reverse lookup for account
- if (!usernameLookup.containsKey(push.user.username)) {
- for (UserModel user : GitBlit.self().getAllUsers()) {
- if (push.user.username.equals(user.emailAddress)) {
- username = user.username;
- usernameLookup.put(push.user.username, username);
- break;
- }
- }
- } else {
- username = usernameLookup.get(push.user.username);
- }
- } else {
- // push username is an account name, lookup for email address
- if (!usernameLookup.containsKey(push.user.username)) {
- UserModel user = GitBlit.self().getUserModel(push.user.username);
- if (user != null) {
- push.user.emailAddress = user.emailAddress;
- usernameLookup.put(push.user.username, user.emailAddress);
- }
- } else {
- push.user.emailAddress = usernameLookup.get(push.user.username);
- }
- }
+ List<PushLogEntry> pushes;
+ if (pageResults) {
+ pushes = PushLogUtils.getPushLogByRef(model.name, r, pageOffset * pushesPerPage, pushesPerPage);
+ } else {
+ pushes = PushLogUtils.getPushLogByRef(model.name, r, limit);
}
- hasPushes = entries.size() > 0;
-
- ListDataProvider<PushLogEntry> dp = new ListDataProvider<PushLogEntry>(entries);
+ // inaccurate way to determine if there are more commits.
+ // works unless commits.size() represents the exact end.
+ hasMore = pushes.size() >= pushesPerPage;
+
+ hasPushes = pushes.size() > 0;
+
+ ListDataProvider<PushLogEntry> dp = new ListDataProvider<PushLogEntry>(pushes);
DataView<PushLogEntry> pushView = new DataView<PushLogEntry>("push", dp) {
private static final long serialVersionUID = 1L;
public void populateItem(final Item<PushLogEntry> pushItem) {
final PushLogEntry push = pushItem.getModelObject();
+ String fullRefName = push.getChangedRefs().get(0);
+ String shortRefName = fullRefName;
+ boolean isTag = false;
+ if (shortRefName.startsWith(org.eclipse.jgit.lib.Constants.R_HEADS)) {
+ shortRefName = shortRefName.substring(org.eclipse.jgit.lib.Constants.R_HEADS.length());
+ } else if (shortRefName.startsWith(org.eclipse.jgit.lib.Constants.R_TAGS)) {
+ shortRefName = shortRefName.substring(org.eclipse.jgit.lib.Constants.R_TAGS.length());
+ isTag = true;
+ }
-
+ pushItem.add(WicketUtils.createDateLabel("whenPushed", push.date, getTimeZone(), getTimeUtils()));
pushItem.add(new GravatarImage("whoAvatar", push.getCommitterIdent(), 40));
- pushItem.add(new LinkPanel("whoPushed", null, push.user.getDisplayName(),
+ if (push.user.username.equals(push.user.emailAddress) && push.user.emailAddress.indexOf('@') > -1) {
+ // username is an email address - 1.2.1 push log bug
+ pushItem.add(new Label("whoPushed", push.user.getDisplayName()));
+ } else {
+ // link to user acount page
+ pushItem.add(new LinkPanel("whoPushed", null, push.user.getDisplayName(),
UserPage.class, WicketUtils.newUsernameParameter(push.user.username)));
- pushItem.add(new Label("whatPushed",
- MessageFormat.format(push.getCommitCount() > 1 ? "pushed {0} commits to":"pushed 1 commit to", push.getCommitCount())));
+ }
+
+ String preposition = "gb.at";
+ boolean isDelete = false;
+ boolean isRewind = false;
+ String what;
+ switch(push.getChangeType(fullRefName)) {
+ case CREATE:
+ if (isTag) {
+ what = getString("gb.pushedNewTag");
+ } else {
+ what = getString("gb.pushedNewBranch");
+ }
+ preposition = "gb.to";
+ break;
+ case DELETE:
+ isDelete = true;
+ if (isTag) {
+ what = getString("gb.deletedTag");
+ } else {
+ what = getString("gb.deletedBranch");
+ }
+ preposition = "gb.from";
+ break;
+ case UPDATE_NONFASTFORWARD:
+ isRewind = true;
+ default:
+ what = MessageFormat.format(push.getCommitCount() > 1 ? getString("gb.pushedNCommitsTo") : getString("gb.pushedOneCommitTo") , push.getCommitCount());
+ break;
+ }
+ pushItem.add(new Label("whatPushed", what));
+
+ pushItem.add(new Label("refRewind", getString("gb.rewind")).setVisible(isRewind));
+
+ if (isDelete) {
+ // can't link to deleted ref
+ pushItem.add(new Label("refPushed", shortRefName));
+ } else if (isTag) {
+ // link to tag
+ pushItem.add(new LinkPanel("refPushed", null, shortRefName,
+ TagPage.class, WicketUtils.newObjectParameter(model.name, fullRefName)));
+ } else {
+ // link to tree
+ pushItem.add(new LinkPanel("refPushed", null, shortRefName,
+ TreePage.class, WicketUtils.newObjectParameter(model.name, fullRefName)));
+ }
+
+ // to/from/etc
+ pushItem.add(new Label("repoPreposition", getString(preposition)));
+
String repoName = StringUtils.stripDotGit(model.name);
- pushItem.add(new LinkPanel("wherePushed", null, repoName,
+ pushItem.add(new LinkPanel("repoPushed", null, repoName,
SummaryPage.class, WicketUtils.newRepositoryParameter(model.name)));
- pushItem.add(WicketUtils.createDateLabel("whenPushed", push.date, getTimeZone(), getTimeUtils()));
- ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(push.getCommits());
+ int maxCommitCount = 5;
+ List<RepositoryCommit> commits = push.getCommits();
+ if (commits.size() > maxCommitCount) {
+ commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
+ }
+
+ // compare link
+ String compareLinkText = null;
+ if ((push.getCommitCount() <= maxCommitCount) && (push.getCommitCount() > 1)) {
+ compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
+ } else if (push.getCommitCount() > maxCommitCount) {
+ int diff = push.getCommitCount() - maxCommitCount;
+ compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
+ }
+ if (StringUtils.isEmpty(compareLinkText)) {
+ pushItem.add(new Label("compareLink").setVisible(false));
+ } else {
+ String endRangeId = push.getNewId(fullRefName);
+ String startRangeId = push.getOldId(fullRefName);
+ pushItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(push.repository, startRangeId, endRangeId)));
+ }
+
+ ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {
private static final long serialVersionUID = 1L;
public void populateItem(final Item<RepositoryCommit> commitItem) {
final RepositoryCommit commit = commitItem.getModelObject();
- // author search link
- String author = commit.getAuthorIdent().getName();
- LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,
- GitSearchPage.class, WicketUtils.newSearchParameter(model.name,
- null, author, Constants.SearchType.AUTHOR));
- setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);
- commitItem.add(authorLink);
+ // author gravatar
+ commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent().getName(),
+ commit.getAuthorIdent().getEmailAddress(), null, 16, false, false));
// merge icon
if (commit.getParentCount() > 1) {
@@ -149,8 +208,6 @@ public class PushesPanel extends BasePanel { }
commitItem.add(shortlog);
- commitItem.add(new RefsPanel("commitRefs", commit.repository, commit.getRefs()));
-
// commit hash link
LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen),
CommitPage.class, WicketUtils.newObjectParameter(
@@ -158,12 +215,6 @@ public class PushesPanel extends BasePanel { WicketUtils.setCssClass(commitHash, "shortsha1");
WicketUtils.setHtmlTooltip(commitHash, commit.getName());
commitItem.add(commitHash);
-
-// item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, WicketUtils
-// .newObjectParameter(repositoryName, entry.getName())).setEnabled(entry
-// .getParentCount() > 0));
-// item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
-// .newObjectParameter(repositoryName, entry.getName())));
}
};
@@ -173,26 +224,26 @@ public class PushesPanel extends BasePanel { add(pushView);
// determine to show pager, more, or neither
-// if (limit <= 0) {
-// // no display limit
-// add(new Label("moreLogs", "").setVisible(false));
-// } else {
-// if (pageResults) {
-// // paging
-// add(new Label("moreLogs", "").setVisible(false));
-// } else {
-// // more
-// if (commits.size() == limit) {
-// // show more
-// add(new LinkPanel("moreLogs", "link", new StringResourceModel("gb.moreLogs",
-// this, null), LogPage.class,
-// WicketUtils.newRepositoryParameter(repositoryName)));
-// } else {
-// // no more
-// add(new Label("moreLogs", "").setVisible(false));
-// }
-// }
-// }
+ if (limit <= 0) {
+ // no display limit
+ add(new Label("morePushes").setVisible(false));
+ } else {
+ if (pageResults) {
+ // paging
+ add(new Label("morePushes").setVisible(false));
+ } else {
+ // more
+ if (pushes.size() == limit) {
+ // show more
+ add(new LinkPanel("morePushes", "link", new StringResourceModel("gb.morePushes",
+ this, null), PushesPage.class,
+ WicketUtils.newRepositoryParameter(model.name)));
+ } else {
+ // no more
+ add(new Label("morePushes").setVisible(false));
+ }
+ }
+ }
}
public boolean hasMore() {
|