From: James Moger Date: Sun, 6 Jan 2013 16:02:52 +0000 (-0500) Subject: Improve pushlog api and model class X-Git-Tag: v1.2.1~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4027303c4df7bc44f02446178bfd9d4c180930c3;p=gitblit.git Improve pushlog api and model class --- diff --git a/src/com/gitblit/models/PushLogEntry.java b/src/com/gitblit/models/PushLogEntry.java index 32a7d007..f625c2a3 100644 --- a/src/com/gitblit/models/PushLogEntry.java +++ b/src/com/gitblit/models/PushLogEntry.java @@ -20,13 +20,16 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.transport.ReceiveCommand; /** * Model class to represent a push into a repository. @@ -44,6 +47,8 @@ public class PushLogEntry implements Serializable, Comparable { public final UserModel user; private final Set commits; + + private final Map refUpdates; /** * Constructor for specified duration of push from start date. @@ -60,6 +65,19 @@ public class PushLogEntry implements Serializable, Comparable { this.date = date; this.user = user; this.commits = new LinkedHashSet(); + this.refUpdates = new HashMap(); + } + + /** + * Tracks the change type for the specified ref. + * + * @param ref + * @param type + */ + public void updateRef(String ref, ReceiveCommand.Type type) { + if (!refUpdates.containsKey(ref)) { + refUpdates.put(ref, type); + } } /** @@ -79,6 +97,20 @@ public class PushLogEntry implements Serializable, Comparable { return null; } + /** + * Returns true if this push contains a non-fastforward ref update. + * + * @return true if this is a non-fastforward push + */ + public boolean isNonFastForward() { + for (Map.Entry entry : refUpdates.entrySet()) { + if (ReceiveCommand.Type.UPDATE_NONFASTFORWARD.equals(entry.getValue())) { + return true; + } + } + return false; + } + /** * Returns the list of branches changed by the push. * @@ -105,9 +137,9 @@ public class PushLogEntry implements Serializable, Comparable { */ protected List getChangedRefs(String baseRef) { Set refs = new HashSet(); - for (RepositoryCommit commit : commits) { - if (baseRef == null || commit.branch.startsWith(baseRef)) { - refs.add(commit.branch); + for (String ref : refUpdates.keySet()) { + if (baseRef == null || ref.startsWith(baseRef)) { + refs.add(ref); } } List list = new ArrayList(refs); @@ -160,7 +192,17 @@ public class PushLogEntry implements Serializable, Comparable { @Override public String toString() { - return MessageFormat.format("{0,date,yyyy-MM-dd HH:mm}: {1} pushed {2,number,0} commit{3} to {4} ", - date, user.getDisplayName(), commits.size(), commits.size() == 1 ? "":"s", repository); + StringBuilder sb = new StringBuilder(); + sb.append(MessageFormat.format("{0,date,yyyy-MM-dd HH:mm}: {1} pushed {2,number,0} commit{3} to {4} ", + date, user.getDisplayName(), commits.size(), commits.size() == 1 ? "":"s", repository)); + for (Map.Entry entry : refUpdates.entrySet()) { + String ref = entry.getKey(); + ReceiveCommand.Type type = entry.getValue(); + sb.append("\n ").append(ref).append(' ').append(type.name()).append('\n'); + for (RepositoryCommit commit : getCommits(ref)) { + sb.append(" ").append(commit.toString()).append('\n'); + } + } + return sb.toString(); } } diff --git a/src/com/gitblit/models/RepositoryCommit.java b/src/com/gitblit/models/RepositoryCommit.java index 3a98f61f..e68e8613 100644 --- a/src/com/gitblit/models/RepositoryCommit.java +++ b/src/com/gitblit/models/RepositoryCommit.java @@ -16,6 +16,7 @@ package com.gitblit.models; import java.io.Serializable; +import java.text.MessageFormat; import java.util.List; import org.eclipse.jgit.lib.PersonIdent; @@ -101,4 +102,11 @@ public class RepositoryCommit implements Serializable, Comparable pushedCommits = JGitUtils.getRevLog(repository, oldId, newId); for (RevCommit pushedCommit : pushedCommits) { log.addCommit(change.path, pushedCommit); } - break; - default: - break; } } }