changeset 796:e86aa7330709

Merge branch Gaya-8.1.x
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Mon, 19 May 2014 19:14:16 +0200
parents 249eb1d652a7 (current diff) 8f7862c1846e (diff)
children bc5d22baabec
files mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java
diffstat 2 files changed, 29 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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> T syncRepository(@NotNull HgVcsRoot root, @NotNull VcsCallable<T> 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> T syncRepositoryOnce(@NotNull HgVcsRoot root, @NotNull VcsCallable<T> 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)