Mercurial > hg > mercurial
changeset 538:8468457fe4d3
Report subrepo changes - initial version
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Tue, 29 Jan 2013 20:53:19 +0400 |
parents | 5fa123e185b3 |
children | 0983cbb59637 |
files | mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubrepoChangesTest.java |
diffstat | 7 files changed, 80 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Tue Jan 29 20:35:17 2013 +0400 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Tue Jan 29 20:53:19 2013 +0400 @@ -164,7 +164,7 @@ HgRepo subrepository = myRepoFactory.create(subrepoConfig.dir(), myHgPath, myAuthSettings); String subrepoUrl; try { - subrepoUrl = subrepoConfig.isRelative() ? resolveUrl(parentRepositoryUrl, subrepoConfig.url()) : subrepoConfig.url(); + subrepoUrl = subrepoConfig.resolveUrl(parentRepositoryUrl); if (myUseLocalMirrors && subrepoConfig.vcsType() == SubRepo.VcsType.hg && !SubRepo.isRelativeUrl(subrepoUrl)) syncSubrepo(subrepository, subrepoUrl, subrepoConfig.revision()); } catch (URISyntaxException e) { @@ -175,14 +175,6 @@ } } - private String resolveUrl(@NotNull String parentRepoUrl, @NotNull String relativeUrl) throws URISyntaxException { - if (!parentRepoUrl.endsWith("/")) - parentRepoUrl = parentRepoUrl + "/"; - URI parentURI = new URI(parentRepoUrl); - URI subrepoAbsUrl = parentURI.resolve(relativeUrl); - return subrepoAbsUrl.toString(); - } - private void syncSubrepo(@NotNull HgRepo subrepository, @NotNull String url, @NotNull String revision) throws VcsException, IOException { if (!subrepository.isValidRepository() || !subrepository.containsRevision(revision)) { updateLocalMirror(url, revision);
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java Tue Jan 29 20:35:17 2013 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java Tue Jan 29 20:53:19 2013 +0400 @@ -3,6 +3,8 @@ import org.jetbrains.annotations.NotNull; import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; /** * @author dmitry.neverov @@ -61,6 +63,16 @@ return !myUrl.equals(other.url()); } + public String resolveUrl(@NotNull String parentRepoUrl) throws URISyntaxException { + if (!isRelative()) + return url(); + if (!parentRepoUrl.endsWith("/")) + parentRepoUrl = parentRepoUrl + "/"; + URI parentURI = new URI(parentRepoUrl); + URI subrepoAbsUrl = parentURI.resolve(url()); + return subrepoAbsUrl.toString(); + } + @Override public String toString() { return myPath + " = " + myUrl + "#" + myRevision;
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Jan 29 20:35:17 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Jan 29 20:53:19 2013 +0400 @@ -543,6 +543,8 @@ for (ChangeSet cset : getChangesets(hgRoot, fromVersion, currentVersion)) { result.add(createModificationData(cset, root, checkoutRules)); } + if (myConfig.reportSubrepoConfigUpdates()) + addSubrepoConfigChanges(hgRoot, result); return result; } @@ -599,6 +601,35 @@ } } + private void addSubrepoConfigChanges(@NotNull HgVcsRoot root, @NotNull List<ModificationData> changes) { + try { + ServerHgRepo repo = createRepo(root); + for (ModificationData change : changes) { + List<SubRepoConfigChange> subrepoConfigChanges = repo.getSubrepoConfigChanges(change.getVersion()); + int i = 1; + for (SubRepoConfigChange c : subrepoConfigChanges) { + if (c.getCurrent() != null && c.getPrevious() != null && c.getCurrent().url().equals(c.getPrevious().url())) { + String subrepoUrl = c.getCurrent().resolveUrl(root.getRepository()); + + HgVcsRoot subrepoRoot = root.withUrl(subrepoUrl); + syncRepository(subrepoRoot); + ServerHgRepo subrepo = createRepo(subrepoRoot); + String prevRevision = subrepo.id().revision(c.getPrevious().revision()).inLocalRepository().call(); + String curRevision = subrepo.id().revision(c.getCurrent().revision()).inLocalRepository().call(); + + change.setAttribute("subrepo." + i + ".rootDiff." + Constants.REPOSITORY_PROP, subrepoUrl); + change.setAttribute("subrepo." + i + ".path", c.getPath()); + change.setAttribute("subrepo." + i + ".oldRevision", prevRevision); + change.setAttribute("subrepo." + i + ".newRevision", curRevision); + i++; + } + } + } + } catch (Exception e) { + Loggers.VCS.warn("Error while reporting subrepo config changes", e); + } + } + @NotNull private List<ChangeSet> getSubrepoChangesets(@NotNull HgVcsRoot root, @NotNull HgRepo repo,
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java Tue Jan 29 20:35:17 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java Tue Jan 29 20:53:19 2013 +0400 @@ -24,5 +24,7 @@ public boolean detectSubrepoChanges(); + public boolean reportSubrepoConfigUpdates(); + public boolean bookmarksEnabled(); }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java Tue Jan 29 20:35:17 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java Tue Jan 29 20:53:19 2013 +0400 @@ -73,6 +73,10 @@ return false; } + public boolean reportSubrepoConfigUpdates() { + return TeamCityProperties.getBooleanOrTrue("teamcity.hg.reportSubrepoConfigUpdates"); + } + public boolean bookmarksEnabled() { return TeamCityProperties.getBooleanOrTrue("teamcity.hg.enableBookmarks"); }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java Tue Jan 29 20:35:17 2013 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java Tue Jan 29 20:53:19 2013 +0400 @@ -16,6 +16,7 @@ private File myCachesDir; private boolean myDontUseRevsets = false; private boolean myDetectSubrepoChanges = false; + private boolean myReportSubrepoConfigUpdates = false; @NotNull public ServerPluginConfig build() { @@ -53,6 +54,10 @@ return myDetectSubrepoChanges; } + public boolean reportSubrepoConfigUpdates() { + return myReportSubrepoConfigUpdates; + } + public boolean bookmarksEnabled() { return true; } @@ -88,4 +93,9 @@ myDetectSubrepoChanges = doDetect; return this; } + + public ServerPluginConfigBuilder reportSubrepoConfigUpdates(boolean doReport) { + myReportSubrepoConfigUpdates = doReport; + return this; + } }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubrepoChangesTest.java Tue Jan 29 20:35:17 2013 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubrepoChangesTest.java Tue Jan 29 20:53:19 2013 +0400 @@ -13,6 +13,7 @@ import java.io.File; import java.io.IOException; import java.util.List; +import java.util.Map; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; @@ -94,4 +95,23 @@ List<ModificationData> changes = myVcs.collectChanges(root, "d350e7209906", "09c256b6163e", CheckoutRules.DEFAULT); assertEquals(3, changes.size()); } + + + public void report_subrepo_config_updates_in_attributes() throws Exception { + ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder() + .cachesDir(myTempFiles.createTempDir()) + .reportSubrepoConfigUpdates(true) + .dontUseRevsets() + .build(); + myVcs = mercurialSupport().withConfig(pluginConfig).build(); + VcsRoot root = vcsRoot().withUrl(myRemoteRepo1.getAbsolutePath()).build(); + List<ModificationData> changes = myVcs.collectChanges(root, "09c256b6163e", "d64d9799c143", CheckoutRules.DEFAULT); + assertEquals(1, changes.size()); + ModificationData m = changes.get(0); + Map<String, String> attrs = m.getAttributes(); + assertEquals(new File(myRemoteRepo1.getParentFile(), "r3").getAbsolutePath(), attrs.get("subrepo.1.rootDiff." + Constants.REPOSITORY_PROP)); + assertEquals("r2", attrs.get("subrepo.1.path")); + assertEquals("514c3e09cddf", attrs.get("subrepo.1.newRevision")); + assertEquals("ebb884b1b691", attrs.get("subrepo.1.oldRevision")); + } }