# HG changeset patch # User Dmitry Neverov # Date 1362069484 -14400 # Node ID e7788cecf48b6c3f58da492fec2e6510d5dfdf7e # Parent 4f1c0ecc337186439495070d9c85f9fc8f1729c1 Move getFromRevisionsForBranch to OperationContext diff -r 4f1c0ecc3371 -r e7788cecf48b mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Thu Feb 28 19:13:52 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Thu Feb 28 20:38:04 2013 +0400 @@ -477,8 +477,8 @@ @NotNull RepositoryStateData toState, @NotNull CheckoutRules rules) throws VcsException { List changes = new ArrayList(); - OperationContext ctx = new OperationContext(this, myRepoFactory); - Set prevStateRevisions = new HashSet(fromState.getBranchRevisions().values()); + HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); + OperationContext ctx = new OperationContext(this, myRepoFactory, myHgPathProvider, fromState, toState); for (Map.Entry entry : toState.getBranchRevisions().entrySet()) { String branch = entry.getKey(); String toRevision = entry.getValue(); @@ -488,7 +488,7 @@ if (toRevision.equals(fromRevision)) continue; - List fromRevisions = getFromRevisionsForBranch(ctx, root, prevStateRevisions, fromRevision, toRevision); + List fromRevisions = ctx.getFromRevisionsForBranch(hgRoot, fromRevision, toRevision); List branchChanges = collectChanges(ctx, root, fromRevisions, toRevision, rules); for (ModificationData change : branchChanges) { if (!ctx.isReportedModification(change)) { @@ -502,52 +502,6 @@ } - /** - * 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: - * - * default - * | topic - * | | - * V V - *101 - * |\ - * | 100 - * | | - *99 | - *..... - * | | - * |/ - * 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. - * - * This method detects such a case and returns [99, 100] as fromRevisions for 101. - */ - @NotNull - private List getFromRevisionsForBranch(@NotNull OperationContext ctx, - @NotNull VcsRoot root, - @NotNull Set prevStateRevisions, - @NotNull String fromRevision, - @NotNull String toRevision) throws VcsException { - List fromRevisions = new ArrayList(); - fromRevisions.add(fromRevision); - - HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); - ctx.syncRepository(hgRoot); - ServerHgRepo repo = createRepo(ctx, hgRoot); - List parentRevisions = repo.parents().ofRevision(toRevision).call(); - for (String parent : parentRevisions) { - if (!fromRevision.equals(parent) && prevStateRevisions.contains(parent)) - fromRevisions.add(parent); - } - - return fromRevisions; - } - @NotNull public List collectChanges(@NotNull VcsRoot fromRoot, @NotNull String fromRootRevision, @NotNull VcsRoot toRoot, @Nullable String toRootRevision, @@ -594,7 +548,9 @@ } public List collectChanges(@NotNull VcsRoot root, @NotNull String fromVersion, @Nullable String currentVersion, @NotNull CheckoutRules checkoutRules) throws VcsException { - OperationContext ctx = new OperationContext(this, myRepoFactory); + if (currentVersion == null) + return emptyList(); + OperationContext ctx = new OperationContext(this, myRepoFactory, myHgPathProvider, fromVersion, currentVersion); List changes = collectChanges(ctx, root, asList(fromVersion), currentVersion, checkoutRules); changes.addAll(getSubrepoChanges(ctx, root, changes)); return changes; diff -r 4f1c0ecc3371 -r e7788cecf48b mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java Thu Feb 28 19:13:52 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java Thu Feb 28 20:38:04 2013 +0400 @@ -4,6 +4,7 @@ import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.AuthSettings; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; import jetbrains.buildServer.vcs.ModificationData; +import jetbrains.buildServer.vcs.RepositoryStateData; import jetbrains.buildServer.vcs.VcsException; import jetbrains.buildServer.vcs.VcsRoot; import org.jetbrains.annotations.NotNull; @@ -16,6 +17,9 @@ private final MercurialVcsSupport myVcs; private final RepoFactory myRepoFactory; + private final HgPathProvider myHgPathProvider; + private final RepositoryStateData myFromState; + private final RepositoryStateData myToState; private Set mySyncedDirs = new HashSet(); private Map myHgVersions = new HashMap(); private Map> myProcessedSubrepoChanges = new HashMap>();//subrepo url -> processed changes intervals @@ -23,11 +27,24 @@ private Map myRepos = new HashMap(); public OperationContext(@NotNull MercurialVcsSupport vcs, - @NotNull RepoFactory repoFactory) { + @NotNull RepoFactory repoFactory, + @NotNull HgPathProvider hgPathProvider, + @NotNull RepositoryStateData fromState, + @NotNull RepositoryStateData toState) { myVcs = vcs; myRepoFactory = repoFactory; + myHgPathProvider = hgPathProvider; + myFromState = fromState; + myToState = toState; } + public OperationContext(@NotNull MercurialVcsSupport vcs, + @NotNull RepoFactory repoFactory, + @NotNull HgPathProvider hgPathProvider, + @NotNull String fromVersion, + @NotNull String toVersion) { + this(vcs, repoFactory, hgPathProvider, RepositoryStateData.createSingleVersionState(fromVersion), RepositoryStateData.createSingleVersionState(toVersion)); + } public void syncRepository(@NotNull final HgVcsRoot root) throws VcsException { File dir = myVcs.getWorkingDir(root); @@ -98,6 +115,51 @@ return revisions; } + + /** + * 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: + * + * default + * | topic + * | | + * V V + *101 + * |\ + * | 100 + * | | + *99 | + *..... + * | | + * |/ + * 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. + * + * This method detects such a case and returns [99, 100] as fromRevisions for 101. + */ + @NotNull + public List getFromRevisionsForBranch(@NotNull HgVcsRoot root, + @NotNull String fromRevision, + @NotNull String toRevision) throws VcsException { + List fromRevisions = new ArrayList(); + fromRevisions.add(fromRevision); + + syncRepository(root); + + ServerHgRepo repo = createRepo(myVcs.getWorkingDir(root), myHgPathProvider.getHgPath(root), root.getAuthSettings()); + List parentRevisions = repo.parents().ofRevision(toRevision).call(); + for (String parent : parentRevisions) { + if (!fromRevision.equals(parent) && myFromState.getBranchRevisions().values().contains(parent)) + fromRevisions.add(parent); + } + + return fromRevisions; + } + private final static class SubrepoChangesInterval extends Pair, String> { private SubrepoChangesInterval(@NotNull List prevRevisions, @NotNull String currentRevision) { super(prevRevisions, currentRevision);