changeset 662:c3c0ebc63d77

CommitsInfoBuilder command now returns all commits without respect to state parameter (API update will follow)
author eugene.petrenko@gmail.com
date Mon, 30 Sep 2013 21:26:55 +0200
parents b5faf07c8171
children e01fa9602447
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java
diffstat 3 files changed, 18 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Mon Sep 30 23:14:26 2013 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Mon Sep 30 21:26:55 2013 +0200
@@ -37,6 +37,7 @@
 
   private final static Logger LOG = Logger.getInstance(LogCommand.class.getName());
   public final static String ZERO_PARENT_ID = "0000000000000000000000000000000000000000";
+  public final static String ZERO_PARENT_SHORT_ID = "000000000000";
   private final static SAXParserFactory ourSAXFactory = SAXParserFactory.newInstance();
 
   private String myFromId;
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java	Mon Sep 30 23:14:26 2013 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java	Mon Sep 30 21:26:55 2013 +0200
@@ -13,6 +13,7 @@
 import java.util.Map;
 
 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.LogCommand.ZERO_PARENT_ID;
+import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.LogCommand.ZERO_PARENT_SHORT_ID;
 
 /**
  * Created 30.09.13 13:05
@@ -34,17 +35,17 @@
   public List<CommitInfo> collectCommits(@NotNull VcsRoot root,
                                          @NotNull CheckoutRules rules,
                                          @NotNull RepositoryStateData headState) throws VcsException {
+    return collectCommits(root, rules);
+  }
+
+  @NotNull
+  public List<CommitInfo> 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 = new HashMap<String, CommitDataBean>();
-
-    //this could be implemented better with newer version of HG
-    //currently we have a process per head and next we merge commits via Java's in-memory map
-    for (String commitId : headState.getBranchRevisions().values()) {
-      commitToBean.putAll(processChanges(repo, commitId));
-    }
+    final Map<String, CommitDataBean> commitToBean = processChanges(repo);
 
     //collect tags info
     Map<String, String> tags = repo.tags().call();
@@ -57,10 +58,8 @@
   }
 
   @NotNull
-  private Map<String, CommitDataBean> processChanges(@NotNull ServerHgRepo repo, @NotNull final String head) throws VcsException {
+  private Map<String, CommitDataBean> processChanges(@NotNull ServerHgRepo repo) throws VcsException {
     final List<ChangeSet> tip = repo.logNoFiles()
-            .fromRevision("0")
-            .toRevision(head)
             .showCommitsFromAllBranches()
             .call();
 
@@ -71,6 +70,7 @@
         final String commitId = p.getId();
 
         if (ZERO_PARENT_ID.equals(commitId)) continue;
+        if (ZERO_PARENT_SHORT_ID.equals(commitId)) continue;
         bean.addParentRevision(commitId);
       }
       bean.addBranch(set.getBranch());
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java	Mon Sep 30 23:14:26 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java	Mon Sep 30 21:26:55 2013 +0200
@@ -1,13 +1,11 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
 import jetbrains.buildServer.TestLogger;
-import jetbrains.buildServer.util.CollectionsUtil;
 import jetbrains.buildServer.vcs.CheckoutRules;
-import jetbrains.buildServer.vcs.RepositoryStateData;
 import jetbrains.buildServer.vcs.VcsException;
 import jetbrains.buildServer.vcs.VcsRoot;
 import jetbrains.vcs.api.CommitInfo;
-import junit.framework.Assert;
+import org.testng.Assert;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -37,6 +35,7 @@
   public void setUp() throws Exception {
     super.setUp();
     ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder()
+//            .hgPath("hg")
             .cachesDir(myTempFiles.createTempDir())
             .build();
     MercurialSupportBuilder mercurialBuilder = mercurialSupport().withConfig(pluginConfig);
@@ -52,9 +51,8 @@
 
     VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();
 
-    final String v = "4780519e01aa"; ///30
 
-    final List<CommitInfo> commitInfos = mySupport.collectCommits(root, CheckoutRules.DEFAULT, RepositoryStateData.createVersionState("default", CollectionsUtil.asMap("default", v)));
+    final List<CommitInfo> commitInfos = mySupport.collectCommits(root, CheckoutRules.DEFAULT);
     Assert.assertFalse(commitInfos.isEmpty());
 
     for (CommitInfo commitInfo : commitInfos) {
@@ -74,24 +72,23 @@
       parents.addAll(commitInfo.getParentRevisions());
     }
 
-    Assert.assertEquals(branches, new TreeSet<String>(Arrays.asList("default", "personal-branch", "test", "topic")));
+    Assert.assertEquals(branches, new TreeSet<String>(Arrays.asList("default", "personal-branch", "test", "topic", "<TEST> Branch with exitics)(*&^%$#@!", "NULL")));
     Assert.assertEquals(tags, new TreeSet<String>(Arrays.asList("t1")));
 
     //check all parent commits are included into the set
-    Assert.assertTrue(commits.containsAll(parents));
+    Assert.assertTrue(commits.containsAll(parents), "Unknown commits: " + new TreeSet<String>(parents){{removeAll(commits);}});
 
-    //head should be head
+    final String v = "4780519e01aa"; ///30
     Assert.assertFalse(parents.contains(v));
   }
 
-
   @Test
   public void should_not_have_parse_errors() throws IOException, VcsException {
     TestLogger.enableMainAndVCSLoggerDebug();
 
     VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();
 
-    final List<CommitInfo> commitInfos = mySupport.collectCommits(root, CheckoutRules.DEFAULT, myVcs.getCollectChangesPolicy().getCurrentState(root));
+    final List<CommitInfo> commitInfos = mySupport.collectCommits(root, CheckoutRules.DEFAULT);
     Assert.assertFalse(commitInfos.isEmpty());
 
     for (CommitInfo commitInfo : commitInfos) {