changeset 685:5a0fc80839a8

Fix push from IDEA
author eugene.petrenko@gmail.com
date Tue, 10 Dec 2013 18:43:13 +0100
parents 7fb8ecf0d35a (diff) c0b08dd02418 (current diff)
children 1efd1846f00a
files
diffstat 2 files changed, 35 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java	Fri Dec 06 14:20:29 2013 +0100
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java	Tue Dec 10 18:43:13 2013 +0100
@@ -3,12 +3,10 @@
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.ChangeSet;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.ChangeSetRevision;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot;
+import jetbrains.buildServer.util.MultiMap;
 import jetbrains.buildServer.vcs.*;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.LogCommand.ZERO_PARENT_ID;
@@ -30,49 +28,39 @@
     myHgVcsRootFactory = vcsRootFactory;
   }
 
+  public void collectCommits(@NotNull final VcsRoot root,
+                             @NotNull final CheckoutRules rules,
+                             @NotNull final CommitsConsumer consumer) throws VcsException {
 
-  @NotNull
-  public List<CommitDataBean> collectCommits(@NotNull VcsRoot root,
-                                             @NotNull CheckoutRules rules) throws VcsException {
     final HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root);
     final ServerHgRepo repo = mySupport.createRepo(hgRoot);
     mySupport.syncRepository(hgRoot);
 
-    final Map<String, CommitDataBean> commitToBean = processChanges(repo);
-
-    //collect tags info
-    Map<String, String> tags = repo.tags().call();
-    for (Map.Entry<String, String> e : tags.entrySet()) {
-      CommitDataBean bean = commitToBean.get(e.getValue());
-      if (bean != null) bean.addTag(e.getKey());
+    MultiMap<String, String> commitToTag = new MultiMap<String, String>();
+    for (Map.Entry<String, String> e : repo.tags().call().entrySet()) {
+      commitToTag.putValue(e.getValue(), e.getKey());
     }
 
-    return new ArrayList<CommitDataBean>(commitToBean.values());
-  }
-
-  @NotNull
-  private Map<String, CommitDataBean> processChanges(@NotNull ServerHgRepo repo) throws VcsException {
-    final List<ChangeSet> tip = repo.logNoFiles()
-            .showCommitsFromAllBranches()
-            .call();
-
-    final Map<String, CommitDataBean> result = new HashMap<String, CommitDataBean>();
-    for (ChangeSet set : tip) {
-      final CommitDataBean bean = new CommitDataBean(set.getId(), set.getFullVersion(), set.getTimestamp());
+    //TODO: make stream parsing of commits instead of parsing of collected string output
+    for (ChangeSet set : repo.logNoFiles().showCommitsFromAllBranches().call()) {
+      final CommitDataBean change = new CommitDataBean(set.getId(), set.getFullVersion(), set.getTimestamp());
       for (ChangeSetRevision p : set.getParents()) {
         final String commitId = p.getId();
 
         if (ZERO_PARENT_ID.equals(commitId)) continue;
         if (ZERO_PARENT_SHORT_ID.equals(commitId)) continue;
-        bean.addParentRevision(commitId);
+        change.addParentRevision(commitId);
 
-        bean.setCommitMessage(set.getDescription());
-        bean.setCommitAuthor(set.getUser());
+        change.setCommitMessage(set.getDescription());
+        change.setCommitAuthor(set.getUser());
       }
-      bean.addBranch(set.getBranch());
-      result.put(bean.getVersion(), bean);
+      change.addBranch(set.getBranch());
+
+      for (String tag : commitToTag.get(set.getId())) {
+        change.addTag(tag);
+      }
+
+      consumer.consumeCommit(change);
     }
-
-    return result;
   }
 }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java	Fri Dec 06 14:20:29 2013 +0100
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java	Tue Dec 10 18:43:13 2013 +0100
@@ -1,21 +1,16 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
 import jetbrains.buildServer.TestLogger;
-import jetbrains.buildServer.vcs.CheckoutRules;
-import jetbrains.buildServer.vcs.CommitDataBean;
-import jetbrains.buildServer.vcs.VcsException;
-import jetbrains.buildServer.vcs.VcsRoot;
+import jetbrains.buildServer.vcs.*;
 import jetbrains.vcs.api.CommitInfo;
+import org.jetbrains.annotations.NotNull;
 import org.testng.Assert;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.*;
 
 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport;
 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository;
@@ -53,7 +48,12 @@
     VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();
 
 
-    final List<CommitDataBean> commitInfos = mySupport.collectCommits(root, CheckoutRules.DEFAULT);
+    final List<CommitInfo> commitInfos = new ArrayList<CommitInfo>();
+    mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() {
+      public void consumeCommit(@NotNull CommitInfo commit) {
+        commitInfos.add(commit);
+      }
+    });
     Assert.assertFalse(commitInfos.isEmpty());
 
     for (CommitInfo commitInfo : commitInfos) {
@@ -89,7 +89,12 @@
 
     VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();
 
-    final List<CommitDataBean> commitInfos = mySupport.collectCommits(root, CheckoutRules.DEFAULT);
+    final List<CommitInfo> commitInfos = new ArrayList<CommitInfo>();
+    mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() {
+      public void consumeCommit(@NotNull CommitInfo commit) {
+        commitInfos.add(commit);
+      }
+    });
     Assert.assertFalse(commitInfos.isEmpty());
 
     for (CommitInfo commitInfo : commitInfos) {