The Unified and Autonomous Development Platform
Collect contribution data from commit information
robin shen5f64d6854d5a
diff --git a/core/src/main/java/com/gitplex/server/git/Contribution.java b/core/src/main/java/com/gitplex/server/git/Contribution.javanew file mode 100644index 0000000000..48c5aed02f--- /dev/null+++ b/core/src/main/java/com/gitplex/server/git/Contribution.java@@ -0,0 +1,35 @@+package com.gitplex.server.git;++import java.io.Serializable;++public class Contribution implements Serializable {++ private static final long serialVersionUID = 1L;++ public enum Type {COMMITS, ADDITIONS, DELETIONS};++ private final int commits;++ private final int additions;++ private final int deletions;++ public Contribution(int commits, int additions, int deletions) {+ this.commits = commits;+ this.additions = additions;+ this.deletions = deletions;+ }++ public int getCommits() {+ return commits;+ }++ public int getAdditions() {+ return additions;+ }++ public int getDeletions() {+ return deletions;+ }++}diff --git a/core/src/main/java/com/gitplex/server/git/Contributor.java b/core/src/main/java/com/gitplex/server/git/Contributor.javanew file mode 100644index 0000000000..ef3d1e9a75--- /dev/null+++ b/core/src/main/java/com/gitplex/server/git/Contributor.java@@ -0,0 +1,31 @@+package com.gitplex.server.git;++import java.io.Serializable;+import java.util.Map;++import org.eclipse.jgit.lib.PersonIdent;++import com.gitplex.server.util.Day;++public class Contributor implements Serializable {++ private static final long serialVersionUID = 1L;++ private final PersonIdent user;++ private final Map<Day, Contribution> dailyContributions;++ public Contributor(PersonIdent user, Map<Day, Contribution> dailyContributions) {+ this.user = user;+ this.dailyContributions = dailyContributions;+ }++ public PersonIdent getUser() {+ return user;+ }++ public Map<Day, Contribution> getDailyContributions() {+ return dailyContributions;+ }++}diff --git a/core/src/main/java/com/gitplex/server/git/DayAndCommits.java b/core/src/main/java/com/gitplex/server/git/DayAndCommits.javadeleted file mode 100644index ec1be4bbd6..0000000000--- a/core/src/main/java/com/gitplex/server/git/DayAndCommits.java+++ /dev/null@@ -1,33 +0,0 @@-package com.gitplex.server.git;--import java.io.Serializable;--import com.gitplex.server.util.Day;--public class DayAndCommits implements Serializable, Comparable<DayAndCommits> {-- private static final long serialVersionUID = 1L;-- private final Day day;-- private final int commits;-- public DayAndCommits(Day day, int commits) {- this.day = day;- this.commits = commits;- }-- public Day getDay() {- return day;- }-- public int getCommits() {- return commits;- }-- @Override- public int compareTo(DayAndCommits o) {- return day.compareTo(o.day);- }--}\ No newline at end of filediff --git a/core/src/main/java/com/gitplex/server/git/LineStats.java b/core/src/main/java/com/gitplex/server/git/LineStats.javanew file mode 100644index 0000000000..00d806670b--- /dev/null+++ b/core/src/main/java/com/gitplex/server/git/LineStats.java@@ -0,0 +1,73 @@+package com.gitplex.server.git;++import java.io.Serializable;+import java.util.ArrayList;+import java.util.Collections;+import java.util.Comparator;+import java.util.HashMap;+import java.util.List;+import java.util.Map;++import javax.annotation.Nullable;++import com.gitplex.server.util.Day;++public class LineStats implements Serializable {++ private static final long serialVersionUID = 1L;++ private final Map<Day, Map<String, Integer>> dailyLines;++ private transient List<String> sortedLanguages;++ public LineStats(Map<Day, Map<String, Integer>> dailyLines) {+ this.dailyLines = dailyLines;+ }++ public Map<Day, Map<String, Integer>> getDailyLines() {+ return dailyLines;+ }++ @Nullable+ public Day getFirstDay() {+ if (!dailyLines.isEmpty())+ return Collections.min(dailyLines.keySet());+ else+ return null;+ }++ @Nullable+ public Day getLastDay() {+ if (!dailyLines.isEmpty())+ return Collections.max(dailyLines.keySet());+ else+ return null;+ }++ public List<String> getSortedLanguages() {+ if (sortedLanguages == null) {+ Map<String, Integer> languageLines = new HashMap<>();+ for (Map<String, Integer> each: dailyLines.values()) {+ for (Map.Entry<String, Integer> entry: each.entrySet()) {+ Integer lines = languageLines.get(entry.getKey());+ if (lines != null)+ lines += entry.getValue();+ else+ lines = entry.getValue();+ languageLines.put(entry.getKey(), lines);+ }+ }+ sortedLanguages = new ArrayList<>(languageLines.keySet());+ Collections.sort(sortedLanguages, new Comparator<String>() {++ @Override+ public int compare(String o1, String o2) {+ return languageLines.get(o2) - languageLines.get(o1);+ }++ });+ }+ return sortedLanguages;+ }++}diff --git a/core/src/main/java/com/gitplex/server/git/UserContribution.java b/core/src/main/java/com/gitplex/server/git/UserContribution.javadeleted file mode 100644index f3fece50b4..0000000000--- a/core/src/main/java/com/gitplex/server/git/UserContribution.java+++ /dev/null@@ -1,29 +0,0 @@-package com.gitplex.server.git;--import java.io.Serializable;-import java.util.List;--import org.eclipse.jgit.lib.PersonIdent;--public class UserContribution implements Serializable {-- private static final long serialVersionUID = 1L;-- private final PersonIdent user;-- private final List<DayAndCommits> dayAndCommits;-- public UserContribution(PersonIdent user, List<DayAndCommits> dayAndCommits) {- this.user = user;- this.dayAndCommits = dayAndCommits;- }-- public PersonIdent getUser() {- return user;- }-- public List<DayAndCommits> getDayAndCommits() {- return dayAndCommits;- }--}diff --git a/core/src/main/java/com/gitplex/server/git/command/FileChange.java b/core/src/main/java/com/gitplex/server/git/command/FileChange.javaindex 03c714c1e6..b09a4fd649 100644--- a/core/src/main/java/com/gitplex/server/git/command/FileChange.java+++ b/core/src/main/java/com/gitplex/server/git/command/FileChange.java@@ -5,39 +5,43 @@ import java.io.Serializable;@SuppressWarnings("serial")public class FileChange implements Serializable {- public enum Action {ADD, MODIFY, DELETE, COPY, RENAME, TYPE}-private final String oldPath;- private final String newPath;+ private final String path;++ private final int additions;- private final Action action;+ private final int deletions;- public FileChange(Action action, String oldPath, String newPath) {- this.action = action;-+ public FileChange(String oldPath, String newPath, int additions, int deletions) {this.oldPath = oldPath;- this.newPath = newPath;+ this.path = newPath;+ this.additions = additions;+ this.deletions = deletions;}public String getOldPath() {return oldPath;}- public String getNewPath() {- return newPath;+ public String getPath() {+ return path;+ }++ public int getAdditions() {+ return additions;}- public Action getAction() {- return action;+ public int getDeletions() {+ return deletions;}@Overridepublic String toString() {- if (action == Action.COPY || action == Action.RENAME)- return action.name() + "\t" + oldPath + "->" + newPath;+ if (oldPath != null)+ return oldPath + "=>" + path;else- return action.name() + "\t" + newPath;+ return path;}}\ No newline at end of filediff --git a/core/src/main/java/com/gitplex/server/git/command/LogCommand.java b/core/src/main/java/com/gitplex/server/git/command/LogCommand.javaindex 49d8a33842..299280125b 100644--- a/core/src/main/java/com/gitplex/server/git/command/LogCommand.java+++ b/core/src/main/java/com/gitplex/server/git/command/LogCommand.java@@ -3,10 +3,9 @@ package com.gitplex.server.git.command;import java.io.File;import java.util.ArrayList;import java.util.List;-import java.util.concurrent.atomic.AtomicBoolean;+import java.util.StringTokenizer;import java.util.concurrent.atomic.AtomicReference;-import org.apache.commons.lang3.StringUtils;import org.eclipse.jgit.util.QuotedString;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -14,6 +13,8 @@ import org.slf4j.LoggerFactory;import com.gitplex.server.git.GitUtils;import com.gitplex.utils.command.Commandline;import com.gitplex.utils.command.LineConsumer;+import com.google.common.base.Preconditions;+import com.google.common.base.Splitter;public abstract class LogCommand extends GitCommand<Void> {@@ -33,76 +34,50 @@ public abstract class LogCommand extends GitCommand<Void> {this.revisions = revisions;return this;}-+@Overridepublic Void call() {+ Preconditions.checkArgument(!revisions.isEmpty(), "Log revisions have to be specified");+Commandline cmd = cmd();- cmd.addArgs("-c", "diff.renameLimit=1000", "log",- "--format=*** commit_begin ***%nhash:%H%nauthor:%aN%nauthorEmail:%aE%n"- + "committerEmail:%cE%ncommitter:%cN%nparents:%P%ncommitterDate:%cd %n"- + "authorDate:%ad %n",- "--date=raw");++ String format = ""+ + "hash:%H %n"+ + "author:%aN %n"+ + "authorEmail:%aE %n"+ + "committer:%cN %n"+ + "committerEmail:%cE %n"+ + "parents:%P %n"+ + "committerDate:%cd %n"+ + "authorDate:%ad %n";++ cmd.addArgs("-c", "diff.renameLimit=1000", "log", "--format=" + format, "--date=raw", "--numstat",+ "--find-renames");- if (!revisions.isEmpty()) {- for (String revision: revisions)- cmd.addArgs(revision);- } else {- cmd.addArgs("--branches");- }-- cmd.addArgs("--name-status", "--find-renames");+ for (String revision: revisions)+ cmd.addArgs(revision);AtomicReference<LogCommit.Builder> commitBuilderRef = new AtomicReference<>();- AtomicBoolean inFileChangesBlock = new AtomicBoolean();cmd.execute(new LineConsumer() {@Overridepublic void consume(String line) {- if (line.equals("*** commit_begin ***")) {+ if (line.startsWith("hash:")) {if (commitBuilderRef.get() != null)LogCommand.this.consume(commitBuilderRef.get().build());commitBuilderRef.set(new LogCommit.Builder());- inFileChangesBlock.set(false);- } else if (inFileChangesBlock.get()) {- FileChange.Action action = null;- if (line.startsWith("A"))- action = FileChange.Action.ADD;- else if (line.startsWith("M"))- action = FileChange.Action.MODIFY;- else if (line.startsWith("D"))- action = FileChange.Action.DELETE;- else if (line.startsWith("C"))- action = FileChange.Action.COPY;- else if (line.startsWith("R"))- action = FileChange.Action.RENAME;- else if (line.startsWith("T"))- action = FileChange.Action.TYPE;-- if (action != null) {- String path = StringUtils.substringAfter(line, "\t");- String path1;- String path2;- if (path.indexOf('\t') != -1) {- path1 = QuotedString.GIT_PATH.dequote(StringUtils.substringBefore(path, "\t"));- path2 = QuotedString.GIT_PATH.dequote(StringUtils.substringAfter(path, "\t"));- } else {- path1 = path2 = QuotedString.GIT_PATH.dequote(path);- }- FileChange fileChange = new FileChange(action, path1, path2);- commitBuilderRef.get().fileChanges.add(fileChange);- }- } else if (line.startsWith("hash:")) {- commitBuilderRef.get().hash = line.substring("hash:".length());+ commitBuilderRef.get().hash = line.substring("hash:".length()).trim();} else if (line.startsWith("author:")) {- commitBuilderRef.get().authorName = line.substring("author:".length());+ commitBuilderRef.get().authorName = line.substring("author:".length()).trim();} else if (line.startsWith("committer:")) {- commitBuilderRef.get().committerName = line.substring("committer:".length());+ commitBuilderRef.get().committerName = line.substring("committer:".length()).trim();} else if (line.startsWith("authorEmail:")) {- commitBuilderRef.get().authorEmail = line.substring("authorEmail:".length());+ commitBuilderRef.get().authorEmail = line.substring("authorEmail:".length()).trim();} else if (line.startsWith("committerEmail:")) {- commitBuilderRef.get().committerEmail = line.substring("committerEmail:".length());+ commitBuilderRef.get().committerEmail = line.substring("committerEmail:".length()).trim();} else if (line.startsWith("parents:")) {- for (String each: StringUtils.split(line.substring("parents:".length()), " "))+ Splitter splitter = Splitter.on(" ").omitEmptyStrings().trimResults();+ for (String each: splitter.split(line.substring("parents:".length())))commitBuilderRef.get().parentHashes.add(each);} else if (line.startsWith("committerDate:")) {commitBuilderRef.get().committerDate =@@ -110,7 +85,38 @@ public abstract class LogCommand extends GitCommand<Void> {} else if (line.startsWith("authorDate:")) {commitBuilderRef.get().authorDate =GitUtils.parseRawDate(line.substring("authorDate:".length()).trim());- inFileChangesBlock.set(true);+ } else if (line.trim().length() != 0) {+ StringTokenizer tokenizer = new StringTokenizer(line, "\t");+ String additionsToken = tokenizer.nextToken();+ int additions = additionsToken.equals("-")?0:Integer.parseInt(additionsToken);+ String deletionsToken = tokenizer.nextToken();+ int deletions = deletionsToken.equals("-")?0:Integer.parseInt(deletionsToken);++ String path = tokenizer.nextToken();+ int renameSignIndex = path.indexOf(" => ");+ if (renameSignIndex != -1) {+ int leftBraceIndex = path.indexOf("{");+ int rightBraceIndex = path.indexOf("}");+ if (leftBraceIndex != -1 && rightBraceIndex != -1 && leftBraceIndex<renameSignIndex+ && rightBraceIndex>renameSignIndex) {+ String leftCommon = path.substring(0, leftBraceIndex);+ String rightCommon = path.substring(rightBraceIndex+1);+ String oldPath = leftCommon + path.substring(leftBraceIndex+1, renameSignIndex)+ + rightCommon;+ String newPath = leftCommon + path.substring(renameSignIndex+4, rightBraceIndex)+ + rightCommon;+ commitBuilderRef.get().fileChanges.add(+ new FileChange(oldPath, newPath, additions, deletions));+ } else {+ String oldPath = QuotedString.GIT_PATH.dequote(path.substring(0, renameSignIndex));+ String newPath = QuotedString.GIT_PATH.dequote(path.substring(renameSignIndex+4));+ commitBuilderRef.get().fileChanges.add(+ new FileChange(oldPath, newPath, additions, deletions));+ }+ } else {+ path = QuotedString.GIT_PATH.dequote(path);+ commitBuilderRef.get().fileChanges.add(new FileChange(null, path, additions, deletions));+ }}}diff --git a/core/src/main/java/com/gitplex/server/git/command/LogCommit.java b/core/src/main/java/com/gitplex/server/git/command/LogCommit.javaindex 36d28c7ffe..6b75abe6e1 100644--- a/core/src/main/java/com/gitplex/server/git/command/LogCommit.java+++ b/core/src/main/java/com/gitplex/server/git/command/LogCommit.java@@ -19,6 +19,8 @@ public class LogCommit implements Serializable {private static final long serialVersionUID = 1L;private final String hash;++ private final Date commitDate;private final PersonIdent committer;@@ -27,10 +29,12 @@ public class LogCommit implements Serializable {private final List<String> parentHashes;private final List<FileChange> fileChanges;-- public LogCommit(String hash, @Nullable PersonIdent committer, @Nullable PersonIdent author,- List<String> parentHashes, List<FileChange> fileChanges) {++ public LogCommit(String hash, @Nullable Date commitDate, @Nullable PersonIdent committer,+ @Nullable PersonIdent author, List<String> parentHashes, List<FileChange> fileChanges,+ int addedLines, int deletedLines) {this.hash = hash;+ this.commitDate = commitDate;this.committer = committer;this.author = author;this.parentHashes = new ArrayList<>(parentHashes);@@ -48,8 +52,8 @@ public class LogCommit implements Serializable {public Collection<String> getChangedFiles() {Collection<String> changedFiles = new HashSet<>();for (FileChange change: getFileChanges()) {- if (change.getNewPath() != null)- changedFiles.add(change.getNewPath());+ if (change.getPath() != null)+ changedFiles.add(change.getPath());if (change.getOldPath() != null)changedFiles.add(change.getOldPath());}@@ -70,6 +74,24 @@ public class LogCommit implements Serializable {return author;}+ public Date getCommitDate() {+ return commitDate;+ }++ public int getAdditions() {+ int additions = 0;+ for (FileChange change: fileChanges)+ additions += change.getAdditions();+ return additions;+ }++ public int getDeletions() {+ int deletions = 0;+ for (FileChange change: fileChanges)+ deletions += change.getDeletions();+ return deletions;+ }+public static class Builder {public String hash;@@ -89,25 +111,26 @@ public class LogCommit implements Serializable {public List<String> parentHashes = new ArrayList<>();public List<FileChange> fileChanges = new ArrayList<>();++ public int addedLines;++ public int deletedLines;public LogCommit build() {PersonIdent committer;- if ((StringUtils.isNotBlank(committerName) || StringUtils.isNotBlank(committerEmail))- && committerDate != null) {+ if (StringUtils.isNotBlank(committerName) || StringUtils.isNotBlank(committerEmail))committer = GitUtils.newPersonIdent(committerName, committerEmail, committerDate);- } else {+ elsecommitter = null;- }PersonIdent author;- if ((StringUtils.isNotBlank(authorName) || StringUtils.isNotBlank(authorEmail))- && authorDate != null) {+ if (StringUtils.isNotBlank(authorName) || StringUtils.isNotBlank(authorEmail))author = GitUtils.newPersonIdent(authorName, authorEmail, authorDate);- } else {+ elseauthor = null;- }- return new LogCommit(hash, committer, author, parentHashes, fileChanges);+ return new LogCommit(hash, committerDate, committer, author, parentHashes, fileChanges,+ addedLines, deletedLines);}}diff --git a/core/src/main/java/com/gitplex/server/manager/CommitInfoManager.java b/core/src/main/java/com/gitplex/server/manager/CommitInfoManager.javaindex 93baef9107..3f0d3fe72a 100644--- a/core/src/main/java/com/gitplex/server/manager/CommitInfoManager.java+++ b/core/src/main/java/com/gitplex/server/manager/CommitInfoManager.java@@ -2,13 +2,14 @@ package com.gitplex.server.manager;import java.util.Collection;import java.util.List;+import java.util.Map;import java.util.Set;import org.eclipse.jgit.lib.ObjectId;-import com.gitplex.server.git.DayAndCommits;+import com.gitplex.server.git.Contribution;+import com.gitplex.server.git.Contributor;import com.gitplex.server.git.NameAndEmail;-import com.gitplex.server.git.UserContribution;import com.gitplex.server.model.Project;import com.gitplex.server.util.Day;import com.gitplex.server.util.facade.ProjectFacade;@@ -18,7 +19,7 @@ public interface CommitInfoManager {List<String> getFiles(Project project);- int getModifications(ProjectFacade project, UserFacade user, String path);+ int getEdits(ProjectFacade project, UserFacade user, String path);int getCommitCount(Project project);@@ -54,8 +55,33 @@ public interface CommitInfoManager {Collection<String> getHistoryPaths(Project project, String path);- List<DayAndCommits> getOverallContributions(Project project);+ /**+ * Get list of contributions, ordered by day+ *+ * @param project+ * project to get daily commits for+ * @return+ * list of contributions, ordered by day+ */+ Map<Day, Contribution> getOverallContributions(Project project);- List<UserContribution> getUserContributions(Project project, int top, Day fromDay, Day toDay);+ /**+ * Get list of top contributors+ *+ * @param project+ * project to get top contributors for+ * @param top+ * number of top contributors to get+ * @param orderBy+ * type of contribution to order by+ * @param fromDay+ * from day+ * @param toDay+ * to day+ * @return+ * list of top user contributors, reversely ordered by number of contributions+ */+ List<Contributor> getTopContributors(Project project, int top, Contribution.Type orderBy,+ Day fromDay, Day toDay);}\ No newline at end of filediff --git a/core/src/main/java/com/gitplex/server/manager/impl/AbstractEnvironmentManager.java b/core/src/main/java/com/gitplex/server/manager/impl/AbstractEnvironmentManager.javaindex f0357d8880..fd6728e1b3 100644--- a/core/src/main/java/com/gitplex/server/manager/impl/AbstractEnvironmentManager.java+++ b/core/src/main/java/com/gitplex/server/manager/impl/AbstractEnvironmentManager.java@@ -108,15 +108,17 @@ public abstract class AbstractEnvironmentManager {}}- protected byte[] getBytes(@Nullable ByteIterable byteIterable) {- if (byteIterable != null)- return Arrays.copyOf(byteIterable.getBytesUnsafe(), byteIterable.getLength());+ @Nullable+ protected byte[] readBytes(Store store, Transaction txn, ByteIterable key) {+ ByteIterable value = store.get(txn, key);+ if (value != null)+ return Arrays.copyOf(value.getBytesUnsafe(), value.getLength());elsereturn null;}protected int readInt(Store store, Transaction txn, ByteIterable key, int defaultValue) {- byte[] bytes = getBytes(store.get(txn, key));+ byte[] bytes = readBytes(store, txn, key);if (bytes != null)return ByteBuffer.wrap(bytes).getInt();else@@ -129,7 +131,7 @@ public abstract class AbstractEnvironmentManager {}protected long readLong(Store store, Transaction txn, ByteIterable key, long defaultValue) {- byte[] bytes = getBytes(store.get(txn, key));+ byte[] bytes = readBytes(store, txn, key);if (bytes != null)return ByteBuffer.wrap(bytes).getLong();elsediff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultCodeCommentRelationInfoManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultCodeCommentRelationInfoManager.javaindex 2c2a1ad343..29b29bf6d2 100644--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultCodeCommentRelationInfoManager.java+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultCodeCommentRelationInfoManager.java@@ -153,7 +153,7 @@ public class DefaultCodeCommentRelationInfoManager extends AbstractEnvironmentMa@Overridepublic String compute(Transaction txn) {- byte[] value = getBytes(defaultStore.get(txn, LAST_PULL_REQUEST_UPDATE_KEY));+ byte[] value = readBytes(defaultStore, txn, LAST_PULL_REQUEST_UPDATE_KEY);return value!=null?new String(value):null;}@@ -214,7 +214,7 @@ public class DefaultCodeCommentRelationInfoManager extends AbstractEnvironmentMa@Overridepublic String compute(final Transaction txn) {- byte[] value = getBytes(defaultStore.get(txn, LAST_CODE_COMMENT_KEY));+ byte[] value = readBytes(defaultStore, txn, LAST_CODE_COMMENT_KEY);return value!=null?new String(value):null;}@@ -280,7 +280,7 @@ public class DefaultCodeCommentRelationInfoManager extends AbstractEnvironmentMa@SuppressWarnings("unchecked")private Set<String> getPullRequestUUIDs(Store store, Transaction txn, ByteIterable commitKey) {- byte[] valueBytes = getBytes(store.get(txn, commitKey));+ byte[] valueBytes = readBytes(store, txn, commitKey);if (valueBytes != null) {return (Set<String>) SerializationUtils.deserialize(valueBytes);} else {@@ -290,7 +290,7 @@ public class DefaultCodeCommentRelationInfoManager extends AbstractEnvironmentMa@SuppressWarnings("unchecked")private Map<String, ComparingInfo> getCodeCommentComparingInfos(Store store, Transaction txn, ByteIterable commitKey) {- byte[] valueBytes = getBytes(store.get(txn, commitKey));+ byte[] valueBytes = readBytes(store, txn, commitKey);if (valueBytes != null) {return (Map<String, ComparingInfo>) SerializationUtils.deserialize(valueBytes);} else {diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultCommitInfoManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultCommitInfoManager.javaindex c70fd595e3..8846105e44 100644--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultCommitInfoManager.java+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultCommitInfoManager.java@@ -10,7 +10,6 @@ import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;-import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Optional;@@ -27,6 +26,7 @@ import javax.inject.Singleton;import org.apache.commons.lang3.SerializationUtils;import org.eclipse.jgit.lib.Constants;import org.eclipse.jgit.lib.ObjectId;+import org.eclipse.jgit.lib.PersonIdent;import org.eclipse.jgit.lib.Ref;import org.eclipse.jgit.lib.Repository;import org.eclipse.jgit.revwalk.RevCommit;@@ -38,10 +38,10 @@ import org.slf4j.LoggerFactory;import com.gitplex.launcher.loader.Listen;import com.gitplex.server.event.RefUpdated;import com.gitplex.server.event.lifecycle.SystemStarted;-import com.gitplex.server.git.DayAndCommits;+import com.gitplex.server.git.Contribution;+import com.gitplex.server.git.Contributor;import com.gitplex.server.git.GitUtils;import com.gitplex.server.git.NameAndEmail;-import com.gitplex.server.git.UserContribution;import com.gitplex.server.git.command.FileChange;import com.gitplex.server.git.command.LogCommand;import com.gitplex.server.git.command.LogCommit;@@ -60,7 +60,6 @@ import com.gitplex.server.util.Day;import com.gitplex.server.util.facade.ProjectFacade;import com.gitplex.server.util.facade.UserFacade;import com.gitplex.utils.FileUtils;-import com.gitplex.utils.Pair;import com.gitplex.utils.PathUtils;import com.gitplex.utils.StringUtils;import com.gitplex.utils.concurrent.Prioritized;@@ -99,7 +98,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemeprivate static final String COMMITS_STORE = "commits";- private static final String MODIFICATIONS_STORE = "modifications";+ private static final String EDITS_STORE = "edits";private static final String HISTORY_PATHS_STORE = "historyPaths";@@ -123,6 +122,8 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemeprivate static final ByteIterable FILES_KEY = new StringByteIterable("files");+ private static final ByteIterable OVERALL_CONTRIBUTIONS_KEY = new StringByteIterable("overallContributions");+private static final ByteIterable COMMIT_COUNT_KEY = new StringByteIterable("commitCount");private static final int PRIORITY = 100;@@ -167,7 +168,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager impleme@Overridepublic ObjectId compute(Transaction txn) {- byte[] bytes = getBytes(defaultStore.get(txn, LAST_COMMIT_KEY));+ byte[] bytes = readBytes(defaultStore, txn, LAST_COMMIT_KEY);return bytes!=null? ObjectId.fromRaw(bytes): null;}@@ -193,7 +194,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemedoCollect(project, commitId, false);} else {Store commitsStore = getStore(env, COMMITS_STORE);- Store modificationsStore = getStore(env, MODIFICATIONS_STORE);+ Store editsStore = getStore(env, EDITS_STORE);Store historyPathsStore = getStore(env, HISTORY_PATHS_STORE);Store pathToIndexStore = getStore(env, PATH_TO_INDEX_STORE);Store indexToPathStore = getStore(env, INDEX_TO_PATH_STORE);@@ -207,7 +208,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager impleme@Overridepublic void execute(Transaction txn) {try {- byte[] bytes = getBytes(defaultStore.get(txn, LAST_COMMIT_KEY));+ byte[] bytes = readBytes(defaultStore, txn, LAST_COMMIT_KEY);ObjectId lastCommitId;if (bytes != null) {@@ -226,23 +227,25 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemenextIndex.user = readInt(defaultStore, txn, NEXT_USER_INDEX_KEY, 0);nextIndex.path = readInt(defaultStore, txn, NEXT_PATH_INDEX_KEY, 0);- Map<Integer, Map<Integer, Integer>> dailyCommitsCache = new HashMap<>();- Map<Long, Integer> modificationsCache = new HashMap<>();+ Map<Integer, Map<Integer, Contribution>> dailyContributionsCache = new HashMap<>();+ Map<Integer, Contribution> overallContributions =+ deserializeContributions(readBytes(defaultStore, txn, OVERALL_CONTRIBUTIONS_KEY));+ Map<Long, Integer> editsCache = new HashMap<>();Set<NameAndEmail> users;- bytes = getBytes(defaultStore.get(txn, USERS_KEY));+ bytes = readBytes(defaultStore, txn, USERS_KEY);if (bytes != null)users = (Set<NameAndEmail>) SerializationUtils.deserialize(bytes);elseusers = new HashSet<>();Map<String, Long> files;- bytes = getBytes(defaultStore.get(txn, FILES_KEY));+ bytes = readBytes(defaultStore, txn, FILES_KEY);if (bytes != null)files = (Map<String, Long>) SerializationUtils.deserialize(bytes);elsefiles = new HashMap<>();-+/** Use a synchronous queue to achieve below purpose:* 1. Add commit to Xodus transactional store in the same thread opening the transaction@@ -292,7 +295,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemebyte[] keyBytes = new byte[20];ObjectId.fromString(commit.getHash()).copyRawTo(keyBytes, 0);ByteIterable key = new ArrayByteIterable(keyBytes);- byte[] valueBytes = getBytes(commitsStore.get(txn, key));+ byte[] valueBytes = readBytes(commitsStore, txn, key);if (valueBytes == null || valueBytes.length % 20 == 0) {/*@@ -317,7 +320,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemekeyBytes = new byte[20];ObjectId.fromString(parentHash).copyRawTo(keyBytes, 0);key = new ArrayByteIterable(keyBytes);- valueBytes = getBytes(commitsStore.get(txn, key));+ valueBytes = readBytes(commitsStore, txn, key);if (valueBytes != null) {newValueBytes = new byte[valueBytes.length+20];System.arraycopy(valueBytes, 0, newValueBytes, 0, valueBytes.length);@@ -328,11 +331,13 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemecommitsStore.put(txn, key, new ArrayByteIterable(newValueBytes));}- if (commit.getCommitter() != null) {- users.add(new NameAndEmail(commit.getCommitter()));+ if (commit.getCommitDate() != null) {for (String file: commit.getChangedFiles())- files.put(file, commit.getCommitter().getWhen().getTime());+ files.put(file, commit.getCommitDate().getTime());}++ if (commit.getCommitter() != null)+ users.add(new NameAndEmail(commit.getCommitter()));if (commit.getAuthor() != null) {NameAndEmail nameAndEmail = new NameAndEmail(commit.getAuthor());@@ -350,42 +355,48 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemenew ArrayByteIterable(SerializationUtils.serialize(nameAndEmail)));}- for (String changedPath: commit.getChangedFiles()) {+ for (FileChange change: commit.getFileChanges()) {+ String path = change.getPath();int pathIndex = getPathIndex(pathToIndexStore, indexToPathStore, txn,- nextIndex, changedPath);- increaseModifications(modificationsStore, txn, modificationsCache,- userIndex, pathIndex);- while (changedPath.contains("/")) {- changedPath = StringUtils.substringBeforeLast(changedPath, "/");+ nextIndex, path);+ int edits = change.getAdditions() + change.getDeletions();+ updateEdits(editsStore, txn, editsCache,+ userIndex, pathIndex, edits);+ while (path.contains("/")) {+ path = StringUtils.substringBeforeLast(path, "/");pathIndex = getPathIndex(pathToIndexStore, indexToPathStore, txn,- nextIndex, changedPath);- increaseModifications(modificationsStore, txn, modificationsCache,- userIndex, pathIndex);+ nextIndex, path);+ updateEdits(editsStore, txn, editsCache,+ userIndex, pathIndex, edits);}pathIndex = getPathIndex(pathToIndexStore, indexToPathStore, txn,nextIndex, "");- increaseModifications(modificationsStore, txn, modificationsCache,- userIndex, pathIndex);+ updateEdits(editsStore, txn, editsCache, userIndex, pathIndex, edits);}- if (commit.getCommitter() != null && commit.getParentHashes().size() <= 1) {- int day = new Day(commit.getCommitter().getWhen()).getValue();- increaseDailyCommits(dailyContributionsStore, txn,- dailyCommitsCache, userIndex, day);- increaseDailyCommits(dailyContributionsStore, txn,- dailyCommitsCache, -1, day);+ if (commit.getCommitDate() != null && commit.getParentHashes().size() <= 1) {+ int dayValue = new Day(commit.getCommitDate()).getValue();+ Map<Integer, Contribution> contributionsOnDay =+ dailyContributionsCache.get(dayValue);+ if (contributionsOnDay == null) {+ contributionsOnDay = deserializeContributions(readBytes(+ dailyContributionsStore, txn, new IntByteIterable(dayValue)));+ dailyContributionsCache.put(dayValue, contributionsOnDay);+ }+ updateContribution(contributionsOnDay, userIndex, commit);++ updateContribution(overallContributions, dayValue, commit);}}}for (FileChange change: commit.getFileChanges()) {- if (change.getAction() == FileChange.Action.COPY- || change.getAction() == FileChange.Action.RENAME) {+ if (change.getOldPath() != null) {int pathIndex = getPathIndex(pathToIndexStore, indexToPathStore, txn,- nextIndex, change.getNewPath());+ nextIndex, change.getPath());ByteIterable pathKey = new IntByteIterable(pathIndex);Set<Integer> historyPathIndexes = new HashSet<>();- byte[] bytesOfHistoryPaths = getBytes(historyPathsStore.get(txn, pathKey));+ byte[] bytesOfHistoryPaths = readBytes(historyPathsStore, txn, pathKey);if (bytesOfHistoryPaths == null) {bytesOfHistoryPaths = new byte[0];int pos = 0;@@ -414,6 +425,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager impleme}}}+}commitOptional = queue.take();}@@ -440,27 +452,16 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemedefaultStore.put(txn, FILES_KEY, new ArrayByteIterable(bytes));filesCache.remove(project.getId());- for (Map.Entry<Integer, Map<Integer, Integer>> dailyCommitsEntry: dailyCommitsCache.entrySet()) {- Integer userIndex = dailyCommitsEntry.getKey();- Map<Integer, Integer> dailyCommitsOfUser = dailyCommitsEntry.getValue();- byte[] bytesOfDailyCommitsOfUser = new byte[dailyCommitsOfUser.size()*Integer.BYTES*2];- int pos = 0;- for (Map.Entry<Integer, Integer> dailyCommitsOfUserEntry: dailyCommitsOfUser.entrySet()) {- byte[] keyBytes = ByteBuffer.allocate(Integer.BYTES)- .putInt(dailyCommitsOfUserEntry.getKey()).array();- System.arraycopy(keyBytes, 0, bytesOfDailyCommitsOfUser, pos, Integer.BYTES);- pos += Integer.BYTES;- byte[] valueBytes = ByteBuffer.allocate(Integer.BYTES)- .putInt(dailyCommitsOfUserEntry.getValue()).array();- System.arraycopy(valueBytes, 0, bytesOfDailyCommitsOfUser, pos, Integer.BYTES);- pos += Integer.BYTES;- }- dailyContributionsStore.put(txn, new IntByteIterable(userIndex),- new ArrayByteIterable(bytesOfDailyCommitsOfUser));+ for (Map.Entry<Integer, Map<Integer, Contribution>> entry: dailyContributionsCache.entrySet()) {+ byte[] bytesOfContributionsOnDay = serializeContributions(entry.getValue());+ dailyContributionsStore.put(txn, new IntByteIterable(entry.getKey()),+ new ArrayByteIterable(bytesOfContributionsOnDay));}+ defaultStore.put(txn, OVERALL_CONTRIBUTIONS_KEY,+ new ArrayByteIterable(serializeContributions(overallContributions)));- for (Map.Entry<Long, Integer> entry: modificationsCache.entrySet())- writeInt(modificationsStore, txn, new LongByteIterable(entry.getKey()), entry.getValue());+ for (Map.Entry<Long, Integer> entry: editsCache.entrySet())+ writeInt(editsStore, txn, new LongByteIterable(entry.getKey()), entry.getValue());bytes = new byte[20];commitId.copyRawTo(bytes, 0);@@ -474,6 +475,19 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager impleme}}+ private void updateContribution(Map<Integer, Contribution> contributions, int key, LogCommit commit) {+ Contribution contribution = contributions.get(key);+ if (contribution != null) {+ contribution = new Contribution(+ contribution.getCommits()+1,+ contribution.getAdditions()+commit.getAdditions(),+ contribution.getDeletions()+commit.getDeletions());+ } else {+ contribution = new Contribution(1, commit.getAdditions(), commit.getDeletions());+ }+ contributions.put(key, contribution);+ }+private int getPathIndex(Store pathToIndexStore, Store indexToPathStore, Transaction txn,NextIndex nextIndex, String path) {StringByteIterable pathKey = new StringByteIterable(path);@@ -486,15 +500,15 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemereturn pathIndex;}- private void increaseModifications(Store modificationsStore, Transaction txn,- Map<Long, Integer> modificationsCache, int userIndex, int pathIndex) {- long modificationsKey = (userIndex<<32)|pathIndex;+ private void updateEdits(Store store, Transaction txn,+ Map<Long, Integer> editsCache, int userIndex, int pathIndex, int edits) {+ long editsKey = (userIndex<<32)|pathIndex;- Integer modificationsOfPathByUser = modificationsCache.get(modificationsKey);- if (modificationsOfPathByUser == null)- modificationsOfPathByUser = readInt(modificationsStore, txn, new LongByteIterable(modificationsKey), 0);- modificationsOfPathByUser++;- modificationsCache.put(modificationsKey, modificationsOfPathByUser);+ Integer editsOfPathByUser = editsCache.get(editsKey);+ if (editsOfPathByUser == null)+ editsOfPathByUser = readInt(store, txn, new LongByteIterable(editsKey), 0);+ editsOfPathByUser += edits;+ editsCache.put(editsKey, editsOfPathByUser);}@Override@@ -509,7 +523,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager impleme@SuppressWarnings("unchecked")@Overridepublic List<NameAndEmail> compute(Transaction txn) {- byte[] bytes = getBytes(store.get(txn, USERS_KEY));+ byte[] bytes = readBytes(store, txn, USERS_KEY);if (bytes != null) {List<NameAndEmail> users =new ArrayList<>((Set<NameAndEmail>) SerializationUtils.deserialize(bytes));@@ -538,7 +552,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager impleme@SuppressWarnings("unchecked")@Overridepublic List<String> compute(Transaction txn) {- byte[] bytes = getBytes(store.get(txn, FILES_KEY));+ byte[] bytes = readBytes(store, txn, FILES_KEY);if (bytes != null) {List<String> files = new ArrayList<>(((Map<String, Long>)SerializationUtils.deserialize(bytes)).keySet());@@ -567,12 +581,12 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager impleme}@Override- public int getModifications(ProjectFacade project, UserFacade user, String path) {+ public int getEdits(ProjectFacade project, UserFacade user, String path) {if (user.getEmail() != null) {Environment env = getEnv(project.getId().toString());Store emailToIndexStore = getStore(env, EMAIL_TO_INDEX_STORE);Store pathToIndexStore = getStore(env, PATH_TO_INDEX_STORE);- Store modificationsStore = getStore(env, MODIFICATIONS_STORE);+ Store editsStore = getStore(env, EDITS_STORE);return env.computeInReadonlyTransaction(new TransactionalComputable<Integer>() {@Override@@ -581,8 +595,8 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemeif (userIndex != -1) {int pathIndex = readInt(pathToIndexStore, txn, new StringByteIterable(path), -1);if (pathIndex != -1) {- long modificationsKey = (userIndex<<32)|pathIndex;- return readInt(modificationsStore, txn, new LongByteIterable(modificationsKey), 0);+ long editsKey = (userIndex<<32)|pathIndex;+ return readInt(editsStore, txn, new LongByteIterable(editsKey), 0);}}return 0;@@ -612,7 +626,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemeObjectId current = stack.pop();byte[] keyBytes = new byte[20];current.copyRawTo(keyBytes, 0);- byte[] valueBytes = getBytes(store.get(txn, new ArrayByteIterable(keyBytes)));+ byte[] valueBytes = readBytes(store, txn, new ArrayByteIterable(keyBytes));if (valueBytes != null) {if (valueBytes.length % 20 == 0) {for (int i=0; i<valueBytes.length/20; i++) {@@ -657,7 +671,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemebyte[] keyBytes = new byte[20];parent.copyRawTo(keyBytes, 0);- byte[] valueBytes = getBytes(store.get(txn, new ArrayByteIterable(keyBytes)));+ byte[] valueBytes = readBytes(store, txn, new ArrayByteIterable(keyBytes));if (valueBytes != null) {if (valueBytes.length % 20 == 0) {for (int i=0; i<valueBytes.length/20; i++) {@@ -738,7 +752,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemebyte[] keyBytes = new byte[20];commit.copyRawTo(keyBytes, 0);ByteIterable key = new ArrayByteIterable(keyBytes);- byte[] valueBytes = getBytes(commitsStore.get(txn, key));+ byte[] valueBytes = readBytes(commitsStore, txn, key);if (valueBytes == null || valueBytes.length % 20 == 0)works.add(new CollectingWork(PRIORITY, commit, ref.getName()));}@@ -875,7 +889,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemeprivate Collection<String> getPaths(Transaction txn, Set<Integer> pathIndexes) {Set<String> paths = new HashSet<>();for (int pathIndex: pathIndexes) {- byte[] pathBytes = getBytes(indexToPathStore.get(txn, new IntByteIterable(pathIndex)));+ byte[] pathBytes = readBytes(indexToPathStore, txn, new IntByteIterable(pathIndex));if (pathBytes != null)paths.add(new String(pathBytes, Charsets.UTF_8));}@@ -892,7 +906,7 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemeSet<Integer> newPathIndexes = new HashSet<>(pathIndexes);for (int eachPathIndex: pathIndexes) {byte[] bytesOfHistoryPaths =- getBytes(historyPathsStore.get(txn, new IntByteIterable(eachPathIndex)));+ readBytes(historyPathsStore, txn, new IntByteIterable(eachPathIndex));if (bytesOfHistoryPaths != null) {int pos = 0;for (int i=0; i<bytesOfHistoryPaths.length/Integer.BYTES; i++) {@@ -918,131 +932,158 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager impleme@Sessional@Override- public List<DayAndCommits> getOverallContributions(Project project) {+ public Map<Day, Contribution> getOverallContributions(Project project) {Environment env = getEnv(project.getId().toString());- Store store = getStore(env, DAILY_CONTRIBUTIONS_STORE);+ Store store = getStore(env, DEFAULT_STORE);- return env.computeInReadonlyTransaction(new TransactionalComputable<List<DayAndCommits>>() {+ return env.computeInReadonlyTransaction(new TransactionalComputable<Map<Day, Contribution>>() {@Override- public List<DayAndCommits> compute(Transaction txn) {- Map<Integer, Integer> map = readDailyCommits(store, txn, new IntByteIterable(-1));- List<DayAndCommits> contributions = new ArrayList<>();- for (Map.Entry<Integer, Integer> entry: map.entrySet())- contributions.add(new DayAndCommits(new Day(entry.getKey()), entry.getValue()));- Collections.sort(contributions);- return contributions;+ public Map<Day, Contribution> compute(Transaction txn) {+ Map<Day, Contribution> overallContributions = new HashMap<>();+ for (Map.Entry<Integer, Contribution> entry:+ deserializeContributions(readBytes(store, txn, OVERALL_CONTRIBUTIONS_KEY)).entrySet()) {+ overallContributions.put(new Day(entry.getKey()), entry.getValue());+ }+ return overallContributions;}});}-+@Sessional@Override- public List<UserContribution> getUserContributions(Project project, int top, Day fromDay, Day toDay) {+ public List<Contributor> getTopContributors(Project project, int top, Contribution.Type orderBy,+ Day fromDay, Day toDay) {Environment env = getEnv(project.getId().toString());Store defaultStore = getStore(env, DEFAULT_STORE);Store indexToUserStore = getStore(env, INDEX_TO_USER_STORE);Store dailyContributionsStore = getStore(env, DAILY_CONTRIBUTIONS_STORE);- return env.computeInReadonlyTransaction(new TransactionalComputable<List<UserContribution>>() {+ return env.computeInReadonlyTransaction(new TransactionalComputable<List<Contributor>>() {@Override- public List<UserContribution> compute(Transaction txn) {- int nextUserIndex = readInt(defaultStore, txn, NEXT_USER_INDEX_KEY, 0);- List<Pair<ByteIterable, Integer>> list = new ArrayList<>();- for (int userIndex=0; userIndex<nextUserIndex; userIndex++) {- ByteIterable userKey = new IntByteIterable(userIndex);- Map<Integer, Integer> dailyCommitCounts = readDailyCommits(dailyContributionsStore, txn, userKey);- int totalCommitCount = 0;- for (Map.Entry<Integer, Integer> entry: dailyCommitCounts.entrySet()) {- if (entry.getKey()>=fromDay.getValue() && entry.getKey()<=toDay.getValue())- totalCommitCount += entry.getValue();+ public List<Contributor> compute(Transaction txn) {+ Map<Integer, Contribution> overallContributions =+ deserializeContributions(readBytes(defaultStore, txn, OVERALL_CONTRIBUTIONS_KEY));+ Map<Integer, Integer> orderByValues = new HashMap<>();+ for (int dayValue: overallContributions.keySet()) {+ if (dayValue >= fromDay.getValue() && dayValue <= toDay.getValue()) {+ ByteIterable dayKey = new IntByteIterable(dayValue);+ Map<Integer, Contribution> contributionsOnDay =+ deserializeContributions(readBytes(dailyContributionsStore, txn, dayKey));+ for (Map.Entry<Integer, Contribution> entry: contributionsOnDay.entrySet()) {+ int orderByValue;+ if (orderBy == Contribution.Type.COMMITS)+ orderByValue = entry.getValue().getCommits();+ else if (orderBy == Contribution.Type.ADDITIONS)+ orderByValue = entry.getValue().getAdditions();+ else+ orderByValue = entry.getValue().getDeletions();+ Integer userIndex = entry.getKey();+ Integer existingOrderByValue = orderByValues.get(userIndex);+ if (existingOrderByValue != null)+ orderByValue += existingOrderByValue;+ orderByValues.put(userIndex, orderByValue);+ }}- list.add(new Pair<>(userKey, totalCommitCount));}- Collections.sort(list, new Comparator<Pair<ByteIterable, Integer>>() {++ List<Integer> topUserIndexes = new ArrayList<>(orderByValues.keySet());+ Collections.sort(topUserIndexes, new Comparator<Integer>() {@Override- public int compare(Pair<ByteIterable, Integer> o1, Pair<ByteIterable, Integer> o2) {- return o2.getSecond() - o1.getSecond();+ public int compare(Integer o1, Integer o2) {+ return orderByValues.get(o2) - orderByValues.get(o1);}});- List<UserContribution> listOfUserContribution = new ArrayList<>();- int numContributionsToReturn = top;- if (numContributionsToReturn > list.size())- numContributionsToReturn = list.size();- for (int i=0; i<numContributionsToReturn; i++) {- Pair<ByteIterable, Integer> pair = list.get(i);- if (pair.getSecond() == 0)- break;- ByteIterable userKey = pair.getFirst();- byte[] userBytes = getBytes(indexToUserStore.get(txn, userKey));- if (userBytes != null) {- List<DayAndCommits> listOfDayAndCommits = new ArrayList<>();- Map<Integer, Integer> commitCounts = readDailyCommits(dailyContributionsStore, txn, userKey);- for (Iterator<Map.Entry<Integer, Integer>> it = commitCounts.entrySet().iterator(); it.hasNext();) {- Map.Entry<Integer, Integer> entry = it.next();- if (entry.getKey()>=fromDay.getValue() && entry.getKey()<=toDay.getValue())- listOfDayAndCommits.add(new DayAndCommits(new Day(entry.getKey()), entry.getValue()));+ if (top < topUserIndexes.size())+ topUserIndexes = topUserIndexes.subList(0, top);++ Set<Integer> topUserIndexSet = new HashSet<>(topUserIndexes);++ Map<Integer, Map<Day, Contribution>> userContributions = new HashMap<>();++ for (int dayValue: overallContributions.keySet()) {+ if (dayValue >= fromDay.getValue() && dayValue <= toDay.getValue()) {+ ByteIterable dayKey = new IntByteIterable(dayValue);+ Map<Integer, Contribution> contributionsOnDay =+ deserializeContributions(readBytes(dailyContributionsStore, txn, dayKey));+ Day day = new Day(dayValue);+ for (Map.Entry<Integer, Contribution> entry: contributionsOnDay.entrySet()) {+ Integer userIndex = entry.getKey();+ if (topUserIndexSet.contains(userIndex)) {+ Map<Day, Contribution> contributionsByUser = userContributions.get(userIndex);+ if (contributionsByUser == null) {+ contributionsByUser = new HashMap<>();+ userContributions.put(userIndex, contributionsByUser);+ }+ contributionsByUser.put(day, entry.getValue());+ }}- Collections.sort(listOfDayAndCommits);- listOfUserContribution.add(new UserContribution(- ((NameAndEmail)SerializationUtils.deserialize(userBytes)).asPersonIdent(),- listOfDayAndCommits));+ }+ }++ List<Contributor> contributors = new ArrayList<>();++ for (int userIndex: topUserIndexes) {+ byte[] userBytes = readBytes(indexToUserStore, txn, new IntByteIterable(userIndex));+ Map<Day, Contribution> contributionsByUser = userContributions.get(userIndex);+ if (userBytes != null && contributionsByUser != null) {+ PersonIdent user = ((NameAndEmail)SerializationUtils.deserialize(userBytes)).asPersonIdent();+ contributors.add(new Contributor(user, contributionsByUser));}}- return listOfUserContribution;+ return contributors;}});}- /**- * Increase contribution- *- * @param userIndex- * user index to increase contribution, use -1 for overall contributions- * @param day- * day of the contribution- */- private void increaseDailyCommits(Store store, Transaction txn,- Map<Integer, Map<Integer, Integer>> dailyCommitsCache, int userIndex, int day) {- Map<Integer, Integer> dailyCommitsOfUser = dailyCommitsCache.get(userIndex);- if (dailyCommitsOfUser == null) {- ByteIterable userKey = new IntByteIterable(userIndex);- dailyCommitsOfUser = readDailyCommits(store, txn, userKey);- dailyCommitsCache.put(userIndex, dailyCommitsOfUser);- }- Integer commitCount = dailyCommitsOfUser.get(day);- if (commitCount != null)- commitCount++;- else- commitCount = 1;- dailyCommitsOfUser.put(day, commitCount);- }-- private Map<Integer, Integer> readDailyCommits(Store store, Transaction txn, ByteIterable userKey) {- byte[] bytes = getBytes(store.get(txn, userKey));+ private Map<Integer, Contribution> deserializeContributions(byte[] bytes) {if (bytes != null) {- Map<Integer, Integer> map = new HashMap<>();+ Map<Integer, Contribution> contributions = new HashMap<>();int pos = 0;- for (int i=0; i<bytes.length/2/Integer.BYTES; i++) {+ for (int i=0; i<bytes.length/4/Integer.BYTES; i++) {int key = ByteBuffer.wrap(bytes, pos, Integer.BYTES).getInt();pos += Integer.BYTES;- int value = ByteBuffer.wrap(bytes, pos, Integer.BYTES).getInt();+ int commits = ByteBuffer.wrap(bytes, pos, Integer.BYTES).getInt();+ pos += Integer.BYTES;+ int additions = ByteBuffer.wrap(bytes, pos, Integer.BYTES).getInt();+ pos += Integer.BYTES;+ int deletions = ByteBuffer.wrap(bytes, pos, Integer.BYTES).getInt();pos += Integer.BYTES;- map.put(key, value);+ contributions.put(key, new Contribution(commits, additions, deletions));}- return map;+ return contributions;} else {return new HashMap<>();}}+ private byte[] serializeContributions(Map<Integer, Contribution> contributions) {+ byte[] bytes = new byte[contributions.size()*Integer.BYTES*4];+ int pos = 0;+ for (Map.Entry<Integer, Contribution> entry: contributions.entrySet()) {+ byte[] keyBytes = ByteBuffer.allocate(Integer.BYTES).putInt(entry.getKey()).array();+ System.arraycopy(keyBytes, 0, bytes, pos, Integer.BYTES);+ pos += Integer.BYTES;+ byte[] commitsBytes = ByteBuffer.allocate(Integer.BYTES).putInt(entry.getValue().getCommits()).array();+ System.arraycopy(commitsBytes, 0, bytes, pos, Integer.BYTES);+ pos += Integer.BYTES;+ byte[] additionsBytes = ByteBuffer.allocate(Integer.BYTES).putInt(entry.getValue().getAdditions()).array();+ System.arraycopy(additionsBytes, 0, bytes, pos, Integer.BYTES);+ pos += Integer.BYTES;+ byte[] deletionsBytes = ByteBuffer.allocate(Integer.BYTES).putInt(entry.getValue().getDeletions()).array();+ System.arraycopy(deletionsBytes, 0, bytes, pos, Integer.BYTES);+ pos += Integer.BYTES;+ }+ return bytes;+ }+@Overrideprotected long getLogFileSize() {return LOG_FILE_SIZE;@@ -1058,4 +1099,5 @@ public class DefaultCommitInfoManager extends AbstractEnvironmentManager implemeint path;}+}diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultVerificationManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultVerificationManager.javaindex 84311905ec..6523a84381 100644--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultVerificationManager.java+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultVerificationManager.java@@ -82,7 +82,7 @@ public class DefaultVerificationManager extends AbstractEnvironmentManager imple@Overridepublic void execute(Transaction txn) {ByteIterable key = new StringByteIterable(VERIFICATION_NAMES_KEY);- byte[] bytes = getBytes(defaultStore.get(txn, key));+ byte[] bytes = readBytes(defaultStore, txn, key);Map<String, Date> verificationNames;if (bytes != null)verificationNames = (Map<String, Date>) SerializationUtils.deserialize(bytes);@@ -102,7 +102,7 @@ public class DefaultVerificationManager extends AbstractEnvironmentManager implenew ArrayByteIterable(SerializationUtils.serialize((Serializable) verificationNames)));key = new StringByteIterable(commit);- bytes = getBytes(verificationsStore.get(txn, key));+ bytes = readBytes(verificationsStore, txn, key);Map<String, Verification> verifications;if (bytes != null)verifications = (Map<String, Verification>) SerializationUtils.deserialize(bytes);@@ -144,7 +144,7 @@ public class DefaultVerificationManager extends AbstractEnvironmentManager imple@SuppressWarnings("unchecked")@Overridepublic Map<String, Verification> compute(Transaction txn) {- byte[] bytes = getBytes(store.get(txn, new StringByteIterable(commit)));+ byte[] bytes = readBytes(store, txn, new StringByteIterable(commit));if (bytes != null)return (Map<String, Verification>) SerializationUtils.deserialize(bytes);else@@ -183,7 +183,7 @@ public class DefaultVerificationManager extends AbstractEnvironmentManager imple@SuppressWarnings("unchecked")@Overridepublic Collection<String> compute(Transaction txn) {- byte[] bytes = getBytes(store.get(txn, new StringByteIterable(VERIFICATION_NAMES_KEY)));+ byte[] bytes = readBytes(store, txn, new StringByteIterable(VERIFICATION_NAMES_KEY));if (bytes != null)return ((Map<String, Date>) SerializationUtils.deserialize(bytes)).keySet();elsediff --git a/core/src/main/java/com/gitplex/server/util/Day.java b/core/src/main/java/com/gitplex/server/util/Day.javaindex 091cad09d7..8a89e85d05 100644--- a/core/src/main/java/com/gitplex/server/util/Day.java+++ b/core/src/main/java/com/gitplex/server/util/Day.java@@ -3,6 +3,8 @@ package com.gitplex.server.util;import java.io.Serializable;import java.util.Date;+import org.apache.commons.lang3.builder.EqualsBuilder;+import org.apache.commons.lang3.builder.HashCodeBuilder;import org.joda.time.DateTime;public class Day implements Serializable, Comparable<Day> {@@ -41,4 +43,21 @@ public class Day implements Serializable, Comparable<Day> {return dateTime.compareTo(o.dateTime);}+ @Override+ public boolean equals(Object other) {+ if (this == other) {+ return true;+ } else if (other instanceof Day) {+ Day otherDay = (Day) other;+ return new EqualsBuilder().append(dateTime, otherDay.dateTime).isEquals();+ } else {+ return false;+ }+ }++ @Override+ public int hashCode() {+ return new HashCodeBuilder(17, 37).append(dateTime).toHashCode();+ }+}diff --git a/core/src/main/java/com/gitplex/server/util/QualityCheckStatus.java b/core/src/main/java/com/gitplex/server/util/QualityCheckStatus.javaindex 2747a1a99c..18567236c5 100644--- a/core/src/main/java/com/gitplex/server/util/QualityCheckStatus.java+++ b/core/src/main/java/com/gitplex/server/util/QualityCheckStatus.java@@ -303,7 +303,7 @@ public class QualityCheckStatus {int addedContributions = 0;for (Map.Entry<UserFacade, Integer> entry: contributions.entrySet()) {UserFacade user = entry.getKey();- int fileContribution = commitInfoManager.getModifications(+ int fileContribution = commitInfoManager.getEdits(update.getRequest().getTargetProject().getFacade(), user, file);entry.setValue(entry.getValue() + fileContribution);addedContributions += fileContribution;diff --git a/core/src/test/java/com/gitplex/server/git/command/LogCommandTest.java b/core/src/test/java/com/gitplex/server/git/command/LogCommandTest.javaindex 4190641287..1e7a950caa 100644--- a/core/src/test/java/com/gitplex/server/git/command/LogCommandTest.java+++ b/core/src/test/java/com/gitplex/server/git/command/LogCommandTest.java@@ -8,7 +8,7 @@ import java.util.List;import org.junit.Test;import com.gitplex.server.git.AbstractGitTest;-import com.gitplex.server.git.command.FileChange.Action;+import com.google.common.collect.Lists;public class LogCommandTest extends AbstractGitTest {@@ -75,18 +75,24 @@ public class LogCommandTest extends AbstractGitTest {commits.add(commit);}- }.call();+ }.revisions(Lists.newArrayList("master")).call();assertEquals(2, commits.size());++ LogCommit commit = commits.get(0);++ assertEquals(3, commit.getFileChanges().size());++ assertEquals("另一个 测试文件", commit.getFileChanges().get(0).getPath());+ assertEquals(0, commit.getFileChanges().get(0).getAdditions());+ assertEquals(1, commit.getFileChanges().get(0).getDeletions());- assertEquals(3, commits.get(0).getFileChanges().size());- assertEquals(Action.MODIFY, commits.get(0).getFileChanges().get(0).getAction());- assertEquals("另一个 测试文件", commits.get(0).getFileChanges().get(0).getNewPath());- assertEquals(Action.RENAME, commits.get(0).getFileChanges().get(1).getAction());- assertEquals("改名后 测试文件", commits.get(0).getFileChanges().get(1).getNewPath());- assertEquals(Action.ADD, commits.get(0).getFileChanges().get(2).getAction());- assertEquals("第三个 测试文件", commits.get(0).getFileChanges().get(2).getNewPath());+ assertEquals("改名后 测试文件", commit.getFileChanges().get(1).getPath());+ assertEquals("测试文件", commit.getFileChanges().get(1).getOldPath());+ assertEquals("第三个 测试文件", commit.getFileChanges().get(2).getPath());+ assertEquals(8, commit.getFileChanges().get(2).getAdditions());+ assertEquals(0, commit.getFileChanges().get(2).getDeletions());}}\ No newline at end of filediff --git a/web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionPanel.html b/web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionListPanel.htmlsimilarity index 100%rename from web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionPanel.htmlrename to web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionListPanel.htmldiff --git a/web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionPanel.java b/web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionListPanel.javasimilarity index 51%rename from web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionPanel.javarename to web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionListPanel.javaindex db58ad0095..98a83c67a7 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionPanel.java+++ b/web/src/main/java/com/gitplex/server/web/page/project/stats/ContributionListPanel.java@@ -17,45 +17,62 @@ import org.apache.wicket.markup.repeater.Item;import org.apache.wicket.model.IModel;import org.apache.wicket.model.Model;-import com.gitplex.server.git.DayAndCommits;import com.gitplex.server.web.WebConstants;import com.gitplex.server.web.util.DateUtils;@SuppressWarnings("serial")-public class ContributionPanel extends Panel {+class ContributionListPanel extends Panel {- public ContributionPanel(String id, IModel<List<DayAndCommits>> contributionModel) {- super(id, contributionModel);+ public ContributionListPanel(String id, IModel<List<DayContribution>> contributionsModel) {+ super(id, contributionsModel);}@Overrideprotected void onInitialize() {super.onInitialize();- List<IColumn<DayAndCommits, Void>> columns = new ArrayList<>();+ List<IColumn<DayContribution, Void>> columns = new ArrayList<>();- columns.add(new AbstractColumn<DayAndCommits, Void>(Model.of("Date")) {+ columns.add(new AbstractColumn<DayContribution, Void>(Model.of("Date")) {@Override- public void populateItem(Item<ICellPopulator<DayAndCommits>> cellItem, String componentId,- IModel<DayAndCommits> rowModel) {+ public void populateItem(Item<ICellPopulator<DayContribution>> cellItem, String componentId,+ IModel<DayContribution> rowModel) {cellItem.add(new Label(componentId, DateUtils.formatDate(rowModel.getObject().getDay().getDate())));}});- columns.add(new AbstractColumn<DayAndCommits, Void>(Model.of("Commits")) {+ columns.add(new AbstractColumn<DayContribution, Void>(Model.of("Commits")) {@Override- public void populateItem(Item<ICellPopulator<DayAndCommits>> cellItem, String componentId,- IModel<DayAndCommits> rowModel) {- cellItem.add(new Label(componentId, rowModel.getObject().getCommits()));+ public void populateItem(Item<ICellPopulator<DayContribution>> cellItem, String componentId,+ IModel<DayContribution> rowModel) {+ cellItem.add(new Label(componentId, rowModel.getObject().getContribution().getCommits()));}});- SortableDataProvider<DayAndCommits, Void> dataProvider = new SortableDataProvider<DayAndCommits, Void>() {+ columns.add(new AbstractColumn<DayContribution, Void>(Model.of("Additions")) {@Override- public Iterator<? extends DayAndCommits> iterator(long first, long count) {+ public void populateItem(Item<ICellPopulator<DayContribution>> cellItem, String componentId,+ IModel<DayContribution> rowModel) {+ cellItem.add(new Label(componentId, rowModel.getObject().getContribution().getAdditions()));+ }+ });++ columns.add(new AbstractColumn<DayContribution, Void>(Model.of("Deletions")) {++ @Override+ public void populateItem(Item<ICellPopulator<DayContribution>> cellItem, String componentId,+ IModel<DayContribution> rowModel) {+ cellItem.add(new Label(componentId, rowModel.getObject().getContribution().getDeletions()));+ }+ });++ SortableDataProvider<DayContribution, Void> dataProvider = new SortableDataProvider<DayContribution, Void>() {++ @Override+ public Iterator<? extends DayContribution> iterator(long first, long count) {if (first + count <= getContribution().size())return getContribution().subList((int)first, (int)(first+count)).iterator();else@@ -68,13 +85,13 @@ public class ContributionPanel extends Panel {}@Override- public IModel<DayAndCommits> model(DayAndCommits object) {+ public IModel<DayContribution> model(DayContribution object) {return Model.of(object);}};- DataTable<DayAndCommits, Void> contributionTable =- new DataTable<DayAndCommits, Void>("table", columns, dataProvider, WebConstants.PAGE_SIZE);+ DataTable<DayContribution, Void> contributionTable =+ new DataTable<DayContribution, Void>("table", columns, dataProvider, WebConstants.PAGE_SIZE);contributionTable.addTopToolbar(new HeadersToolbar<>(contributionTable, dataProvider));contributionTable.addBottomToolbar(new AjaxNavigationToolbar(contributionTable));@@ -83,8 +100,8 @@ public class ContributionPanel extends Panel {}@SuppressWarnings("unchecked")- private List<DayAndCommits> getContribution() {- return (List<DayAndCommits>) getDefaultModelObject();+ private List<DayContribution> getContribution() {+ return (List<DayContribution>) getDefaultModelObject();}}diff --git a/web/src/main/java/com/gitplex/server/web/page/project/stats/DayContribution.java b/web/src/main/java/com/gitplex/server/web/page/project/stats/DayContribution.javanew file mode 100644index 0000000000..a376204827--- /dev/null+++ b/web/src/main/java/com/gitplex/server/web/page/project/stats/DayContribution.java@@ -0,0 +1,34 @@+package com.gitplex.server.web.page.project.stats;++import java.io.Serializable;++import com.gitplex.server.git.Contribution;+import com.gitplex.server.util.Day;++class DayContribution implements Serializable, Comparable<DayContribution> {++ private static final long serialVersionUID = 1L;++ private final Day day;++ private final Contribution contribution;++ public DayContribution(Day day, Contribution contribution) {+ this.day = day;+ this.contribution = contribution;+ }++ public Day getDay() {+ return day;+ }++ public Contribution getContribution() {+ return contribution;+ }++ @Override+ public int compareTo(DayContribution o) {+ return day.compareTo(o.day);+ }++}\ No newline at end of filediff --git a/web/src/main/java/com/gitplex/server/web/page/project/stats/ProjectStatsPage.html b/web/src/main/java/com/gitplex/server/web/page/project/stats/ProjectStatsPage.htmlindex 5c4c062386..91ccbea88c 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/stats/ProjectStatsPage.html+++ b/web/src/main/java/com/gitplex/server/web/page/project/stats/ProjectStatsPage.html@@ -1,21 +1,34 @@<wicket:extend><div id="project-stats">- <div class="contribution">+ <div class="well"><h2>Overall contribution</h2><div wicket:id="overallContribution"></div></div>- <div class="user-contributions">+ <div class="top-contributors"><h2>Top 10 User Contributions</h2>- <form wicket:id="dateRange">+ <form wicket:id="topOptions" class="form-inline"><div wicket:id="feedback"></div>- <input wicket:id="fromDay" placeholder="yyyy-MM-dd"></input>- <input wicket:id="toDay" placeholder="yyyy-MM-dd"></input>- <a wicket:id="update">Update</a>+ <div class="form-group">+ <label class="control-label">From Day: </label>+ <input wicket:id="fromDay" placeholder="yyyy-MM-dd" class="form-control"></input>+ </div>+ <div class="form-group">+ <label class="control-label">To Day: </label>+ <input wicket:id="toDay" placeholder="yyyy-MM-dd" class="form-control"></input>+ </div>+ <div class="form-group">+ <label class="control-label">Order By: </label>+ <select wicket:id="orderBy" class="form-control"></select>+ </div>+ <div class="form-group">+ <a wicket:id="update" class="btn btn-default">Update</a>+ </div></form>- <div wicket:id="userContributions" class="contribution">+ <hr/>+ <div wicket:id="topContributors" class="well"><div wicket:id="user"></div>- <div wicket:id="userContribution"></div>+ <div wicket:id="contributions"></div></div></div></div>diff --git a/web/src/main/java/com/gitplex/server/web/page/project/stats/ProjectStatsPage.java b/web/src/main/java/com/gitplex/server/web/page/project/stats/ProjectStatsPage.javaindex c8e3a54c9a..ccadf069d7 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/stats/ProjectStatsPage.java+++ b/web/src/main/java/com/gitplex/server/web/page/project/stats/ProjectStatsPage.java@@ -1,12 +1,15 @@package com.gitplex.server.web.page.project.stats;import java.util.ArrayList;+import java.util.Collections;import java.util.List;+import java.util.Map;import org.apache.commons.lang.StringUtils;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.head.JavaScriptHeaderItem;import org.apache.wicket.markup.head.OnDomReadyHeaderItem;+import org.apache.wicket.markup.html.form.DropDownChoice;import org.apache.wicket.markup.html.form.Form;import org.apache.wicket.markup.html.form.SubmitLink;import org.apache.wicket.markup.html.form.TextField;@@ -20,8 +23,8 @@ import org.apache.wicket.model.PropertyModel;import org.apache.wicket.request.mapper.parameter.PageParameters;import com.gitplex.server.GitPlex;-import com.gitplex.server.git.DayAndCommits;-import com.gitplex.server.git.UserContribution;+import com.gitplex.server.git.Contribution;+import com.gitplex.server.git.Contributor;import com.gitplex.server.manager.CommitInfoManager;import com.gitplex.server.util.Day;import com.gitplex.server.web.WebConstants;@@ -34,20 +37,23 @@ import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel@SuppressWarnings("serial")public class ProjectStatsPage extends ProjectPage {- private final IModel<List<DayAndCommits>> overallContributionsModel =- new LoadableDetachableModel<List<DayAndCommits>>() {+ private final IModel<List<DayContribution>> overallContributionsModel =+ new LoadableDetachableModel<List<DayContribution>>() {@Override- protected List<DayAndCommits> load() {- return GitPlex.getInstance(CommitInfoManager.class).getOverallContributions(getProject());+ protected List<DayContribution> load() {+ Map<Day, Contribution> map = GitPlex.getInstance(CommitInfoManager.class).getOverallContributions(getProject());+ return sort(map);}};-+private String fromDayText;private String toDayText;+ private String orderBy = Contribution.Type.COMMITS.name();+public ProjectStatsPage(PageParameters params) {super(params);}@@ -57,14 +63,22 @@ public class ProjectStatsPage extends ProjectPage {overallContributionsModel.detach();super.onDetach();}++ private List<DayContribution> sort(Map<Day, Contribution> map) {+ List<DayContribution> list = new ArrayList<>();+ for (Map.Entry<Day, Contribution> entry: map.entrySet())+ list.add(new DayContribution(entry.getKey(), entry.getValue()));+ Collections.sort(list);+ return list;+ }@Overrideprotected void onInitialize() {super.onInitialize();- add(new ContributionPanel("overallContribution", overallContributionsModel));+ add(new ContributionListPanel("overallContribution", overallContributionsModel));- Form<?> form = new Form<Void>("dateRange");+ Form<?> form = new Form<Void>("topOptions");form.add(new SubmitLink("update") {@Override@@ -93,13 +107,19 @@ public class ProjectStatsPage extends ProjectPage {form.add(new TextField<String>("fromDay", new PropertyModel<String>(this, "fromDayText")));form.add(new TextField<String>("toDay", new PropertyModel<String>(this, "toDayText")));+ List<String> orderByChoices = new ArrayList<>();+ for (Contribution.Type type: Contribution.Type.values())+ orderByChoices.add(type.name());++ form.add(new DropDownChoice<String>("orderBy", new PropertyModel<String>(this, "orderBy"), orderByChoices));+add(form);- add(new ListView<UserContribution>("userContributions", new LoadableDetachableModel<List<UserContribution>>() {+ add(new ListView<Contributor>("topContributors", new LoadableDetachableModel<List<Contributor>>() {@Override- protected List<UserContribution> load() {- List<DayAndCommits> overallContributions = overallContributionsModel.getObject();+ protected List<Contributor> load() {+ List<DayContribution> overallContributions = overallContributionsModel.getObject();int size = overallContributions.size();if (size != 0) {Day fromDay;@@ -117,7 +137,7 @@ public class ProjectStatsPage extends ProjectPage {}return GitPlex.getInstance(CommitInfoManager.class)- .getUserContributions(getProject(), 10, fromDay, toDay);+ .getTopContributors(getProject(), 25, Contribution.Type.valueOf(orderBy), fromDay, toDay);} else {return new ArrayList<>();}@@ -126,18 +146,18 @@ public class ProjectStatsPage extends ProjectPage {}) {@Override- protected void populateItem(ListItem<UserContribution> item) {- UserContribution userContribution = item.getModelObject();+ protected void populateItem(ListItem<Contributor> item) {+ Contributor userContribution = item.getModelObject();Fragment fragment = new Fragment("user", "userFrag", ProjectStatsPage.this);fragment.add(new AvatarLink("avatar", userContribution.getUser()));fragment.add(new UserLink("link", userContribution.getUser()));item.add(fragment);- item.add(new ContributionPanel("userContribution", new AbstractReadOnlyModel<List<DayAndCommits>>() {+ item.add(new ContributionListPanel("contributions", new AbstractReadOnlyModel<List<DayContribution>>() {@Override- public List<DayAndCommits> getObject() {- return item.getModelObject().getDayAndCommits();+ public List<DayContribution> getObject() {+ return sort(item.getModelObject().getDailyContributions());}}));diff --git a/web/src/main/java/com/gitplex/server/web/page/project/stats/project-stats.css b/web/src/main/java/com/gitplex/server/web/page/project/stats/project-stats.cssindex dab6d92669..ee9f3ffbd8 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/stats/project-stats.css+++ b/web/src/main/java/com/gitplex/server/web/page/project/stats/project-stats.css@@ -2,8 +2,10 @@padding: 20px;}-#project-stats .contribution {- border: 1px solid #BBB;- padding: 20px;+#project-stats .form-inline div {+ margin-right: 10px;}+#project-stats .form-inline div .btn {+ margin-left: 20px;+}\ No newline at end of filediff --git a/web/src/main/java/com/gitplex/server/web/page/project/stats/project-stats.js b/web/src/main/java/com/gitplex/server/web/page/project/stats/project-stats.jsindex ed2e774ba6..2b13258cd6 100644--- a/web/src/main/java/com/gitplex/server/web/page/project/stats/project-stats.js+++ b/web/src/main/java/com/gitplex/server/web/page/project/stats/project-stats.js@@ -2,4 +2,4 @@ gitplex.server.stats = {onDomReady: function() {}-}\ No newline at end of file+}