Mercurial > hg > mercurial
changeset 556:e7788cecf48b
Move getFromRevisionsForBranch to OperationContext
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Thu, 28 Feb 2013 20:38:04 +0400 |
parents | 4f1c0ecc3371 |
children | 2b8299ba321d |
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, 69 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- 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<ModificationData> changes = new ArrayList<ModificationData>(); - OperationContext ctx = new OperationContext(this, myRepoFactory); - Set<String> prevStateRevisions = new HashSet<String>(fromState.getBranchRevisions().values()); + HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); + OperationContext ctx = new OperationContext(this, myRepoFactory, myHgPathProvider, fromState, toState); for (Map.Entry<String, String> entry : toState.getBranchRevisions().entrySet()) { String branch = entry.getKey(); String toRevision = entry.getValue(); @@ -488,7 +488,7 @@ if (toRevision.equals(fromRevision)) continue; - List<String> fromRevisions = getFromRevisionsForBranch(ctx, root, prevStateRevisions, fromRevision, toRevision); + List<String> fromRevisions = ctx.getFromRevisionsForBranch(hgRoot, fromRevision, toRevision); List<ModificationData> 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<String> getFromRevisionsForBranch(@NotNull OperationContext ctx, - @NotNull VcsRoot root, - @NotNull Set<String> prevStateRevisions, - @NotNull String fromRevision, - @NotNull String toRevision) throws VcsException { - List<String> fromRevisions = new ArrayList<String>(); - fromRevisions.add(fromRevision); - - HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); - ctx.syncRepository(hgRoot); - ServerHgRepo repo = createRepo(ctx, hgRoot); - List<String> 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<ModificationData> collectChanges(@NotNull VcsRoot fromRoot, @NotNull String fromRootRevision, @NotNull VcsRoot toRoot, @Nullable String toRootRevision, @@ -594,7 +548,9 @@ } public List<ModificationData> 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<ModificationData> changes = collectChanges(ctx, root, asList(fromVersion), currentVersion, checkoutRules); changes.addAll(getSubrepoChanges(ctx, root, changes)); return changes;
--- 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<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>>();//subrepo url -> processed changes intervals @@ -23,11 +27,24 @@ private Map<File, ServerHgRepo> myRepos = new HashMap<File, ServerHgRepo>(); 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<String> getFromRevisionsForBranch(@NotNull HgVcsRoot root, + @NotNull String fromRevision, + @NotNull String toRevision) throws VcsException { + List<String> fromRevisions = new ArrayList<String>(); + fromRevisions.add(fromRevision); + + syncRepository(root); + + ServerHgRepo repo = createRepo(myVcs.getWorkingDir(root), myHgPathProvider.getHgPath(root), root.getAuthSettings()); + List<String> 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<List<String>, String> { private SubrepoChangesInterval(@NotNull List<String> prevRevisions, @NotNull String currentRevision) { super(prevRevisions, currentRevision);