summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorGabriel Luong2013-05-27 15:57:35 (EDT)
committer Szymon Brandys2013-06-14 08:00:13 (EDT)
commit2aa910bc533fcd82b654cf8f9c85d988ccaa8092 (patch)
treeeea5b69b312f5022da56f561babf6a2bcbf6f360
parente58dbacf4bae6994f5f384132d66445baaeaafbc (diff)
downloadorg.eclipse.orion.server-2aa910bc533fcd82b654cf8f9c85d988ccaa8092.zip
org.eclipse.orion.server-2aa910bc533fcd82b654cf8f9c85d988ccaa8092.tar.gz
org.eclipse.orion.server-2aa910bc533fcd82b654cf8f9c85d988ccaa8092.tar.bz2
Bug 407174 - Git log performance very slow
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Commit.java27
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Log.java24
2 files changed, 38 insertions, 13 deletions
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Commit.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Commit.java
index cff0601..22d08b8 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Commit.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Commit.java
@@ -74,6 +74,7 @@ public class Commit extends GitObject {
*/
private boolean isRoot = true;
private Map<ObjectId, JSONArray> commitToBranchMap;
+ private Map<ObjectId, Map<String, Ref>> commitToTagMap;
public Commit(URI cloneLocation, Repository db, RevCommit revCommit, String pattern) {
super(cloneLocation, db);
@@ -89,12 +90,22 @@ public class Commit extends GitObject {
this.commitToBranchMap = map;
}
+ public void setCommitToTagMap(Map<ObjectId, Map<String, Ref>> map) {
+ this.commitToTagMap = map;
+ }
+
public Map<ObjectId, JSONArray> getCommitToBranchMap() throws GitAPIException, JSONException, URISyntaxException, IOException, CoreException {
if (commitToBranchMap == null)
commitToBranchMap = Log.getCommitToBranchMap(cloneLocation, db);
return commitToBranchMap;
}
+ public Map<ObjectId, Map<String, Ref>> getCommitToTagMap() throws GitAPIException, JSONException, URISyntaxException, IOException, CoreException {
+ if (commitToTagMap == null)
+ commitToTagMap = Log.getCommitToTagMap(cloneLocation, db);
+ return commitToTagMap;
+ }
+
/**
* Return body of the commit
*
@@ -175,7 +186,7 @@ public class Commit extends GitObject {
// TODO: expandable
@PropertyDescription(name = GitConstants.KEY_TAGS)
- private JSONArray getTags() throws MissingObjectException, JSONException, URISyntaxException, CoreException, IOException {
+ private JSONArray getTags() throws MissingObjectException, JSONException, URISyntaxException, CoreException, IOException, GitAPIException {
return toJSON(getTagsForCommit());
}
@@ -244,18 +255,8 @@ public class Commit extends GitObject {
return BaseToCommitConverter.getCommitLocation(cloneLocation, revCommit.getName(), pattern, BaseToCommitConverter.REMOVE_FIRST_2);
}
- private Map<String, Ref> getTagsForCommit() throws MissingObjectException, IOException {
- final Map<String, Ref> tags = new HashMap<String, Ref>();
- for (final Entry<String, Ref> tag : db.getTags().entrySet()) {
- Ref ref = db.peel(tag.getValue());
- ObjectId refId = ref.getPeeledObjectId();
- if (refId == null)
- refId = ref.getObjectId();
- if (!AnyObjectId.equals(refId, revCommit))
- continue;
- tags.put(tag.getKey(), tag.getValue());
- }
- return tags;
+ private Map<String, Ref> getTagsForCommit() throws MissingObjectException, IOException, GitAPIException, JSONException, URISyntaxException, CoreException {
+ return getCommitToTagMap().get(revCommit.getId());
}
private URI createDiffLocation(String toRefId, String fromRefId, String path) throws URISyntaxException {
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Log.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Log.java
index 9bab0cf..d24cc62 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Log.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/objects/Log.java
@@ -14,10 +14,12 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.*;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.*;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.RemoteConfig;
@@ -92,11 +94,13 @@ public class Log extends GitObject {
@PropertyDescription(name = ProtocolConstants.KEY_CHILDREN)
private JSONArray getChildren() throws GitAPIException, JSONException, URISyntaxException, IOException, CoreException {
Map<ObjectId, JSONArray> commitToBranchMap = getCommitToBranchMap(cloneLocation, db);
+ Map<ObjectId, Map<String, Ref>> commitToTagMap = getCommitToTagMap(cloneLocation, db);
JSONArray children = new JSONArray();
int i = 0;
for (RevCommit revCommit : commits) {
Commit commit = new Commit(cloneLocation, db, revCommit, pattern);
commit.setCommitToBranchMap(commitToBranchMap);
+ commit.setCommitToTagMap(commitToTagMap);
children.put(commit.toJSON());
if (i++ == pageSize - 1)
break;
@@ -228,4 +232,24 @@ public class Log extends GitObject {
}
return commitToBranch;
}
+
+ static Map<ObjectId, Map<String, Ref>> getCommitToTagMap(URI cloneLocation, Repository db) throws MissingObjectException, IOException {
+ HashMap<ObjectId, Map<String, Ref>> commitToTag = new HashMap<ObjectId, Map<String, Ref>>();
+ for (Entry<String, Ref> tag : db.getTags().entrySet()) {
+ Ref ref = db.peel(tag.getValue());
+ ObjectId commitId = ref.getPeeledObjectId();
+ if (commitId == null)
+ commitId = ref.getObjectId();
+
+ Map<String, Ref> tags = commitToTag.get(commitId);
+ if (tags != null) {
+ tags.put(tag.getKey(), tag.getValue());
+ } else {
+ tags = new HashMap<String, Ref>();
+ tags.put(tag.getKey(), tag.getValue());
+ commitToTag.put(commitId, tags);
+ }
+ }
+ return commitToTag;
+ }
}