# HG changeset patch # User Dmitry Neverov # Date 1400519656 -7200 # Node ID e86aa7330709387cd1390273876aa660c5b0ae00 # Parent 249eb1d652a7f1ac10c387e67e36f7606bef3136# Parent 8f7862c1846e3525a968140d60aa6953304f67dc Merge branch Gaya-8.1.x diff -r 249eb1d652a7 -r e86aa7330709 mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java --- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Thu May 01 19:55:03 2014 +0200 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Mon May 19 19:14:16 2014 +0200 @@ -23,6 +23,7 @@ import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.exception.UnrelatedRepositoryException; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.exception.WrongSubrepoUrlException; +import jetbrains.buildServer.log.Loggers; import jetbrains.buildServer.vcs.IncludeRule; import jetbrains.buildServer.vcs.VcsException; import jetbrains.buildServer.vcs.VcsRoot; @@ -179,6 +180,7 @@ syncSubrepo(subrepository, subrepoUrl, subrepoConfig.revision()); } catch (WrongSubrepoUrlException e) { myLogger.warning("Failed to resolve subrepo url '" + subrepoConfig.url() + "': " + e.getMessage()); + Loggers.VCS.warn("Failed to resolve subrepo url '" + subrepoConfig.url() + "'", e); subrepoUrl = subrepoConfig.url(); } updateSubrepositories(subrepository, subrepoConfig.revision(), subrepoUrl); diff -r 249eb1d652a7 -r e86aa7330709 mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Thu May 01 19:55:03 2014 +0200 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Mon May 19 19:14:16 2014 +0200 @@ -546,25 +546,42 @@ } public T syncRepository(@NotNull HgVcsRoot root, @NotNull VcsCallable cmd) throws VcsException { + boolean customWorkingDir = root.getCustomWorkingDir() != null; File workingDir = getWorkingDir(root); + int attemptsLeft = 3; + VcsException lastError = null; + while (attemptsLeft-- > 0) { + try { + return syncRepositoryOnce(root, cmd, workingDir); + } catch (UnrelatedRepositoryException e) { + if (customWorkingDir) + throw new VcsException(e.getMessage() + ". VCS root uses a custom clone dir, manual recovery is required.", e); + Loggers.VCS.warn("Repository at " + workingDir.getAbsolutePath() + " is unrelated to " + root.getRepository() + + ". Clone it again, attempts left " + attemptsLeft); + myMirrorManager.forgetDir(workingDir); + lastError = e; + } catch (AbandonedTransactionFound e) { + if (customWorkingDir) + throw new VcsException(e.getMessage() + ". VCS root uses a custom clone dir, manual recovery is required.", e); + Loggers.VCS.warn("Abandoned transaction found in repository " + root.getRepository() + " at " + + workingDir.getAbsolutePath() + ". Clone it again, attempts left " + attemptsLeft); + myMirrorManager.forgetDir(workingDir); + lastError = e; + } + } + throw lastError; + } + + + private T syncRepositoryOnce(@NotNull HgVcsRoot root, @NotNull VcsCallable cmd, @NotNull File workingDir) throws VcsException { lockWorkDir(workingDir); HgRepo repo = createRepo(root); try { if (repo.isValidRepository()) { - try { resetBookmarks(repo); repo.pull().fromRepository(root.getRepository()) .withTimeout(myConfig.getPullTimeout()) .call(); - } catch (UnrelatedRepositoryException e) { - Loggers.VCS.warn("Repository at " + root.getRepository() + " is unrelated, clone it again"); - myMirrorManager.forgetDir(workingDir); - syncRepository(root); - } catch (AbandonedTransactionFound e) { - Loggers.VCS.warn("Abandoned transaction found in repository " + root.getRepository() + ", clone it again"); - myMirrorManager.forgetDir(workingDir); - syncRepository(root); - } } else { repo.doClone().fromRepository(root.getRepository()) .setUpdateWorkingDir(false)