changeset 551:4a18bdd61aa6

Cache repos in order to not read .hgstate/.hgsubstate twice
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Mon, 25 Feb 2013 16:49:13 +0400
parents 2fbe8c7fa710
children ba4f9148d39e
files mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java
diffstat 2 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Mon Feb 25 16:33:20 2013 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Mon Feb 25 16:49:13 2013 +0400
@@ -540,7 +540,7 @@
   }
 
   public List<ModificationData> collectChanges(@NotNull VcsRoot root, @NotNull String fromVersion, @Nullable String currentVersion, @NotNull CheckoutRules checkoutRules) throws VcsException {
-    OperationContext ctx = new OperationContext(this);
+    OperationContext ctx = new OperationContext(this, myRepoFactory);
     return collectChanges(ctx, root, asList(fromVersion), currentVersion, checkoutRules);
   }
 
@@ -577,7 +577,7 @@
       result.addParentRevision(parent.getId());
     }
     setCanBeIgnored(result, cset);
-    result.setAttributes(getAttributes(root, cset));
+    result.setAttributes(getAttributes(ctx, root, cset));
     return result;
   }
 
@@ -615,12 +615,12 @@
   }
 
   @NotNull
-  private Map<String, String> getAttributes(@NotNull VcsRoot mainRoot, @NotNull ChangeSet cset) throws VcsException {
+  private Map<String, String> getAttributes(@NotNull OperationContext ctx, @NotNull VcsRoot mainRoot, @NotNull ChangeSet cset) throws VcsException {
     Map<String, String> attributes = new HashMap<String, String>();
     HgVcsRoot root = myHgVcsRootFactory.createHgRoot(mainRoot);
     if (myConfig.detectSubrepoChanges() && root.detectSubrepoChanges()) {
       try {
-        ServerHgRepo repo = createRepo(root);
+        ServerHgRepo repo = createRepo(ctx, root);
         SubrepoConfigChangesAttributes builder = new SubrepoConfigChangesAttributes();
         for (HgSubrepoConfigChange c : repo.getSubrepoConfigChanges(cset)) {
           fillSubrepoConfigChanges(builder, root, c);
@@ -795,9 +795,7 @@
   }
 
   public ServerHgRepo createRepo(@NotNull OperationContext ctx, @NotNull HgVcsRoot root) throws VcsException {
-    ServerHgRepo repo = myRepoFactory.create(getWorkingDir(root), myHgPathProvider.getHgPath(root), root.getAuthSettings());
-    repo.setOperationContext(ctx);
-    return repo;
+    return ctx.createRepo(getWorkingDir(root), myHgPathProvider.getHgPath(root), root.getAuthSettings());
   }
 
 
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java	Mon Feb 25 16:33:20 2013 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java	Mon Feb 25 16:49:13 2013 +0400
@@ -1,6 +1,7 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
 import com.intellij.openapi.util.Pair;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.AuthSettings;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot;
 import jetbrains.buildServer.vcs.VcsException;
 import jetbrains.buildServer.vcs.VcsRoot;
@@ -12,12 +13,16 @@
 public class OperationContext {
 
   private final MercurialVcsSupport myVcs;
+  private final RepoFactory myRepoFactory;
   private Set<File> mySyncedDirs = new HashSet<File>();
   private Map<String, HgVersion> myHgVersions = new HashMap<String, HgVersion>();
   private Map<String, Set<SubrepoChangesInterval>> myProcessedSubrepoChanges = new HashMap<String, Set<SubrepoChangesInterval>>();
+  private Map<File, ServerHgRepo> myRepos = new HashMap<File, ServerHgRepo>();
 
-  public OperationContext(@NotNull MercurialVcsSupport vcs) {
+  public OperationContext(@NotNull MercurialVcsSupport vcs,
+                          @NotNull RepoFactory repoFactory) {
     myVcs = vcs;
+    myRepoFactory = repoFactory;
   }
 
 
@@ -58,6 +63,17 @@
     return processedSubrepoChanges.contains(new SubrepoChangesInterval(previousSubrepoRevisions, currentSubrepoRevision));
   }
 
+  @NotNull
+  public ServerHgRepo createRepo(@NotNull File workingDir, @NotNull String hgPath, @NotNull AuthSettings authSettings) throws VcsException {
+    ServerHgRepo repo = myRepos.get(workingDir);
+    if (repo != null)
+      return repo;
+    repo = myRepoFactory.create(workingDir, hgPath, authSettings);
+    repo.setOperationContext(this);
+    myRepos.put(workingDir, repo);
+    return repo;
+  }
+
   private final static class SubrepoChangesInterval extends Pair<List<String>, String> {
     private SubrepoChangesInterval(@NotNull List<String> prevRevisions, @NotNull String currentRevision) {
       super(prevRevisions, currentRevision);