| | |
| | | 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.
|
| | |
| | |
|
| | | private final Set<RepositoryCommit> commits;
|
| | |
|
| | | private final Map<String, ReceiveCommand.Type> refUpdates;
|
| | |
|
| | | /**
|
| | | * Constructor for specified duration of push from start date.
|
| | | *
|
| | |
| | | this.date = date;
|
| | | this.user = user;
|
| | | this.commits = new LinkedHashSet<RepositoryCommit>();
|
| | | this.refUpdates = new HashMap<String, ReceiveCommand.Type>();
|
| | | }
|
| | | |
| | | /**
|
| | | * 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);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | return commitModel;
|
| | | }
|
| | | 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<String, ReceiveCommand.Type> entry : refUpdates.entrySet()) {
|
| | | if (ReceiveCommand.Type.UPDATE_NONFASTFORWARD.equals(entry.getValue())) {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | protected List<String> getChangedRefs(String baseRef) {
|
| | | Set<String> refs = new HashSet<String>();
|
| | | 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<String> list = new ArrayList<String>(refs);
|
| | |
| | |
|
| | | @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<String, ReceiveCommand.Type> 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();
|
| | | }
|
| | | }
|