summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/models
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-06-24 09:36:19 -0400
committerJames Moger <james.moger@gitblit.com>2013-06-24 09:36:19 -0400
commit79dd0bddbd939c85f002f3a33b95ae84d0bf38cb (patch)
treeb72b140a2af157ed878178ba7022c2eacae12a67 /src/main/java/com/gitblit/models
parent03232453be7624bc2fc8a942e8c280353606fe8b (diff)
downloadgitblit-79dd0bddbd939c85f002f3a33b95ae84d0bf38cb.tar.gz
gitblit-79dd0bddbd939c85f002f3a33b95ae84d0bf38cb.zip
Implemented commit cache for the dashboards, activity, and project pages
Diffstat (limited to 'src/main/java/com/gitblit/models')
-rw-r--r--src/main/java/com/gitblit/models/Activity.java26
-rw-r--r--src/main/java/com/gitblit/models/RefLogEntry.java19
-rw-r--r--src/main/java/com/gitblit/models/RepositoryCommit.java20
3 files changed, 57 insertions, 8 deletions
diff --git a/src/main/java/com/gitblit/models/Activity.java b/src/main/java/com/gitblit/models/Activity.java
index 547c348f..8af86d61 100644
--- a/src/main/java/com/gitblit/models/Activity.java
+++ b/src/main/java/com/gitblit/models/Activity.java
@@ -103,14 +103,28 @@ public class Activity implements Serializable, Comparable<Activity> {
*/
public RepositoryCommit addCommit(String repository, String branch, RevCommit commit) {
RepositoryCommit commitModel = new RepositoryCommit(repository, branch, commit);
+ return addCommit(commitModel);
+ }
+
+ /**
+ * Adds a commit to the activity object as long as the commit is not a
+ * duplicate.
+ *
+ * @param repository
+ * @param branch
+ * @param commit
+ * @return a RepositoryCommit, if one was added. Null if this is duplicate
+ * commit
+ */
+ public RepositoryCommit addCommit(RepositoryCommit commitModel) {
if (commits.add(commitModel)) {
- String author = StringUtils.removeNewlines(commit.getAuthorIdent().getName());
+ String author = StringUtils.removeNewlines(commitModel.getAuthorIdent().getName());
String authorName = author.toLowerCase();
- String authorEmail = StringUtils.removeNewlines(commit.getAuthorIdent().getEmailAddress()).toLowerCase();
- if (!repositoryMetrics.containsKey(repository)) {
- repositoryMetrics.put(repository, new Metric(repository));
+ String authorEmail = StringUtils.removeNewlines(commitModel.getAuthorIdent().getEmailAddress()).toLowerCase();
+ if (!repositoryMetrics.containsKey(commitModel.repository)) {
+ repositoryMetrics.put(commitModel.repository, new Metric(commitModel.repository));
}
- repositoryMetrics.get(repository).count++;
+ repositoryMetrics.get(commitModel.repository).count++;
if (!authorExclusions.contains(authorName) && !authorExclusions.contains(authorEmail)) {
if (!authorMetrics.containsKey(author)) {
@@ -122,7 +136,7 @@ public class Activity implements Serializable, Comparable<Activity> {
}
return null;
}
-
+
public int getCommitCount() {
return commits.size();
}
diff --git a/src/main/java/com/gitblit/models/RefLogEntry.java b/src/main/java/com/gitblit/models/RefLogEntry.java
index 54d17771..79e8a2ca 100644
--- a/src/main/java/com/gitblit/models/RefLogEntry.java
+++ b/src/main/java/com/gitblit/models/RefLogEntry.java
@@ -160,7 +160,24 @@ public class RefLogEntry implements Serializable, Comparable<RefLogEntry> {
}
return null;
}
-
+
+ /**
+ * Adds a commit to the push entry object as long as the commit is not a
+ * duplicate.
+ *
+ * @param branch
+ * @param commit
+ * @return a RepositoryCommit, if one was added. Null if this is duplicate
+ * commit
+ */
+ public RepositoryCommit addCommit(RepositoryCommit commit) {
+ if (commits.add(commit)) {
+ authorCount = -1;
+ return commit;
+ }
+ return null;
+ }
+
/**
* Adds a a list of repository commits. This is used to construct discrete
* ref push log entries
diff --git a/src/main/java/com/gitblit/models/RepositoryCommit.java b/src/main/java/com/gitblit/models/RepositoryCommit.java
index e68e8613..dd58b42b 100644
--- a/src/main/java/com/gitblit/models/RepositoryCommit.java
+++ b/src/main/java/com/gitblit/models/RepositoryCommit.java
@@ -17,8 +17,10 @@ package com.gitblit.models;
import java.io.Serializable;
import java.text.MessageFormat;
+import java.util.Date;
import java.util.List;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -54,6 +56,10 @@ public class RepositoryCommit implements Serializable, Comparable<RepositoryComm
return refs;
}
+ public ObjectId getId() {
+ return commit.getId();
+ }
+
public String getName() {
return commit.getName();
}
@@ -65,10 +71,18 @@ public class RepositoryCommit implements Serializable, Comparable<RepositoryComm
public String getShortMessage() {
return commit.getShortMessage();
}
+
+ public Date getCommitDate() {
+ return new Date(commit.getCommitTime() * 1000L);
+ }
public int getParentCount() {
return commit.getParentCount();
}
+
+ public RevCommit [] getParents() {
+ return commit.getParents();
+ }
public PersonIdent getAuthorIdent() {
return commit.getAuthorIdent();
@@ -77,7 +91,7 @@ public class RepositoryCommit implements Serializable, Comparable<RepositoryComm
public PersonIdent getCommitterIdent() {
return commit.getCommitterIdent();
}
-
+
@Override
public boolean equals(Object o) {
if (o instanceof RepositoryCommit) {
@@ -103,6 +117,10 @@ public class RepositoryCommit implements Serializable, Comparable<RepositoryComm
return 0;
}
+ public RepositoryCommit clone(String withRef) {
+ return new RepositoryCommit(repository, withRef, commit);
+ }
+
@Override
public String toString() {
return MessageFormat.format("{0} {1} {2,date,yyyy-MM-dd HH:mm} {3} {4}",