Mercurial > hg > mercurial
changeset 649:0b50d7952a7d
TW-23468 support tags as branches
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java Thu Sep 26 16:28:57 2013 +0400 @@ -29,6 +29,7 @@ String UNCOMPRESSED_TRANSFER = "uncompressedTransfer"; String USER_FOR_TAG = "tagUsername"; String DETECT_SUBREPO_CHANGES = "detectSubrepoChanges"; + String USE_TAGS_AS_BRANCHES = "useTagsAsBranches"; String GLOBAL_DETECT_SUBREPO_CHANGES = "teamcity.hg.detectSubrepoChanges"; }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Thu Sep 26 16:28:57 2013 +0400 @@ -73,8 +73,14 @@ return new BookmarksCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings); } - public Map<String, String> getBranchRevisions(boolean includeBookmarks) throws VcsException { + public TagsCommand tags() { + return new TagsCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings); + } + + public Map<String, String> getBranchRevisions(boolean includeBookmarks, boolean includeTags) throws VcsException { Map<String, String> revisions = new HashMap<String, String>(); + if (includeTags) + revisions.putAll(tags().call()); if (includeBookmarks && version().call().isEqualsOrGreaterThan(BookmarksCommand.REQUIRED_HG_VERSION)) revisions.putAll(bookmarks().call()); revisions.putAll(branches().call());
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java Thu Sep 26 16:28:57 2013 +0400 @@ -43,6 +43,7 @@ private final AuthSettings myAuthSettings; private File myCustomWorkingDir; private final boolean myDetectSubrepoChanges; + private final boolean myUseTagsAsBranches; public HgVcsRoot(@NotNull final VcsRoot vcsRoot) { this(vcsRoot.getProperties()); @@ -58,6 +59,7 @@ myUserForTag = getProperty(Constants.USER_FOR_TAG); myAuthSettings = new AuthSettings(getProperty(Constants.USERNAME), getProperty(Constants.PASSWORD)); myDetectSubrepoChanges = Boolean.parseBoolean(getProperty(Constants.DETECT_SUBREPO_CHANGES)); + myUseTagsAsBranches = Boolean.parseBoolean(getProperty(Constants.USE_TAGS_AS_BRANCHES)); } public HgVcsRoot withUrl(@NotNull String repositoryUrl) { @@ -129,6 +131,10 @@ return myDetectSubrepoChanges; } + public boolean useTagsAsBranches() { + return myUseTagsAsBranches; + } + public boolean isSubrepo() { return Boolean.valueOf(getProperty("teamcity.internal.subrepo")); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/TagsCommand.java Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,30 @@ +package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; + +import jetbrains.buildServer.vcs.VcsException; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.util.Map; + +public class TagsCommand extends BranchesCommand { + + public TagsCommand(@NotNull CommandSettings commandSettings, + @NotNull String hgPath, + @NotNull File workingDir, + @NotNull AuthSettings authSettings) { + super(commandSettings, hgPath, workingDir, authSettings); + } + + @NotNull + @Override + protected String getBranchesCommand() { + return "tags"; + } + + @Override + public Map<String, String> call() throws VcsException { + Map<String, String> raw = super.call(); + raw.remove("tip"); + return raw; + } +}
--- a/mercurial-server/resources/buildServerResources/mercurialSettings.jsp Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-server/resources/buildServerResources/mercurialSettings.jsp Thu Sep 26 16:28:57 2013 +0400 @@ -28,6 +28,13 @@ </tr> <bs:branchSpecTableRow/> <tr> + <th><label for="reportTagRevisions">Use tags as branches:</label></th> + <td> + <props:checkboxProperty name="useTagsAsBranches"/> + <div class="smallNote" style="margin: 0">If enabled tags can be used in branch specification</div> + </td> + </tr> + <tr> <th><label for="serverClonePath">Clone repository to: </label></th> <td><props:textProperty name="serverClonePath" className="longField"/> <div class="smallNote" style="margin: 0;">Provide path to a parent directory on TeamCity server where a cloned repository should be created (applicable to "Automatically on server" checkout mode only). Leave blank to use default path.</div>
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CheckoutRepository.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CheckoutRepository.java Thu Sep 26 16:28:57 2013 +0400 @@ -21,6 +21,7 @@ private final MirrorManager myMirrorManager; private final HgRepoFactory myHgRepoFactory; private final int myPullTimeout; + private boolean myGlobalTagsAsBranches; private final HgVcsRoot myRoot; private final File myWorkingDir; private String myRevision; @@ -29,6 +30,7 @@ CheckoutRepository(@NotNull MirrorManager mirrorManager, @NotNull HgRepoFactory hgRepoFactory, int pullTimeout, + boolean globalTagsAsBranches, @NotNull HgVcsRoot root, @NotNull File workingDir) { myMirrorManager = mirrorManager; @@ -58,7 +60,8 @@ updateRepository(root, workingDir, revision); if (revision == null && myBranch != null) { HgRepo repo = myHgRepoFactory.createRepo(root, workingDir); - Map<String, String> revisions = repo.getBranchRevisions(true); + boolean includeTags = myGlobalTagsAsBranches && root.useTagsAsBranches(); + Map<String, String> revisions = repo.getBranchRevisions(true, includeTags); revision = revisions.get(myBranch); } if (revision == null)
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCollectChangesPolicy.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCollectChangesPolicy.java Thu Sep 26 16:28:57 2013 +0400 @@ -43,7 +43,8 @@ public RepositoryStateData getCurrentState(@NotNull VcsRoot root) throws VcsException { HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); myVcs.syncRepository(hgRoot); - Map<String, String> revisions = myVcs.createRepo(hgRoot).getBranchRevisions(myConfig.bookmarksEnabled()); + boolean includeTags = myConfig.useTagsAsBranches() && hgRoot.useTagsAsBranches(); + Map<String, String> revisions = myVcs.createRepo(hgRoot).getBranchRevisions(myConfig.bookmarksEnabled(), includeTags); String defaultBranchName = hgRoot.getBranchName(); if (revisions.get(defaultBranchName) == null) { throw new VcsException("Cannot find revision of the default branch '" +
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialMergeSupport.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialMergeSupport.java Thu Sep 26 16:28:57 2013 +0400 @@ -47,7 +47,7 @@ for (MergeTask task : tasks) { MergeResult result = new MergeResult(); try { - new CheckoutRepository(myMirrorManager, myHgRepoFactory, myConfig.getPullTimeout(), hgRoot, tmpDir) + new CheckoutRepository(myMirrorManager, myHgRepoFactory, myConfig.getPullTimeout(), myConfig.useTagsAsBranches(), hgRoot, tmpDir) .setRevision(task.getDestinationRevision()).checkout(); repo.merge().revision(task.getSourceRevision()).call(); } catch (MergeConflictException e) { @@ -85,7 +85,7 @@ tmpDir = HgFileUtil.createTempDir(); HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); - new CheckoutRepository(myMirrorManager, myHgRepoFactory, myConfig.getPullTimeout(), hgRoot, tmpDir) + new CheckoutRepository(myMirrorManager, myHgRepoFactory, myConfig.getPullTimeout(), myConfig.useTagsAsBranches(), hgRoot, tmpDir) .setBranch(dstBranch).checkout(); HgRepo repo = myHgRepoFactory.createRepo(hgRoot, tmpDir);
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java Thu Sep 26 16:28:57 2013 +0400 @@ -3,8 +3,6 @@ import org.jetbrains.annotations.Nullable; import org.quartz.CronExpression; -import java.util.Set; - /** * @author dmitry.neverov */ @@ -23,6 +21,8 @@ public boolean bookmarksEnabled(); + public boolean useTagsAsBranches(); + public int getMaxDagNodesCount(); public int getLogOutputLimit();
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java Thu Sep 26 16:28:57 2013 +0400 @@ -67,6 +67,10 @@ return TeamCityProperties.getBooleanOrTrue("teamcity.hg.enableBookmarks"); } + public boolean useTagsAsBranches() { + return TeamCityProperties.getBooleanOrTrue("teamcity.hg.useTagsAsBranches"); + } + public long getMirrorExpirationTimeoutMillis() { int days = TeamCityProperties.getInteger("teamcity.hg.mirrorExpirationTimeoutDays", 7); return days * Dates.ONE_DAY;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java Thu Sep 26 16:28:57 2013 +0400 @@ -17,6 +17,7 @@ private boolean myDontUseRevsets = false; private boolean myDetectSubrepoChanges = true; private long myMirrorExpirationTimeout; + private boolean myTagsAsBranches = true; @NotNull public ServerPluginConfig build() { @@ -53,6 +54,10 @@ return true; } + public boolean useTagsAsBranches() { + return myTagsAsBranches; + } + public int getMaxDagNodesCount() { return 0; } @@ -114,4 +119,9 @@ myMirrorExpirationTimeout = timeoutMillis; return this; } + + public ServerPluginConfigBuilder withTagsAsBranches(boolean tagsAsBranches) { + myTagsAsBranches = tagsAsBranches; + return this; + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/TagsTest.java Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,73 @@ +package jetbrains.buildServer.buildTriggers.vcs.mercurial; + +import jetbrains.buildServer.vcs.RepositoryStateData; +import jetbrains.buildServer.vcs.VcsRoot; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.IOException; + +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.BookmarksTest.RepositoryStateDataMatcher.hasBranch; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.BookmarksTest.RepositoryStateDataMatcher.hasNoBranch; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.ServerPluginConfigBuilder.serverPluginConfig; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.not; + +@Test +public class TagsTest extends BaseMercurialTestCase { + + private File myRemoteRepository; + private ServerPluginConfigBuilder myConfig; + + @BeforeMethod + public void setUp() throws Exception { + super.setUp(); + myConfig = serverPluginConfig() + .cachesDir(myTempFiles.createTempDir()) + .hgPath(Util.getHgPath()); + + myRemoteRepository = myTempFiles.createTempDir(); + Util.copyRepository(new File("mercurial-tests/testData/tags"), myRemoteRepository); + } + + public void no_tags_reported_by_default() throws Exception { + VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).build(); + RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); + assertThat(state, not(hasBranch("v1").withRevision("fa7ad5b80a88"))); + assertThat(state, not(hasBranch("v4").withRevision("f7fbcc489e40"))); + } + + public void should_report_tag_revisions() throws Exception { + VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build(); + RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); + assertThat(state, hasBranch("v1").withRevision("fa7ad5b80a88")); + assertThat(state, hasBranch("v4").withRevision("f7fbcc489e40")); + } + + public void branch_has_higher_precedence_over_tag() throws Exception { + VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build(); + RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); + assertThat(state, hasBranch("topic").withRevision("efde33cd0b66")); + } + + public void tags_can_be_turned_off_globally() throws Exception { + myConfig.withTagsAsBranches(false); + VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build(); + RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); + assertThat(state, not(hasBranch("v1").withRevision("fa7ad5b80a88"))); + assertThat(state, not(hasBranch("v4").withRevision("f7fbcc489e40"))); + } + + public void tags_should_not_include_tip() throws Exception { + VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build(); + RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); + assertThat(state, hasNoBranch("tip")); + } + + private MercurialVcsSupport getVcs() throws IOException { + return mercurialSupport().withConfig(myConfig.build()).build(); + } +}
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java Thu Sep 26 16:28:57 2013 +0400 @@ -1,13 +1,14 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial; -import java.io.File; -import java.io.IOException; import jetbrains.buildServer.vcs.SVcsRoot; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import org.jetbrains.annotations.NotNull; import org.jmock.Expectations; import org.jmock.Mockery; +import java.io.File; +import java.io.IOException; + /** * @author dmitry.neverov */ @@ -23,6 +24,7 @@ private boolean myUncompressed = true; private File myCloneRepositoryTo; private boolean myDetectSubrepoChanges = false; + private boolean myTagsAsBranches = false; public static VcsRootBuilder vcsRoot() { return new VcsRootBuilder(); @@ -40,6 +42,7 @@ vcsRoot.addProperty(Constants.DETECT_SUBREPO_CHANGES, String.valueOf(myDetectSubrepoChanges)); if (myCloneRepositoryTo != null) vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, String.valueOf(myCloneRepositoryTo.getAbsolutePath())); + vcsRoot.addProperty(Constants.USE_TAGS_AS_BRANCHES, String.valueOf(myTagsAsBranches)); return vcsRoot; } @@ -58,6 +61,7 @@ allowing(root).getProperty(with(Constants.UNCOMPRESSED_TRANSFER)); will(returnValue(null)); allowing(root).getProperty(with(Constants.USER_FOR_TAG)); will(returnValue(myUserForTag)); allowing(root).getProperty(with(Constants.DETECT_SUBREPO_CHANGES)); will(returnValue(String.valueOf(myDetectSubrepoChanges))); + allowing(root).getProperty(with(Constants.USE_TAGS_AS_BRANCHES)); will(returnValue(String.valueOf(myTagsAsBranches))); }}); if (myCloneRepositoryTo != null) { context.checking(new Expectations() {{ @@ -126,4 +130,10 @@ myDetectSubrepoChanges = detectSubrepoChanges; return this; } + + + public VcsRootBuilder withTagsEnabled(boolean useTagsAsBranches) { + myTagsAsBranches = useTagsAsBranches; + return this; + } }
--- a/mercurial-tests/src/testng.xml Wed Sep 25 13:27:18 2013 +0400 +++ b/mercurial-tests/src/testng.xml Thu Sep 26 16:28:57 2013 +0400 @@ -33,6 +33,7 @@ <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.HgVcsRootFactoryTest"/> <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.SubRepoTest"/> <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.MergeSupportTest"/> + <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.TagsTest"/> </classes> </test> </suite>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/README Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,19 @@ + o 9:72902de1ba45 +tag topic -> 3256c19d708b + | +o | 8:efde33cd0b66 (topic) +tag v1 -> fa7ad5b80a88 +| | +| o | 7:210d711041da (topic2) +tag v1 -> b86ee8b83781 +| | | +| o | 6:b86ee8b83781 (topic2) +| | | +| | o 5:3256c19d708b +tag v4 -> f7fbcc489e40 +| | | +| | o 4:f7fbcc489e40 +| |/ +o | 3:fa7ad5b80a88 (topic) +tag v1 -> 6c3929c66c32 +| | +o | 2:6c3929c66c32 (topic) +|/ +o 1:b6e596caff9d +tag v1 -> 1ecfad722425 +| +o 0:1ecfad722425
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/hg/branch Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,1 @@ +default
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/hg/cache/branchheads-served Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,4 @@ +72902de1ba4503a2acabdac782dd1baedc56c590 9 +72902de1ba4503a2acabdac782dd1baedc56c590 default +efde33cd0b66ae0fb22031ae49890ed8291d54b0 topic +210d711041da69982df2472bdbae12d3da50b7eb topic2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/hg/cache/tags Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,11 @@ +9 72902de1ba4503a2acabdac782dd1baedc56c590 e2013c4534f7af87eba501437ab756184ce06738 +8 efde33cd0b66ae0fb22031ae49890ed8291d54b0 16b0ff5750dd8451acd25496c85e8ee8827f02c8 +7 210d711041da69982df2472bdbae12d3da50b7eb 9b2a39cbdbc150021d3769e20b8f75affa52af84 + +3256c19d708b4efae92b281b386876eab63d4b7e topic +1ecfad72242555475feeefe00643a834cae04b15 v1 +1ecfad72242555475feeefe00643a834cae04b15 v1 +6c3929c66c328e85039f7588fc9344f93e0bd04b v1 +b86ee8b83781935bca1c5ee4ffe7f3b6f12923f2 v1 +fa7ad5b80a88c64f8f32d1b7a0cc96fb2a5092ae v1 +f7fbcc489e403a950ddba6e4a7b1674b60d66c65 v4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/hg/last-message.txt Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,1 @@ +Added tag topic for changeset 3256c19d708b \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/hg/requires Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,4 @@ +dotencode +fncache +revlogv1 +store
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/hg/store/fncache Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,2 @@ +data/.hgtags.i +data/a.i
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/hg/store/phaseroots Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,1 @@ +1 1ecfad72242555475feeefe00643a834cae04b15
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/hg/store/undo.phaseroots Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,1 @@ +1 1ecfad72242555475feeefe00643a834cae04b15
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/tags/hg/undo.branch Thu Sep 26 16:28:57 2013 +0400 @@ -0,0 +1,1 @@ +default \ No newline at end of file