# HG changeset patch # User Dmitry Neverov # Date 1294767526 -10800 # Node ID 43f4c91d5eaaf197151868e5bba3685851288790 # Parent 3a8af53dea6b2015daae850e38588613280ef5d0# Parent 7e36394a9c009d3bb17dd0099c9a05bd01f66ffc Implement BranchSupport interface diff -r 3a8af53dea6b -r 43f4c91d5eaa mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSet.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSet.java Tue Jan 11 18:16:49 2011 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSet.java Tue Jan 11 20:38:46 2011 +0300 @@ -109,4 +109,13 @@ public boolean containsFiles() { return myContainsFiles; } + + + /** + * Check if changeset is initial changeset (has no parents) + * @return true if changeset is initial changeset + */ + public boolean isInitial() { + return getParents() == null; + } } diff -r 3a8af53dea6b -r 43f4c91d5eaa mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java Tue Jan 11 18:16:49 2011 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java Tue Jan 11 20:38:46 2011 +0300 @@ -33,6 +33,7 @@ private String myFromId; private String myToId; private ArrayList myPaths; + private Integer myLimit = null; private static final String CHANGESET_PREFIX = "changeset:"; private static final String USER_PREFIX = "user:"; private static final String PARENT_PREFIX = "parent:"; @@ -57,6 +58,10 @@ myPaths = new ArrayList(relPaths); } + public void setLimit(final int limit) { + myLimit = limit; + } + public List execute() throws VcsException { GeneralCommandLine cli = createCommandLine(); cli.addParameter("log"); @@ -71,6 +76,10 @@ String to = myToId; if (to == null) to = "tip"; cli.addParameter(from + ":" + to); + if (myLimit != null) { + cli.addParameter("--limit"); + cli.addParameter(myLimit.toString()); + } if (myPaths != null) { for (String path: myPaths) { cli.addParameter(path); diff -r 3a8af53dea6b -r 43f4c91d5eaa mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Jan 11 18:16:49 2011 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Jan 11 20:38:46 2011 +0300 @@ -52,7 +52,7 @@ *

Working copy of repository is created in the $TEAMCITY_DATA_PATH/system/caches/hg_<hash code> folder. *

Personal builds (remote runs) are not yet supported, they require corresponding functionality from the IDE. */ -public class MercurialVcsSupport extends ServerVcsSupport implements LabelingSupport, VcsFileContentProvider { +public class MercurialVcsSupport extends ServerVcsSupport implements LabelingSupport, VcsFileContentProvider, BranchSupport { private ConcurrentMap myWorkDirLocks= new ConcurrentHashMap(); private VcsManager myVcsManager; private File myDefaultWorkFolderParent; @@ -412,6 +412,54 @@ } @NotNull + public String getRemoteRunOnBranchPattern() { + return "remote-run/{teamcity.user}/.+"; + } + + @NotNull + public Map getBranchesRevisions(@NotNull VcsRoot root) throws VcsException { + syncClonedRepository(root); + Settings settings = createSettings(root); + BranchesCommand branches = new BranchesCommand(settings); + Map result = new HashMap(); + for (Map.Entry entry : branches.execute().entrySet()) { + result.put(entry.getKey(), entry.getValue().getId()); + } + return result; + } + + @NotNull + public Map getBranchRootOptions(@NotNull VcsRoot root, @NotNull String branchName) { + final Map options = new HashMap(root.getProperties()); + options.put(Constants.BRANCH_NAME_PROP, branchName); + return options; + } + + public List collectChanges(@NotNull VcsRoot fromRoot, @NotNull String fromRootRevision, + @NotNull VcsRoot toRoot, @Nullable String toRootRevision, + @NotNull CheckoutRules checkoutRules) throws VcsException { + //we get all branches while clone, if vcs roots are related it is doesn't matter in which one search for branch point + syncClonedRepository(fromRoot); + String branchPoint = getBranchPoint(fromRoot, fromRootRevision, toRootRevision); + return ((CollectChangesByCheckoutRules) getCollectChangesPolicy()).collectChanges(toRoot, branchPoint, toRootRevision, checkoutRules); + } + + private String getBranchPoint(@NotNull VcsRoot root, String branchOneRev, String branchTwoRev) throws VcsException { + Settings settings = createSettings(root); + LogCommand lc = new LogCommand(settings); + lc.setFromRevId(new ChangeSetRevision(branchOneRev).getId()); + lc.setToRevId(new ChangeSetRevision(branchTwoRev).getId()); + lc.setLimit(1); + List changeSets = lc.execute(); + ChangeSet cs = changeSets.get(0); + if (cs.isInitial()) { + return cs.getId(); + } else { + return cs.getParents().get(0).getId(); + } + } + + @NotNull public CollectChangesPolicy getCollectChangesPolicy() { return new CollectChangesByCheckoutRules() { public List collectChanges(@NotNull VcsRoot root, @NotNull String fromVersion, @Nullable String currentVersion, @NotNull CheckoutRules checkoutRules) throws VcsException { diff -r 3a8af53dea6b -r 43f4c91d5eaa mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Tue Jan 11 18:16:49 2011 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Tue Jan 11 20:38:46 2011 +0300 @@ -84,14 +84,20 @@ return ((CollectChangesByCheckoutRules) myVcs.getCollectChangesPolicy()).collectChanges(vcsRoot, from, to, rules); } - private List collectChanges(@NotNull VcsRoot vcsRoot, @NotNull String from, @NotNull String to, @NotNull IncludeRule rule) throws VcsException { - return ((CollectChangesByIncludeRules)myVcs.getCollectChangesPolicy()).getChangeCollector(vcsRoot, from, to).collectChanges(rule); + public void test_collect_changes_between_two_same_roots() throws Exception { + VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); + VcsRootImpl sameVcsRoot = createVcsRoot(simpleRepo()); + List changes = myVcs.collectChanges(vcsRoot, "0:9875b412a788", sameVcsRoot, "3:9522278aa38d", new CheckoutRules("")); + do_check_for_collect_changes(changes); } public void test_collect_changes() throws Exception { VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); + List changes = collectChanges(vcsRoot, "0:9875b412a788", "3:9522278aa38d", new CheckoutRules("")); + do_check_for_collect_changes(changes); + } - List changes = collectChanges(vcsRoot, "0:9875b412a788", "3:9522278aa38d", new CheckoutRules("")); + private void do_check_for_collect_changes(List changes) throws Exception { assertEquals(3, changes.size()); ModificationData md1 = changes.get(0); @@ -337,6 +343,16 @@ return new File("mercurial-tests/testData/rep2").getAbsolutePath(); } + public void test_collect_changes_between_two_different_roots() throws Exception { + VcsRootImpl defaultRoot = createVcsRoot(mergeCommittsRepo()); + VcsRootImpl branchRoot = createVcsRoot(mergeCommittsRepo(), "test"); + List changes = myVcs.collectChanges(defaultRoot, "11:48177654181c", branchRoot, "10:fc524efc2bc4", CheckoutRules.DEFAULT); + assertEquals(changes.size(), 2); + + assertEquals("9:8c44244d6645", changes.get(0).getVersion()); + assertEquals("10:fc524efc2bc4", changes.get(1).getVersion()); + } + public void test_collect_changes_merge() throws Exception { VcsRootImpl vcsRoot = createVcsRoot(mergeCommittsRepo()); diff -r 3a8af53dea6b -r 43f4c91d5eaa mercurial.ipr --- a/mercurial.ipr Tue Jan 11 18:16:49 2011 +0300 +++ b/mercurial.ipr Tue Jan 11 20:38:46 2011 +0300 @@ -443,6 +443,7 @@ + diff -r 3a8af53dea6b -r 43f4c91d5eaa mercurial.properties --- a/mercurial.properties Tue Jan 11 18:16:49 2011 +0300 +++ b/mercurial.properties Tue Jan 11 20:38:46 2011 +0300 @@ -1,5 +1,4 @@ -path.variable.ant_home=C\:/Tools/apache-ant-1.7.1 -path.variable.maven_repository=C\:/Documents and Settings/pavel.sher/.m2/repository -path.variable.teamcitydistribution=C\:/TeamCity -path.variable.user_home_grails=C\:/Documents and Settings/pavel.sher/.grails -path.variable.user_home_griffon=C\:/Documents and Settings/pavel.sher/.griffon \ No newline at end of file +path.variable.maven_repository=/home/nd/.m2/repository +path.variable.teamcitydistribution=/home/nd/sandbox/TeamCity-Eluru +path.variable.path.to.idea.libs=/home/nd/sandbox/idea/idea-IU-98.319/lib +jdk.home.1.5=/opt/jdk1.5.0_18 \ No newline at end of file diff -r 3a8af53dea6b -r 43f4c91d5eaa mercurial.xml --- a/mercurial.xml Tue Jan 11 18:16:49 2011 +0300 +++ b/mercurial.xml Tue Jan 11 20:38:46 2011 +0300 @@ -1,563 +1,619 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file