Mercurial > hg > mercurial
changeset 520:1ca68585ffce Faradi-7.1.x
Support mirrors for subrepos with relative paths
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Fri, 07 Dec 2012 21:54:45 +0400 |
parents | 9c22b0679417 |
children | 4f5273a54927 64d3b1f5ae6b |
files | mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java |
diffstat | 4 files changed, 64 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Fri Nov 30 17:24:32 2012 +0400 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Fri Dec 07 21:54:45 2012 +0400 @@ -13,6 +13,8 @@ import java.io.File; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Map; import static com.intellij.openapi.util.io.FileUtil.delete; @@ -152,42 +154,56 @@ Map<String, SubRepo> subrepos = repo.getSubrepositories(toVersion); for (Map.Entry<String, SubRepo> entry : subrepos.entrySet()) { String path = entry.getKey(); - SubRepo subrepo = entry.getValue(); - myLogger.message("Process subrepo at path " + path + " (url: " + subrepo.url() + ")"); + SubRepo subrepoConfig = entry.getValue(); + myLogger.message("Process subrepoConfig at path " + path + " (url: " + subrepoConfig.url() + ")"); SubRepo workingDirSubrepo = workingDirSubrepos.get(path); - if (workingDirSubrepo != null && subrepo.hasDifferentUrlThan(workingDirSubrepo)) { - myLogger.message("The url of subrepo was changed between revisions " + workingDirRevision + " and " + toVersion + " , delete the subrepo"); - delete(subrepo.dir()); + if (workingDirSubrepo != null && subrepoConfig.hasDifferentUrlThan(workingDirSubrepo)) { + myLogger.message("The url of subrepoConfig was changed between revisions " + workingDirRevision + " and " + toVersion + " , delete the subrepoConfig"); + delete(subrepoConfig.dir()); + } + HgRepo subrepository = myRepoFactory.create(subrepoConfig.dir(), myHgPath, myAuthSettings); + String subrepoUrl; + try { + subrepoUrl = subrepoConfig.isRelative() ? resolveUrl(parentRepositoryUrl, subrepoConfig.url()) : subrepoConfig.url(); + if (myUseLocalMirrors && subrepoConfig.vcsType() == SubRepo.VcsType.hg && !SubRepo.isRelativeUrl(subrepoUrl)) + syncSubrepo(subrepository, subrepoUrl, subrepoConfig.revision()); + } catch (URISyntaxException e) { + myLogger.warning("Failed to resolve subrepo url '" + subrepoConfig.url() + "': " + e.getMessage()); + subrepoUrl = subrepoConfig.url(); } - HgRepo subrepository = myRepoFactory.create(subrepo.dir(), myHgPath, myAuthSettings); - if (myUseLocalMirrors && subrepo.vcsType() == SubRepo.VcsType.hg) { - if (subrepo.isRelative()) { - myLogger.message("Subrepo url " + subrepo.url() + " is relative, subrepo will be updated during parent repository update"); - } else { - if (!subrepository.isValidRepository() || !subrepository.containsRevision(subrepo.revision())) { - updateLocalMirror(subrepo.url(), subrepo.revision()); - File mirrorDir = myMirrorManager.getMirrorDir(subrepo.url()); - if (subrepository.isValidRepository()) { - myLogger.message("Pull from local mirror"); - subrepository.pull().fromRepository(mirrorDir) - .withTraceback(myUseTraceback) - .withTimeout(myPullTimeout) - .call(); - myLogger.message("done"); - } else { - myLogger.message("Clone subrepo from local mirror"); - subrepository.doClone().fromRepository(mirrorDir) - .withTraceback(myUseTraceback) - .setUpdateWorkingDir(false) - .setUsePullProtocol(false) - .call(); - subrepository.setDefaultPath(subrepo.url()); - myLogger.message("done"); - } - } - } + updateSubrepositories(subrepository, subrepoConfig.revision(), subrepoUrl); + } + } + + 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); + File mirrorDir = myMirrorManager.getMirrorDir(url); + if (subrepository.isValidRepository()) { + myLogger.message("Pull from local mirror"); + subrepository.pull().fromRepository(mirrorDir) + .withTraceback(myUseTraceback) + .withTimeout(myPullTimeout) + .call(); + myLogger.message("done"); + } else { + myLogger.message("Clone subrepo from local mirror"); + subrepository.doClone().fromRepository(mirrorDir) + .withTraceback(myUseTraceback) + .setUpdateWorkingDir(false) + .setUsePullProtocol(false) + .call(); + subrepository.setDefaultPath(url); + myLogger.message("done"); } - updateSubrepositories(subrepository, subrepo.revision(), subrepo.url()); } }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Fri Nov 30 17:24:32 2012 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Fri Dec 07 21:54:45 2012 +0400 @@ -135,10 +135,14 @@ return myWorkingDir.isDirectory() && new File(myWorkingDir, ".hg").isDirectory(); } - public void setDefaultPath(@NotNull String defaultPath) { - File hgrc = new File(new File(myWorkingDir, ".hg"), "hgrc"); - String content = "[paths]\ndefault = " + defaultPath; - FileUtil.writeFile(hgrc, content); + public void setDefaultPath(@NotNull String defaultPath) throws VcsException { + try { + File hgrc = new File(new File(myWorkingDir, ".hg"), "hgrc"); + String content = "[paths]\ndefault = " + defaultPath; + FileUtil.writeFileAndReportErrors(hgrc, content); + } catch (IOException e) { + throw new VcsException(e); + } } public boolean hasSubreposAtRevision(@NotNull String revision) {
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java Fri Nov 30 17:24:32 2012 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java Fri Dec 07 21:54:45 2012 +0400 @@ -43,7 +43,11 @@ } public boolean isRelative() { - return myUrl.startsWith(".."); + return isRelativeUrl(myUrl); + } + + public static boolean isRelativeUrl(@NotNull String url) { + return url.startsWith(".."); } @NotNull
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java Fri Nov 30 17:24:32 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java Fri Dec 07 21:54:45 2012 +0400 @@ -99,8 +99,8 @@ copy(new File("mercurial-tests/testData/subrepos/r2")); copy(new File("mercurial-tests/testData/subrepos/r3")); VcsRootImpl root = vcsRoot().withUrl(myR1Dir.getAbsolutePath()).build(); - doUpdate(root, "34017377d9c3"); - doUpdate(root, "d350e7209906"); + doUpdate(root, "34017377d9c3", true); + doUpdate(root, "d350e7209906", true); }