changeset 560:a1c15a8cec64

Optimization works only for hg with revsets
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Fri, 01 Mar 2013 18:59:41 +0400
parents 7744e1643109
children 35098f0c8fda
files mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java
diffstat 4 files changed, 33 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Fri Mar 01 17:40:16 2013 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Fri Mar 01 18:59:41 2013 +0400
@@ -488,7 +488,7 @@
       if (toRevision.equals(fromRevision))
         continue;
 
-      Collection<String> fromRevisions = ctx.getFromRevisionsForBranch(hgRoot, toRevision);
+      Collection<String> fromRevisions = ctx.getFromRevisionsForBranch(hgRoot, fromRevision, toRevision);
       List<ModificationData> branchChanges = collectChanges(ctx, root, fromRevisions, toRevision, rules);
       for (ModificationData change : branchChanges) {
         if (!ctx.isReportedModification(change)) {
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java	Fri Mar 01 17:40:16 2013 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java	Fri Mar 01 18:59:41 2013 +0400
@@ -2,7 +2,6 @@
 
 import com.intellij.openapi.util.Pair;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.AuthSettings;
-import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.ChangeSetRevision;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot;
 import jetbrains.buildServer.util.graph.*;
 import jetbrains.buildServer.vcs.ModificationData;
@@ -15,6 +14,8 @@
 import java.io.File;
 import java.util.*;
 
+import static java.util.Collections.singleton;
+
 public class OperationContext {
 
   private final MercurialVcsSupport myVcs;
@@ -120,16 +121,18 @@
 
 
   /**
-   * Collecting changes is per branch. We usually take branch revision in fromState,
-   * revision in toState and collect changes between them. This can lead to redundant
-   * changes being reported. Consider the following graph:
+   * Collecting changes is per branch, but we should take revisions of other branches
+   * into account otherwise plugin can report redundant changes. Consider the following graph:
    *
    * default
    * | topic
    * |  |
    * V  V
-   *101
-   * |\
+   *103
+   * | 102
+   * | |
+   *101|
+   * |\|
    * | 100
    * | |
    *99 |
@@ -138,17 +141,23 @@
    * |/
    * 1
    *
-   * When changes are collected between states {default:99, topic:100} and {default: 101, topic:100},
-   * plugin reports changes from 1 to 101, even though it probably has reported changes reachable
-   * from 100 earlier.
+   * Let's say plugin collects changes between states {default:99, topic:100} and {default: 103, topic:102}.
+   * If we run hg log -r 'ancestors(103)-ancestors(99)' it will return changes [1..103]. But changes
+   * [1..100] were probably already reported and TeamCity will not persist them.
    *
-   * This method detects such a case and returns [99, 100] as fromRevisions for 101.
+   * This method detects such a cases and returns (99, 100) for 103.
    */
   @NotNull
-  public Collection<String> getFromRevisionsForBranch(@NotNull HgVcsRoot root, @NotNull String toRevision) throws VcsException {
-    Set<String> fromRevisions = new HashSet<String>();
+  public Collection<String> getFromRevisionsForBranch(@NotNull HgVcsRoot root,
+                                                      @NotNull String fromRevision,
+                                                      @NotNull String toRevision) throws VcsException {
     syncRepository(root);
     ServerHgRepo repo = createRepo(myVcs.getWorkingDir(root), myHgPathProvider.getHgPath(root), root.getAuthSettings());
+
+    if (!repo.supportRevsets())
+      return singleton(fromRevision);
+
+    Set<String> fromRevisions = new HashSet<String>();
     if (myToState.getBranchRevisions().size() > 1) {
       VcsRootKey rootKey = VcsRootKey.create(root);
       DAG<String> dag = myDags.get(rootKey);
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java	Fri Mar 01 17:40:16 2013 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java	Fri Mar 01 18:59:41 2013 +0400
@@ -76,6 +76,11 @@
     }
   }
 
+  public boolean supportRevsets() throws VcsException {
+    HgVersion hgVersion = getHgVersion();
+    return hgVersion.isEqualsOrGreaterThan(REVSET_HG_VERSION);
+  }
+
   private HgVersion getHgVersion() throws VcsException {
     if (myContext != null)
       return myContext.getHgVersion(this);
@@ -91,7 +96,6 @@
 
   @NotNull
   public DAG<String> loadDag() throws VcsException {
-//    List<Pair<ChangeSetRevision, ChangeSetRevision>> edges = new LoadDagCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings, myDagTemplate).call();
     List<Pair<String, String>> edges = new LoadDagCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings, myDagTemplate).call();
     return DAGs.createFromEdges(edges);
   }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Fri Mar 01 17:40:16 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Fri Mar 01 18:59:41 2013 +0400
@@ -604,7 +604,9 @@
   }
 
 
-  public void should_not_report_duplicate_changes() throws Exception {
+  @RequiredHgVersion(min = "1.7.0")
+  @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion")
+  public void should_not_report_duplicate_changes(@NotNull HgVersion _) throws Exception {
     VcsRootImpl root = createVcsRoot(myRep2Path);
     List<ModificationData> changes = myVcs.collectChanges(root,
             RepositoryStateData.createVersionState("default", map("default", "505c5b9d01e6", "personal-branch", "96b78d73081d")),
@@ -614,7 +616,9 @@
   }
 
 
-  public void should_not_report_duplicate_changes2() throws Exception {
+  @RequiredHgVersion(min = "1.7.0")
+  @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion")
+  public void should_not_report_duplicate_changes2(@NotNull HgVersion _) throws Exception {
     VcsRootImpl root = createVcsRoot(myRep2Path);
     List<ModificationData> changes = myVcs.collectChanges(root,
             RepositoryStateData.createVersionState("default", map("default", "528572bbf77b", "personal-branch", "27184c50d7ef")),