summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-01-06 11:02:52 -0500
committerJames Moger <james.moger@gitblit.com>2013-01-06 11:02:52 -0500
commit4027303c4df7bc44f02446178bfd9d4c180930c3 (patch)
treeb93f47c6fcefdb8b4ff435bddea3b3729e65b4cc /src
parent9e186eedf1a09ca7ac4fbdea32b00e7e5331f7eb (diff)
downloadgitblit-4027303c4df7bc44f02446178bfd9d4c180930c3.tar.gz
gitblit-4027303c4df7bc44f02446178bfd9d4c180930c3.zip
Improve pushlog api and model class
Diffstat (limited to 'src')
-rw-r--r--src/com/gitblit/models/PushLogEntry.java52
-rw-r--r--src/com/gitblit/models/RepositoryCommit.java8
-rw-r--r--src/com/gitblit/utils/PushLogUtils.java8
3 files changed, 59 insertions, 9 deletions
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<PushLogEntry> {
public final UserModel user;
private final Set<RepositoryCommit> commits;
+
+ private final Map<String, ReceiveCommand.Type> refUpdates;
/**
* Constructor for specified duration of push from start date.
@@ -60,6 +65,19 @@ public class PushLogEntry implements Serializable, Comparable<PushLogEntry> {
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);
+ }
}
/**
@@ -80,6 +98,20 @@ public class PushLogEntry implements Serializable, Comparable<PushLogEntry> {
}
/**
+ * 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;
+ }
+
+ /**
* Returns the list of branches changed by the push.
*
* @return a list of branches
@@ -105,9 +137,9 @@ public class PushLogEntry implements Serializable, Comparable<PushLogEntry> {
*/
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);
@@ -160,7 +192,17 @@ public class PushLogEntry implements Serializable, Comparable<PushLogEntry> {
@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();
}
}
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<RepositoryComm
}
return 0;
}
+
+ @Override
+ public String toString() {
+ return MessageFormat.format("{0} {1} {2,date,yyyy-MM-dd HH:mm} {3} {4}",
+ getShortName(), branch, getCommitterIdent().getWhen(), getAuthorIdent().getName(),
+ getShortMessage());
+ }
} \ No newline at end of file
diff --git a/src/com/gitblit/utils/PushLogUtils.java b/src/com/gitblit/utils/PushLogUtils.java
index a3b1d66b..665533b3 100644
--- a/src/com/gitblit/utils/PushLogUtils.java
+++ b/src/com/gitblit/utils/PushLogUtils.java
@@ -321,20 +321,20 @@ public class PushLogUtils {
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;
}
}
}