The Unified and Autonomous Development Platform
Use jgit revwalk/treewalk to speed up commit information collection
robin shinedce8daff90d6
diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/CherryPickCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/CherryPickCommand.javaindex b7ed17b2d1..3f4b9a2a12 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/CherryPickCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/CherryPickCommand.java@@ -72,7 +72,7 @@ public class CherryPickCommand extends GitCommand<String> {});if (emptyCommitSet.get())- return new Git(repoDir).parseRevision("HEAD", true);+ return new Git(gitDir).parseRevision("HEAD", true);if (hasConflict.get())return null;@@ -80,7 +80,7 @@ public class CherryPickCommand extends GitCommand<String> {result.checkReturnCode();}}- return new Git(repoDir).parseRevision("HEAD", true);+ return new Git(gitDir).parseRevision("HEAD", true);}}diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/GitCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/GitCommand.javaindex 84293cd883..820af52070 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/GitCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/GitCommand.java@@ -23,20 +23,20 @@ public abstract class GitCommand<V> implements Callable<V> {private static final String MIN_VERSION = "1.8.0";- protected final File repoDir;+ protected final File gitDir;private final Map<String, String> environments;- public GitCommand(File repoDir, @Nullable Map<String, String> environments) {- this.repoDir = repoDir;+ public GitCommand(File gitDir, @Nullable Map<String, String> environments) {+ this.gitDir = gitDir;this.environments = environments;- if (!repoDir.exists())- FileUtils.createDir(repoDir);+ if (!gitDir.exists())+ FileUtils.createDir(gitDir);}- public GitCommand(File repoDir) {- this(repoDir, null);+ public GitCommand(File gitDir) {+ this(gitDir, null);}/**@@ -91,7 +91,7 @@ public abstract class GitCommand<V> implements Callable<V> {public Commandline cmd() {String gitExe = getGitExe();- Commandline cmd = new Commandline(gitExe).workingDir(repoDir);+ Commandline cmd = new Commandline(gitExe).workingDir(gitDir);if (environments != null)cmd.environments(environments);return cmd;diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/IsTreeLinkCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/IsTreeLinkCommand.javaindex 5c73a8e0a5..8e91485bf8 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/IsTreeLinkCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/IsTreeLinkCommand.java@@ -41,7 +41,7 @@ public class IsTreeLinkCommand extends GitCommand<Boolean> {String targetPath;try {- targetPath = new String(new Git(repoDir).show(revision, symlink), "UTF8");+ targetPath = new String(new Git(gitDir).show(revision, symlink), "UTF8");} catch (UnsupportedEncodingException e) {throw new RuntimeException(e);}diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/ListSubModulesCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/ListSubModulesCommand.javaindex a4afbb794b..c014fcf2a6 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/ListSubModulesCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/ListSubModulesCommand.java@@ -24,7 +24,7 @@ public class ListSubModulesCommand extends GitCommand<Map<String, String>> {public Map<String, String> call() {Map<String, String> modules = new HashMap<>();- String content = new String(new Git(repoDir).show(revision, ".gitmodules"));+ String content = new String(new Git(gitDir).show(revision, ".gitmodules"));String path = null;String url = null;diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.javaindex f88073b231..7f9ccd3f6a 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java@@ -1,124 +1,124 @@-package com.pmease.commons.git.command;--import java.io.File;-import java.util.concurrent.atomic.AtomicBoolean;--import org.slf4j.Logger;-import org.slf4j.LoggerFactory;--import com.google.common.base.Preconditions;-import com.pmease.commons.git.Git;-import com.pmease.commons.util.execution.Commandline;-import com.pmease.commons.util.execution.ExecuteResult;-import com.pmease.commons.util.execution.LineConsumer;--public class MergeCommand extends GitCommand<String> {-- private static final Logger logger = LoggerFactory.getLogger(MergeCommand.class);-- public enum FastForwardMode {FF_ONLY, NO_FF, FF};-- private String revision;-- private FastForwardMode fastForwardMode;-- private boolean squash;-- private String strategy;-- private String strategyOption;-- private String message;-- public MergeCommand(final File repoDir) {- super(repoDir);- }-- public MergeCommand revision(String revision) {- this.revision = revision;- return this;- }-- public MergeCommand fastForwardMode(FastForwardMode fastForwardMode) {- this.fastForwardMode = fastForwardMode;- return this;- }-- public MergeCommand strategy(String strategy) {- this.strategy = strategy;- return this;- }-- public MergeCommand strategyOption(String strategyOption) {- this.strategyOption = strategyOption;- return this;- }-- public MergeCommand squash(boolean squash) {- this.squash = squash;- return this;- }-- public MergeCommand message(String message) {- this.message = message;- return this;- }-- @Override- public String call() {- Preconditions.checkNotNull(revision, "revision has to be specified.");-- Commandline cmd = cmd().addArgs("merge");-- cmd.addArgs("--no-edit", "--quiet");-- if (fastForwardMode == FastForwardMode.FF_ONLY)- cmd.addArgs("--ff-only");- else if (fastForwardMode == FastForwardMode.NO_FF)- cmd.addArgs("--no-ff");- else- cmd.addArgs("--ff");-- if (strategy != null)- cmd.addArgs("--strategy=" + strategy);- if (strategyOption != null)- cmd.addArgs("--strategy-option=" + strategyOption);-- if (squash)- cmd.addArgs("--squash");- else if (message != null)- cmd.addArgs("-m", message);-- cmd.addArgs(revision);-- final AtomicBoolean conflict = new AtomicBoolean(false);-- ExecuteResult result = cmd.execute(new LineConsumer() {-- @Override- public void consume(String line) {- if (line.startsWith("CONFLICT") || line.startsWith("fatal: Not possible to fast-forward"))- conflict.set(true);- }-- }, new LineConsumer() {-- @Override- public void consume(String line) {- logger.error(line);- }-- });-- if (conflict.get())- return null;-- result.checkReturnCode();-- Git git = new Git(repoDir);- if (squash)- git.commit(message, false, false);- return git.parseRevision("HEAD", true);- }--}+package com.pmease.commons.git.command;++import java.io.File;+import java.util.concurrent.atomic.AtomicBoolean;++import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++import com.google.common.base.Preconditions;+import com.pmease.commons.git.Git;+import com.pmease.commons.util.execution.Commandline;+import com.pmease.commons.util.execution.ExecuteResult;+import com.pmease.commons.util.execution.LineConsumer;++public class MergeCommand extends GitCommand<String> {++ private static final Logger logger = LoggerFactory.getLogger(MergeCommand.class);++ public enum FastForwardMode {FF_ONLY, NO_FF, FF};++ private String revision;++ private FastForwardMode fastForwardMode;++ private boolean squash;++ private String strategy;++ private String strategyOption;++ private String message;++ public MergeCommand(final File repoDir) {+ super(repoDir);+ }++ public MergeCommand revision(String revision) {+ this.revision = revision;+ return this;+ }++ public MergeCommand fastForwardMode(FastForwardMode fastForwardMode) {+ this.fastForwardMode = fastForwardMode;+ return this;+ }++ public MergeCommand strategy(String strategy) {+ this.strategy = strategy;+ return this;+ }++ public MergeCommand strategyOption(String strategyOption) {+ this.strategyOption = strategyOption;+ return this;+ }++ public MergeCommand squash(boolean squash) {+ this.squash = squash;+ return this;+ }++ public MergeCommand message(String message) {+ this.message = message;+ return this;+ }++ @Override+ public String call() {+ Preconditions.checkNotNull(revision, "revision has to be specified.");++ Commandline cmd = cmd().addArgs("merge");++ cmd.addArgs("--no-edit", "--quiet");++ if (fastForwardMode == FastForwardMode.FF_ONLY)+ cmd.addArgs("--ff-only");+ else if (fastForwardMode == FastForwardMode.NO_FF)+ cmd.addArgs("--no-ff");+ else+ cmd.addArgs("--ff");++ if (strategy != null)+ cmd.addArgs("--strategy=" + strategy);+ if (strategyOption != null)+ cmd.addArgs("--strategy-option=" + strategyOption);++ if (squash)+ cmd.addArgs("--squash");+ else if (message != null)+ cmd.addArgs("-m", message);++ cmd.addArgs(revision);++ final AtomicBoolean conflict = new AtomicBoolean(false);++ ExecuteResult result = cmd.execute(new LineConsumer() {++ @Override+ public void consume(String line) {+ if (line.startsWith("CONFLICT") || line.startsWith("fatal: Not possible to fast-forward"))+ conflict.set(true);+ }++ }, new LineConsumer() {++ @Override+ public void consume(String line) {+ logger.error(line);+ }++ });++ if (conflict.get())+ return null;++ result.checkReturnCode();++ Git git = new Git(gitDir);+ if (squash)+ git.commit(message, false, false);+ return git.parseRevision("HEAD", true);+ }++}diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/RevListCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/RevListCommand.javanew file mode 100644index 0000000000..f3669d2789--- /dev/null+++ b/commons.git/src/main/java/com/pmease/commons/git/command/RevListCommand.java@@ -0,0 +1,208 @@+package com.pmease.commons.git.command;++import java.io.File;+import java.util.ArrayList;+import java.util.Date;+import java.util.List;++import org.apache.commons.lang3.time.DateFormatUtils;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++import com.pmease.commons.util.execution.Commandline;+import com.pmease.commons.util.execution.LineConsumer;++public class RevListCommand extends GitCommand<List<String>> {++ private static final Logger logger = LoggerFactory.getLogger(RevListCommand.class);++ private List<String> revisions = new ArrayList<>();++ private List<String> paths = new ArrayList<>();++ private String after;++ private String before;++ private int count;++ private int skip;++ private boolean ignoreCase;++ private List<String> messages = new ArrayList<>();++ private List<String> authors = new ArrayList<>();++ private List<String> committers = new ArrayList<>();++ public RevListCommand(File gitDir) {+ super(gitDir);+ }++ public List<String> revisions() {+ return revisions;+ }++ public RevListCommand revisions(List<String> revisions) {+ this.revisions = revisions;+ return this;+ }++ public List<String> paths() {+ return paths;+ }++ public RevListCommand paths(List<String> paths) {+ this.paths = paths;+ return this;+ }++ public String after() {+ return after;+ }++ public RevListCommand after(String after) {+ this.after = after;+ return this;+ }++ public RevListCommand after(Date after) {+ this.after = DateFormatUtils.ISO_DATE_FORMAT.format(after);+ return this;+ }++ public String before() {+ return before;+ }++ public RevListCommand before(String before) {+ this.before = before;+ return this;+ }++ public RevListCommand before(Date before) {+ this.before = DateFormatUtils.ISO_DATE_FORMAT.format(before);+ return this;+ }++ public int count() {+ return count;+ }++ public RevListCommand count(int count) {+ this.count = count;+ return this;+ }++ public int skip() {+ return skip;+ }++ public RevListCommand skip(int skip) {+ this.skip = skip;+ return this;+ }++ public boolean ignoreCase() {+ return ignoreCase;+ }++ public RevListCommand ignoreCase(boolean ignoreCase) {+ this.ignoreCase = ignoreCase;+ return this;+ }++ public List<String> messages() {+ return messages;+ }++ public RevListCommand messages(List<String> messages) {+ this.messages = messages;+ return this;+ }++ public List<String> authors() {+ return authors;+ }++ public RevListCommand authors(List<String> authors) {+ this.authors = authors;+ return this;+ }++ public List<String> committers() {+ return committers;+ }++ public RevListCommand commmitters(List<String> committers) {+ this.committers = committers;+ return this;+ }++ @Override+ public List<String> call() {+ Commandline cmd = cmd();+ cmd.addArgs("log",+ "--format=*** commit_begin ***%n%B%n*** commit_message_end ***%n%N"+ + "*** commit_note_end ***%nhash:%H%nauthor:%aN%nauthorEmail:%aE%n"+ + "committerEmail:%cE%ncommitter:%cN%nparents:%P%ncommitterDate:%cd %n"+ + "authorDate:%ad %n",+ "--date=raw");++ if (!revisions.isEmpty()) {+ for (String revision: revisions)+ cmd.addArgs(revision);+ } else {+ cmd.addArgs("--branches");+ }++ if (before != null)+ cmd.addArgs("--before", before);++ if (after != null)+ cmd.addArgs("--after", after);++ if (count != 0)+ cmd.addArgs("-" + count);+ if (skip != 0)+ cmd.addArgs("--skip=" + skip);++ for (String author: authors)+ cmd.addArgs("--author=" + author);++ for (String committer: committers)+ cmd.addArgs("--committer=" + committer);++ for (String message: messages)+ cmd.addArgs("--grep=" + message);++ if (ignoreCase)+ cmd.addArgs("-i");++ cmd.addArgs("--");++ for (String path: paths)+ cmd.addArgs(path);++ List<String> commitHashes = new ArrayList<>();+ cmd.execute(new LineConsumer() {++ @Override+ public void consume(String line) {+ commitHashes.add(line);+ }++ }, new LineConsumer() {++ @Override+ public void consume(String line) {+ logger.error(line);+ }++ }).checkReturnCode();++ return commitHashes;+ }++}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.javaindex 0bef42b2b1..7065f4e378 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java@@ -359,6 +359,10 @@ public class Depot extends AbstractEntity implements AccountBelonging {return new Git(AppLoader.getInstance(StorageManager.class).getGitDir(this));}+ public File getGitDir() {+ return AppLoader.getInstance(StorageManager.class).getGitDir(this);+ }+/*** Whether or not specified git represents a valid repository git. This can be used to tell* apart a GitPlex repository git from some other Git repositories.diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitInfoManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitInfoManager.javaindex 21f8502d26..ee38479b0e 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitInfoManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitInfoManager.java@@ -1,7 +1,6 @@package com.pmease.gitplex.core.manager;import java.util.List;-import java.util.Map;import java.util.Set;import org.eclipse.jgit.lib.ObjectId;@@ -19,11 +18,9 @@ public interface CommitInfoManager {int getCommitCount(Depot depot);- List<NameAndEmail> getContributors(Depot depot);+ List<NameAndEmail> getAuthors(Depot depot);- Map<String, Map<NameAndEmail, Long>> getContributions(Depot depot, Set<String> files);-- Map<NameAndEmail, Long> getContributions(Depot depot, String file);+ List<NameAndEmail> getCommitters(Depot depot);/*** Given an ancestor commit, get all its descendant commits. The result might be incompletediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitInfoManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitInfoManager.javaindex fc3885d5ee..3074962ab1 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitInfoManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitInfoManager.java@@ -12,14 +12,11 @@ import java.util.HashMap;import java.util.HashSet;import java.util.List;import java.util.Map;-import java.util.Optional;import java.util.Set;import java.util.Stack;import java.util.concurrent.Callable;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.ExecutionException;-import java.util.concurrent.ExecutorService;-import java.util.concurrent.SynchronousQueue;import javax.annotation.Nullable;import javax.inject.Inject;@@ -33,14 +30,12 @@ import org.eclipse.jgit.lib.Ref;import org.eclipse.jgit.revwalk.RevCommit;import org.eclipse.jgit.revwalk.RevObject;import org.eclipse.jgit.revwalk.RevWalk;+import org.eclipse.jgit.treewalk.TreeWalk;+import org.eclipse.jgit.treewalk.filter.TreeFilter;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import com.pmease.commons.git.Commit;-import com.pmease.commons.git.Git;import com.pmease.commons.git.NameAndEmail;-import com.pmease.commons.git.command.CommitConsumer;-import com.pmease.commons.git.command.LogCommand;import com.pmease.commons.hibernate.UnitOfWork;import com.pmease.commons.util.FileUtils;import com.pmease.commons.util.concurrent.PrioritizedRunnable;@@ -78,11 +73,11 @@ public class DefaultCommitInfoManager implements CommitInfoManager, DepotListeneprivate static final String COMMITS_STORE = "commits";- private static final String CONTRIBUTIONS_STORE = "contributions";-private static final ByteIterable LAST_COMMIT_KEY = new StringByteIterable("lastCommit");- private static final ByteIterable CONTRIBUTORS_KEY = new StringByteIterable("contributors");+ private static final ByteIterable AUTHORS_KEY = new StringByteIterable("authors");++ private static final ByteIterable COMMITTERS_KEY = new StringByteIterable("committers");private static final ByteIterable FILES_KEY = new StringByteIterable("files");@@ -100,39 +95,37 @@ public class DefaultCommitInfoManager implements CommitInfoManager, DepotListeneprivate final UnitOfWork unitOfWork;- private final ExecutorService executorService;-private final Map<Long, Environment> envs = new HashMap<>();private final Map<Long, List<String>> filesCache = new ConcurrentHashMap<>();private final Map<Long, Integer> commitCountCache = new ConcurrentHashMap<>();- private final Map<Long, List<NameAndEmail>> contributorsCache = new ConcurrentHashMap<>();+ private final Map<Long, List<NameAndEmail>> authorsCache = new ConcurrentHashMap<>();++ private final Map<Long, List<NameAndEmail>> committersCache = new ConcurrentHashMap<>();@Injectpublic DefaultCommitInfoManager(DepotManager depotManager, StorageManager storageManager,WorkManager workManager, SequentialWorkManager sequentialWorkManager,- UnitOfWork unitOfWork, ExecutorService executorService) {+ UnitOfWork unitOfWork) {this.depotManager = depotManager;this.storageManager = storageManager;this.workManager = workManager;this.sequentialWorkManager = sequentialWorkManager;this.unitOfWork = unitOfWork;- this.executorService = executorService;}private String getSequentialExecutorKey(Depot depot) {return "repository-" + depot.getId() + "-collectCommitInfo";}- private void doCollect(Depot depot, ObjectId commit) {+ private void doCollect(Depot depot, ObjectId commitId) {logger.info("Collecting commit information (repository: {}, until commit: {})",- depot.getFQN(), commit.name());+ depot.getFQN(), commitId.name());Environment env = getEnv(depot);Store defaultStore = getStore(env, DEFAULT_STORE);Store commitsStore = getStore(env, COMMITS_STORE);- Store contributionsStore = getStore(env, CONTRIBUTIONS_STORE);env.executeInTransaction(new TransactionalExecutable() {@@ -140,11 +133,11 @@ public class DefaultCommitInfoManager implements CommitInfoManager, DepotListene@Overridepublic void execute(final Transaction txn) {byte[] bytes = getBytes(defaultStore.get(txn, LAST_COMMIT_KEY));- String lastCommit;+ ObjectId lastCommitId;if (bytes != null)- lastCommit = new String(bytes);+ lastCommitId = ObjectId.fromRaw(bytes);else- lastCommit = null;+ lastCommitId = null;bytes = getBytes(defaultStore.get(txn, COMMIT_COUNT_KEY));int commitCount;@@ -153,73 +146,53 @@ public class DefaultCommitInfoManager implements CommitInfoManager, DepotListeneelsecommitCount = 0;- boolean commitCountChanged = false;-- Git git = depot.git();-- LogCommand log = new LogCommand(git.depotDir());- List<String> revisions = new ArrayList<>();- if (lastCommit != null) {- revisions.add(lastCommit + ".." + commit.name());- lastCommit = null;- } else {- revisions.add(commit.name());- }-- Set<NameAndEmail> contributors = null;- boolean contributorsChanged = false;+ Set<NameAndEmail> authors;+ bytes = getBytes(defaultStore.get(txn, AUTHORS_KEY));+ if (bytes != null)+ authors = (Set<NameAndEmail>) SerializationUtils.deserialize(bytes);+ else+ authors = new HashSet<NameAndEmail>();- Set<String> files = null;- boolean filesChanged = false;+ Set<NameAndEmail> committers;+ bytes = getBytes(defaultStore.get(txn, COMMITTERS_KEY));+ if (bytes != null)+ committers = (Set<NameAndEmail>) SerializationUtils.deserialize(bytes);+ else+ committers = new HashSet<NameAndEmail>();- /*- * Use a synchronous queue to achieve below purpose:- * 1. Add commit to Xodus transactional store in the same thread opening the transaction- * as this is required by Xodus- * 2. Do not pile up commits to use minimal memory- */- SynchronousQueue<Optional<Commit>> queue = new SynchronousQueue<>();- executorService.execute(new Runnable() {-- @Override- public void run() {- try {- log.revisions(revisions).listChangedFiles(true).run(new CommitConsumer() {-- @Override- public void consume(Commit commit) {- try {- queue.put(Optional.of(commit));- } catch (InterruptedException e) {- }- }-- });- } catch (Exception e) {- logger.error("Error running git log command", e);- } finally {- try {- queue.put(Optional.empty());- } catch (InterruptedException e) {- }- }+ try ( RevWalk revWalk = new RevWalk(depot.getRepository());+ TreeWalk treeWalk = new TreeWalk(depot.getRepository());) {+ treeWalk.setRecursive(true);+ RevCommit currentCommit = revWalk.parseCommit(commitId);+ revWalk.markStart(currentCommit);+ treeWalk.addTree(currentCommit.getTree());+ if (lastCommitId != null) {+ RevCommit lastCommit = revWalk.parseCommit(lastCommitId);+ revWalk.markUninteresting(lastCommit);+ treeWalk.addTree(lastCommit.getTree());+ treeWalk.setFilter(TreeFilter.ANY_DIFF);}- });- while (true) {- Optional<Commit> optionalCommit = null;- try {- optionalCommit = queue.take();- } catch (InterruptedException e) {+ Set<String> files;+ bytes = getBytes(defaultStore.get(txn, FILES_KEY));+ if (bytes != null) {+ files = (Set<String>) SerializationUtils.deserialize(bytes);+ } else {+ files = new HashSet<String>();}- if (optionalCommit == null || !optionalCommit.isPresent())- break;- Commit commit = optionalCommit.get();- try {+ while (treeWalk.next()) {+ files.add(treeWalk.getPathString());+ }++ bytes = SerializationUtils.serialize((Serializable) files);+ defaultStore.put(txn, FILES_KEY, new ArrayByteIterable(bytes));+ filesCache.remove(depot.getId());++ RevCommit commit = revWalk.next();+ while (commit != null) {byte[] keyBytes = new byte[20];- ObjectId commitId = ObjectId.fromString(commit.getHash());- commitId.copyRawTo(keyBytes, 0);+ commit.copyRawTo(keyBytes, 0);ByteIterable key = new ArrayByteIterable(keyBytes);byte[] valueBytes = getBytes(commitsStore.get(txn, key));@@ -241,11 +214,10 @@ public class DefaultCommitInfoManager implements CommitInfoManager, DepotListenecommitsStore.put(txn, key, new ArrayByteIterable(newValueBytes));commitCount++;- commitCountChanged = true;- for (String parentHash: commit.getParentHashes()) {+ for (RevCommit parent: commit.getParents()) {keyBytes = new byte[20];- ObjectId.fromString(parentHash).copyRawTo(keyBytes, 0);+ parent.copyRawTo(keyBytes, 0);key = new ArrayByteIterable(keyBytes);valueBytes = getBytes(commitsStore.get(txn, key));if (valueBytes != null) {@@ -254,90 +226,48 @@ public class DefaultCommitInfoManager implements CommitInfoManager, DepotListene} else {newValueBytes = new byte[20];}- commitId.copyRawTo(newValueBytes, newValueBytes.length-20);+ commit.copyRawTo(newValueBytes, newValueBytes.length-20);commitsStore.put(txn, key, new ArrayByteIterable(newValueBytes));}- if (contributors == null) {- bytes = getBytes(defaultStore.get(txn, CONTRIBUTORS_KEY));- if (bytes != null)- contributors = (Set<NameAndEmail>) SerializationUtils.deserialize(bytes);- else- contributors = new HashSet<NameAndEmail>();- }- if (StringUtils.isNotBlank(commit.getAuthor().getName())- || StringUtils.isNotBlank(commit.getAuthor().getEmailAddress())) {- NameAndEmail contributor = new NameAndEmail(commit.getAuthor());- if (!contributors.contains(contributor)) {- contributors.add(contributor);- contributorsChanged = true;- }+ if (StringUtils.isNotBlank(commit.getAuthorIdent().getName())+ || StringUtils.isNotBlank(commit.getAuthorIdent().getEmailAddress())) {+ authors.add(new NameAndEmail(commit.getAuthorIdent()));}- if (files == null) {- bytes = getBytes(defaultStore.get(txn, FILES_KEY));- if (bytes != null)- files = (Set<String>) SerializationUtils.deserialize(bytes);- else- files = new HashSet<String>();+ if (StringUtils.isNotBlank(commit.getCommitterIdent().getName())+ || StringUtils.isNotBlank(commit.getCommitterIdent().getEmailAddress())) {+ committers.add(new NameAndEmail(commit.getCommitterIdent()));}- for (String file: commit.getChangedFiles()) {- ByteIterable fileKey = new StringByteIterable(file);- bytes = getBytes(contributionsStore.get(txn, fileKey));- Map<NameAndEmail, Long> fileContributions;- if (bytes != null)- fileContributions = (Map<NameAndEmail, Long>) SerializationUtils.deserialize(bytes);- else- fileContributions = new HashMap<>();- if (StringUtils.isNotBlank(commit.getAuthor().getName())- || StringUtils.isNotBlank(commit.getAuthor().getEmailAddress())) {- NameAndEmail contributor = new NameAndEmail(commit.getAuthor());- long contributionTime = commit.getAuthor().getWhen().getTime();- Long lastContributionTime = fileContributions.get(contributor);- if (lastContributionTime == null || lastContributionTime.longValue() < contributionTime)- fileContributions.put(contributor, contributionTime);- }-- bytes = SerializationUtils.serialize((Serializable) fileContributions);- contributionsStore.put(txn, fileKey, new ArrayByteIterable(bytes));-- if (!files.contains(file)) {- files.add(file);- filesChanged = true;- }- }-- if (lastCommit == null)- lastCommit = commit.getHash();+ if (lastCommitId == null)+ lastCommitId = commit.copy();}- } catch (Exception e) {- logger.error("Error processing commit " + commit.getHash(), e);+ commit = revWalk.next();}+ } catch (IOException e) {+ throw new RuntimeException(e);}- if (contributorsChanged) {- bytes = SerializationUtils.serialize((Serializable) contributors);- defaultStore.put(txn, CONTRIBUTORS_KEY, new ArrayByteIterable(bytes));- contributorsCache.remove(depot.getId());- }- if (filesChanged) {- bytes = SerializationUtils.serialize((Serializable) files);- defaultStore.put(txn, FILES_KEY, new ArrayByteIterable(bytes));- filesCache.remove(depot.getId());- }- if (lastCommit != null) {- bytes = lastCommit.getBytes();- defaultStore.put(txn, LAST_COMMIT_KEY, new ArrayByteIterable(bytes));- }- if (commitCountChanged) {- bytes = SerializationUtils.serialize(commitCount);- defaultStore.put(txn, COMMIT_COUNT_KEY, new ArrayByteIterable(bytes));- commitCountCache.put(depot.getId(), commitCount);- }+ bytes = SerializationUtils.serialize((Serializable) authors);+ defaultStore.put(txn, AUTHORS_KEY, new ArrayByteIterable(bytes));+ authorsCache.remove(depot.getId());++ bytes = SerializationUtils.serialize((Serializable) committers);+ defaultStore.put(txn, COMMITTERS_KEY, new ArrayByteIterable(bytes));+ committersCache.remove(depot.getId());++ bytes = SerializationUtils.serialize(commitCount);+ defaultStore.put(txn, COMMIT_COUNT_KEY, new ArrayByteIterable(bytes));+ commitCountCache.put(depot.getId(), commitCount);++ bytes = new byte[20];+ commitId.copyRawTo(bytes, 0);+ defaultStore.put(txn, LAST_COMMIT_KEY, new ArrayByteIterable(bytes));}+});- logger.info("Commit information collected (repository: {}, until commit: {})", depot.getFQN(), commit.name());+ logger.info("Commit information collected (repository: {}, until commit: {})", depot.getFQN(), commitId.name());}@Override@@ -402,33 +332,61 @@ public class DefaultCommitInfoManager implements CommitInfoManager, DepotListene}@Override- public List<NameAndEmail> getContributors(Depot depot) {- List<NameAndEmail> contributors = contributorsCache.get(depot.getId());- if (contributors == null) {+ public List<NameAndEmail> getAuthors(Depot depot) {+ List<NameAndEmail> authors = authorsCache.get(depot.getId());+ if (authors == null) {Environment env = getEnv(depot);- final Store store = getStore(env, DEFAULT_STORE);+ Store store = getStore(env, DEFAULT_STORE);- contributors = env.computeInReadonlyTransaction(new TransactionalComputable<List<NameAndEmail>>() {+ authors = env.computeInReadonlyTransaction(new TransactionalComputable<List<NameAndEmail>>() {@SuppressWarnings("unchecked")@Overridepublic List<NameAndEmail> compute(Transaction txn) {- byte[] bytes = getBytes(store.get(txn, CONTRIBUTORS_KEY));+ byte[] bytes = getBytes(store.get(txn, AUTHORS_KEY));if (bytes != null) {- List<NameAndEmail> contributors =+ List<NameAndEmail> authors =new ArrayList<>((Set<NameAndEmail>) SerializationUtils.deserialize(bytes));- Collections.sort(contributors);- return contributors;+ Collections.sort(authors);+ return authors;} else {return new ArrayList<>();}}});- contributorsCache.put(depot.getId(), contributors);+ authorsCache.put(depot.getId(), authors);}- return contributors;+ return authors;}+ @Override+ public List<NameAndEmail> getCommitters(Depot depot) {+ List<NameAndEmail> committers = committersCache.get(depot.getId());+ if (committers == null) {+ Environment env = getEnv(depot);+ Store store = getStore(env, DEFAULT_STORE);++ committers = env.computeInReadonlyTransaction(new TransactionalComputable<List<NameAndEmail>>() {++ @SuppressWarnings("unchecked")+ @Override+ public List<NameAndEmail> compute(Transaction txn) {+ byte[] bytes = getBytes(store.get(txn, COMMITTERS_KEY));+ if (bytes != null) {+ List<NameAndEmail> committers =+ new ArrayList<>((Set<NameAndEmail>) SerializationUtils.deserialize(bytes));+ Collections.sort(committers);+ return committers;+ } else {+ return new ArrayList<>();+ }+ }+ });+ committersCache.put(depot.getId(), committers);+ }+ return committers;+ }+@Overridepublic List<String> getFiles(Depot depot) {List<String> files = filesCache.get(depot.getId());@@ -456,52 +414,6 @@ public class DefaultCommitInfoManager implements CommitInfoManager, DepotListenereturn files;}- @Override- public Map<String, Map<NameAndEmail, Long>> getContributions(Depot depot, Set<String> files) {- Environment env = getEnv(depot);- Store store = getStore(env, CONTRIBUTIONS_STORE);-- return env.computeInReadonlyTransaction(new TransactionalComputable<Map<String, Map<NameAndEmail, Long>>>() {-- @SuppressWarnings("unchecked")- @Override- public Map<String, Map<NameAndEmail, Long>> compute(Transaction txn) {- Map<String, Map<NameAndEmail, Long>> fileContributors = new HashMap<>();- for (String file: files) {- ByteIterable fileKey = new StringByteIterable(file);- Map<NameAndEmail, Long> contributions;- byte[] value = getBytes(store.get(txn, fileKey));- if (value != null)- contributions = (Map<NameAndEmail, Long>) SerializationUtils.deserialize(value);- else- contributions = new HashMap<>();- fileContributors.put(file, contributions);- }- return fileContributors;- }- });- }-- @Override- public Map<NameAndEmail, Long> getContributions(Depot depot, String file) {- Environment env = getEnv(depot);- Store store = getStore(env, CONTRIBUTIONS_STORE);-- return env.computeInReadonlyTransaction(new TransactionalComputable<Map<NameAndEmail, Long>>() {-- @SuppressWarnings("unchecked")- @Override- public Map<NameAndEmail, Long> compute(Transaction txn) {- ByteIterable fileKey = new StringByteIterable(file);- byte[] value = getBytes(store.get(txn, fileKey));- if (value != null)- return (Map<NameAndEmail, Long>) SerializationUtils.deserialize(value);- else- return new HashMap<>();- }- });- }-@Overridepublic Set<ObjectId> getDescendants(Depot depot, final ObjectId ancestor) {Environment env = getEnv(depot);@@ -596,7 +508,7 @@ public class DefaultCommitInfoManager implements CommitInfoManager, DepotListeneenv.close();filesCache.remove(depot.getId());commitCountCache.remove(depot.getId());- contributorsCache.remove(depot.getId());+ authorsCache.remove(depot.getId());FileUtils.deleteDir(getInfoDir(depot));}diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.javaindex 925ef66da6..7609a6f77a 100644--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/DefaultIndexManager.java@@ -147,9 +147,10 @@ public class DefaultIndexManager implements IndexManager {return indexVersion.get();}- private IndexResult index(org.eclipse.jgit.lib.Repository jgitRepo, AnyObjectId commitId,+ private IndexResult index(Repository repository, AnyObjectId commitId,IndexWriter writer, final IndexSearcher searcher) throws Exception {- try (RevWalk revWalk = new RevWalk(jgitRepo); TreeWalk treeWalk = new TreeWalk(jgitRepo)) {+ try ( RevWalk revWalk = new RevWalk(repository);+ TreeWalk treeWalk = new TreeWalk(repository)) {treeWalk.addTree(revWalk.parseCommit(commitId).getTree());treeWalk.setRecursive(true);@@ -163,8 +164,8 @@ public class DefaultIndexManager implements IndexManager {String lastCommitAnalyzersVersion = doc.get(LAST_COMMIT_INDEX_VERSION.name());if (lastCommitAnalyzersVersion.equals(extractors.getVersion())) {String lastCommitHash = doc.get(LAST_COMMIT_HASH.name());- ObjectId lastCommitId = jgitRepo.resolve(lastCommitHash);- if (jgitRepo.hasObject(lastCommitId)) {+ ObjectId lastCommitId = repository.resolve(lastCommitHash);+ if (repository.hasObject(lastCommitId)) {treeWalk.addTree(revWalk.parseCommit(lastCommitId).getTree());treeWalk.setFilter(TreeFilter.ANY_DIFF);}@@ -220,14 +221,14 @@ public class DefaultIndexManager implements IndexManager {if (currentBlobIndexVersion != null) {if (!blobIndexVersion.equals(currentBlobIndexVersion)) {writer.deleteDocuments(query);- indexBlob(writer, jgitRepo, extractor, blobId, blobPath);+ indexBlob(writer, repository, extractor, blobId, blobPath);indexed++;}} else {writer.deleteDocuments(query);}} else if (currentBlobIndexVersion != null) {- indexBlob(writer, jgitRepo, extractor, blobId, blobPath);+ indexBlob(writer, repository, extractor, blobId, blobPath);indexed++;}}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/QueryAssistBehavior.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/QueryAssistBehavior.javaindex 36ac68bf11..8728cef800 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/QueryAssistBehavior.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/QueryAssistBehavior.java@@ -74,7 +74,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {case CommitQueryParser.COMMITTER:Map<String, Range> suggestedInputs = new LinkedHashMap<>();CommitInfoManager commitInfoManager = GitPlex.getInstance(CommitInfoManager.class);- List<NameAndEmail> contributors = commitInfoManager.getContributors(depot);+ List<NameAndEmail> contributors = commitInfoManager.getAuthors(depot);for (NameAndEmail contributor: contributors) {String content;if (StringUtils.isNotBlank(contributor.getEmailAddress()))diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.javaindex 099bbd3a0e..135fed184b 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.java@@ -1,10 +1,14 @@package com.pmease.gitplex.web.page.depot.file;+import java.io.IOException;import java.util.ArrayList;+import java.util.Collections;+import java.util.HashSet;import java.util.List;-import java.util.Map;+import java.util.Set;import org.apache.wicket.Component;+import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.link.BookmarkablePageLink;import org.apache.wicket.markup.html.link.Link;@@ -14,15 +18,18 @@ import org.apache.wicket.markup.html.panel.Fragment;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;+import org.eclipse.jgit.lib.ObjectId;import org.eclipse.jgit.lib.PersonIdent;+import org.eclipse.jgit.revwalk.RevCommit;+import org.eclipse.jgit.revwalk.RevWalk;+import com.google.common.collect.Lists;import com.pmease.commons.git.BlobIdent;import com.pmease.commons.git.Commit;import com.pmease.commons.git.NameAndEmail;+import com.pmease.commons.git.command.RevListCommand;import com.pmease.commons.wicket.component.DropdownLink;-import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.entity.Depot;-import com.pmease.gitplex.core.manager.CommitInfoManager;import com.pmease.gitplex.web.component.avatar.Avatar;import com.pmease.gitplex.web.component.avatar.AvatarLink;import com.pmease.gitplex.web.component.contributorpanel.ContributorPanel;@@ -33,12 +40,15 @@ import com.pmease.gitplex.web.util.DateUtils;@SuppressWarnings("serial")class ContributionPanel extends Panel {+ private static final int MAX_CONTRIBUTORS = 1000;+private final IModel<Depot> depotModel;private final Commit commit;private final BlobIdent blobIdent;+public ContributionPanel(String id, IModel<Depot> depotModel, BlobIdent blobIdent) {super(id);@@ -68,38 +78,56 @@ class ContributionPanel extends Panel {@Overrideprotected Component newContent(String id) {- Fragment fragment = new Fragment(id, "contributorsFrag", ContributionPanel.this);- fragment.add(new ListView<NameAndEmail>("contributors", new LoadableDetachableModel<List<NameAndEmail>>() {+ return new AjaxLazyLoadPanel(id) {@Override- protected List<NameAndEmail> load() {- Map<NameAndEmail, Long> contributorsMap = GitPlex.getInstance(CommitInfoManager.class)- .getContributions(depotModel.getObject(), blobIdent.path);- List<NameAndEmail> contributors = new ArrayList<>(contributorsMap.keySet());- contributors.sort((element1, element2)- ->(int)(contributorsMap.get(element1)-contributorsMap.get(element2)));- return contributors;- }-- }) {+ public Component getLazyLoadComponent(String markupId) {+ Fragment fragment = new Fragment(id, "contributorsFrag", ContributionPanel.this);+ fragment.add(new ListView<NameAndEmail>("contributors", new LoadableDetachableModel<List<NameAndEmail>>() {- @Override- protected void populateItem(ListItem<NameAndEmail> item) {- NameAndEmail nameAndEmail = item.getModelObject();- PersonIdent person = new PersonIdent(nameAndEmail.getName(), nameAndEmail.getEmailAddress());- DepotCommitsPage.State state = new DepotCommitsPage.State();- state.setCompareWith(blobIdent.revision);- state.setQuery(String.format("path(%s) author(%s <%s>)",- blobIdent.path, nameAndEmail.getName(), nameAndEmail.getEmailAddress()));- Link<Void> link = new BookmarkablePageLink<Void>("link", DepotCommitsPage.class,- DepotCommitsPage.paramsOf(depotModel.getObject(), state));- link.add(new Avatar("avatar", person));- link.add(new Label("name", person.getName()));- item.add(link);+ @Override+ protected List<NameAndEmail> load() {+ Depot depot = depotModel.getObject();+ RevListCommand revList = new RevListCommand(depot.getGitDir());+ revList.paths(Lists.newArrayList(blobIdent.path));+ revList.revisions(Lists.newArrayList(blobIdent.revision));+ revList.count(MAX_CONTRIBUTORS);+ Set<NameAndEmail> setOfAuthors = new HashSet<>();+ try (RevWalk revWalk = new RevWalk(depot.getRepository())) {+ for (String commitHash: revList.call()) {+ RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitHash));+ setOfAuthors.add(new NameAndEmail(commit.getAuthorIdent()));+ }+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ List<NameAndEmail> listOfAuthors = new ArrayList<>(setOfAuthors);+ Collections.sort(listOfAuthors);+ return listOfAuthors;+ }++ }) {++ @Override+ protected void populateItem(ListItem<NameAndEmail> item) {+ NameAndEmail nameAndEmail = item.getModelObject();+ PersonIdent person = new PersonIdent(nameAndEmail.getName(), nameAndEmail.getEmailAddress());+ DepotCommitsPage.State state = new DepotCommitsPage.State();+ state.setCompareWith(blobIdent.revision);+ state.setQuery(String.format("path(%s) author(%s <%s>)",+ blobIdent.path, nameAndEmail.getName(), nameAndEmail.getEmailAddress()));+ Link<Void> link = new BookmarkablePageLink<Void>("link", DepotCommitsPage.class,+ DepotCommitsPage.paramsOf(depotModel.getObject(), state));+ link.add(new Avatar("avatar", person));+ link.add(new Label("name", person.getName()));+ item.add(link);+ }++ });+ return fragment;}- });- return fragment;+ };}@Override