import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.Date;\r
+import java.util.HashMap;\r
import java.util.HashSet;\r
import java.util.LinkedHashSet;\r
import java.util.List;\r
+import java.util.Map;\r
import java.util.Set;\r
\r
import org.eclipse.jgit.lib.Constants;\r
import org.eclipse.jgit.revwalk.RevCommit;\r
+import org.eclipse.jgit.transport.ReceiveCommand;\r
\r
/**\r
* Model class to represent a push into a repository.\r
public final UserModel user;\r
\r
private final Set<RepositoryCommit> commits;\r
+ \r
+ private final Map<String, ReceiveCommand.Type> refUpdates;\r
\r
/**\r
* Constructor for specified duration of push from start date.\r
this.date = date;\r
this.user = user;\r
this.commits = new LinkedHashSet<RepositoryCommit>();\r
+ this.refUpdates = new HashMap<String, ReceiveCommand.Type>();\r
+ }\r
+ \r
+ /**\r
+ * Tracks the change type for the specified ref.\r
+ * \r
+ * @param ref\r
+ * @param type\r
+ */\r
+ public void updateRef(String ref, ReceiveCommand.Type type) {\r
+ if (!refUpdates.containsKey(ref)) {\r
+ refUpdates.put(ref, type);\r
+ }\r
}\r
\r
/**\r
return null;\r
}\r
\r
+ /**\r
+ * Returns true if this push contains a non-fastforward ref update.\r
+ * \r
+ * @return true if this is a non-fastforward push\r
+ */\r
+ public boolean isNonFastForward() {\r
+ for (Map.Entry<String, ReceiveCommand.Type> entry : refUpdates.entrySet()) {\r
+ if (ReceiveCommand.Type.UPDATE_NONFASTFORWARD.equals(entry.getValue())) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+ \r
/**\r
* Returns the list of branches changed by the push.\r
* \r
*/\r
protected List<String> getChangedRefs(String baseRef) {\r
Set<String> refs = new HashSet<String>();\r
- for (RepositoryCommit commit : commits) {\r
- if (baseRef == null || commit.branch.startsWith(baseRef)) {\r
- refs.add(commit.branch);\r
+ for (String ref : refUpdates.keySet()) {\r
+ if (baseRef == null || ref.startsWith(baseRef)) {\r
+ refs.add(ref);\r
}\r
}\r
List<String> list = new ArrayList<String>(refs);\r
\r
@Override\r
public String toString() {\r
- return MessageFormat.format("{0,date,yyyy-MM-dd HH:mm}: {1} pushed {2,number,0} commit{3} to {4} ",\r
- date, user.getDisplayName(), commits.size(), commits.size() == 1 ? "":"s", repository);\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append(MessageFormat.format("{0,date,yyyy-MM-dd HH:mm}: {1} pushed {2,number,0} commit{3} to {4} ",\r
+ date, user.getDisplayName(), commits.size(), commits.size() == 1 ? "":"s", repository));\r
+ for (Map.Entry<String, ReceiveCommand.Type> entry : refUpdates.entrySet()) {\r
+ String ref = entry.getKey();\r
+ ReceiveCommand.Type type = entry.getValue();\r
+ sb.append("\n ").append(ref).append(' ').append(type.name()).append('\n');\r
+ for (RepositoryCommit commit : getCommits(ref)) {\r
+ sb.append(" ").append(commit.toString()).append('\n');\r
+ }\r
+ }\r
+ return sb.toString();\r
}\r
}\r
for (PathChangeModel change : changedRefs) {
switch (change.changeType) {
case DELETE:
+ log.updateRef(change.path, ReceiveCommand.Type.DELETE);
break;
case ADD:
- case MODIFY:
+ log.updateRef(change.path, ReceiveCommand.Type.CREATE);
+ 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];
List<RevCommit> pushedCommits = JGitUtils.getRevLog(repository, oldId, newId);
for (RevCommit pushedCommit : pushedCommits) {
log.addCommit(change.path, pushedCommit);
}
- break;
- default:
- break;
}
}
}