# HG changeset patch # User Dmitry Neverov # Date 1356768658 -14400 # Node ID e9de7632c0d48d9d0dc07fe7e65cd1d73e81e604 # Parent 6de7b8ad3f8dd2fed742a3d31f25425030d61b21 Fix BranchSupport diff -r 6de7b8ad3f8d -r e9de7632c0d4 mercurial-server-tc/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialBranchSupport.java --- a/mercurial-server-tc/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialBranchSupport.java Tue Dec 18 18:40:44 2012 +0400 +++ b/mercurial-server-tc/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialBranchSupport.java Sat Dec 29 12:10:58 2012 +0400 @@ -1,78 +1,12 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.ChangeSet; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; import jetbrains.buildServer.vcs.*; -import jetbrains.buildServer.vcs.impl.VcsRootImpl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.List; -import java.util.Map; public class MercurialBranchSupport implements BranchSupport, MercurialServerExtension { - - private HgVcsRootFactory myHgRootFactory; - private MercurialVcsSupport myMercurialSupport; - - public MercurialBranchSupport() { - } - - public void setMercurialSupport(@NotNull MercurialVcsSupport mercurialSupport) { - myMercurialSupport = mercurialSupport; - } - - public void setHgRootFactory(@NotNull HgVcsRootFactory hgRootFactory) { - myHgRootFactory = hgRootFactory; - } - @NotNull public String getRemoteRunOnBranchPattern() { return "remote-run/*"; } - - @NotNull - public RepositoryStateData getCurrentState(@NotNull VcsRoot repository) throws VcsException { - return myMercurialSupport.getCurrentState(repository); - } - - @NotNull - public Map getBranchRootOptions(@NotNull VcsRoot original, @NotNull String branchName) { - final Map options = new HashMap(original.getProperties()); - options.put(Constants.BRANCH_NAME_PROP, branchName); - return options; - } - - @Nullable - public PersonalBranchDescription getPersonalBranchDescription(@NotNull VcsRoot original, @NotNull String branchName) throws VcsException { - HgVcsRoot hgRoot = myHgRootFactory.createHgRoot(original); - VcsRoot branchRoot = createBranchRoot(original, branchName); - String baseVersion = myMercurialSupport.getCurrentVersion(original); - String branchVersion = myMercurialSupport.getCurrentVersion(branchRoot); - String mergeBase = myMercurialSupport.getMergeBase(hgRoot, baseVersion, branchVersion); - - if (mergeBase == null) - return null; - - List changeSets = myMercurialSupport.createRepo(hgRoot) - .log() - .fromRevision(mergeBase) - .toRevision(branchVersion) - .showCommitsFromAllBranches() - .call(); - if (changeSets.size() > 1) {//when branch points to the commit in original branch we get 1 cset - String branchId = changeSets.get(1).getId(); - String username = changeSets.get(changeSets.size() - 1).getUser(); - return new PersonalBranchDescription(branchId, username); - } else { - return null; - } - } - - private VcsRoot createBranchRoot(VcsRoot original, String branchName) { - VcsRootImpl result = new VcsRootImpl(original.getId(), original.getProperties()); - result.addProperty(Constants.BRANCH_NAME_PROP, branchName); - return result; - } }