# HG changeset patch # User Dmitry Neverov # Date 1300259873 -10800 # Node ID 5013242d3af777d121d12fbd912d2cd630003494 # Parent 42bbe553bd8baa0d7196c5b1038035f66420cde2 Do clone directly to working dir instead of tmp dir diff -r 42bbe553bd8b -r 5013242d3af7 mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java --- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Fri Jan 21 09:56:06 2011 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Wed Mar 16 10:17:53 2011 +0300 @@ -21,7 +21,6 @@ import jetbrains.buildServer.agent.vcs.UpdateByIncludeRules; import jetbrains.buildServer.agent.vcs.UpdatePolicy; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.*; -import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.vcs.CheckoutRules; import jetbrains.buildServer.vcs.IncludeRule; import jetbrains.buildServer.vcs.VcsException; @@ -29,7 +28,6 @@ import org.jetbrains.annotations.NotNull; import java.io.File; -import java.io.IOException; public class MercurialAgentSideVcsSupport extends AgentVcsSupport implements UpdateByIncludeRules { private void updateWorkingDir(final Settings settings, final String version, final BuildProgressLogger logger) throws VcsException { @@ -41,51 +39,11 @@ logger.message("Working directory updated successfully"); } - private File cloneRepository(final Settings settings) throws VcsException { - File tempDir; - try { - File parent = FileUtil.createTempDirectory("hg", "clone"); - parent.deleteOnExit(); - tempDir = new File(parent, "hg"); - } catch (IOException e) { - throw new VcsException("Failed to create temp directory: " + e.getLocalizedMessage()); - } - + private void doClone(final Settings settings, final File workingDir) throws VcsException { CloneCommand cc = new CloneCommand(settings); - cc.setDestDir(tempDir.getAbsolutePath()); - + cc.setDestDir(workingDir.getAbsolutePath()); cc.setUpdateWorkingDir(false); cc.execute(); - return tempDir; - } - - /** - * Moves files from one directory to another with all subdirectories. - * Removes old directory if it became empty. - */ - private static boolean moveDir(File oldDir, File newDir) { - // both old and new directories exist - boolean moveSuccessful = true; - final File[] files = oldDir.listFiles(); - if (files != null) { - for (File file: files) { - if (file.isFile()) { - File destFile = new File(newDir, file.getName()); - destFile.getParentFile().mkdirs(); - if (!file.renameTo(destFile)) { - moveSuccessful = false; - } - } else if (!moveDir(file, new File(newDir, file.getName()))) { - moveSuccessful = false; - } - } - } - - if (moveSuccessful) { - FileUtil.deleteIfEmpty(oldDir); - } - - return moveSuccessful; } @NotNull @@ -112,26 +70,14 @@ Settings settings = new Settings(workingDir, vcsRoot); settings.setWorkingDir(workingDir); if (settings.hasCopyOfRepository()) { - // execute pull command logger.message("Repository in working directory found, start pulling changes"); PullCommand pc = new PullCommand(settings); pc.execute(); logger.message("Changes successfully pulled"); } else { - // execute clone command logger.message("No repository in working directory found, start cloning repository to temporary folder"); - File parentDir = cloneRepository(settings); - logger.message("Repository successfully cloned to: " + parentDir.getAbsolutePath()); - logger.message("Moving repository to working directory: " + workingDir.getAbsolutePath()); - if (!moveDir(parentDir, workingDir)) { - File hgDir = new File(workingDir, ".hg"); - if (hgDir.isDirectory()) { - FileUtil.delete(hgDir); - } - throw new VcsException("Failed to move directory content: " + parentDir.getAbsolutePath() + " to: " + workingDir.getAbsolutePath()); - } - - logger.message("Repository successfully moved to working directory: " + workingDir.getAbsolutePath()); + doClone(settings, workingDir); + logger.message("Repository successfully cloned to: " + workingDir.getAbsolutePath()); } updateWorkingDir(settings, toVersion, logger); }