changeset 675:1d417eb6ea28

Add an option for excluding subrepos from patch
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Wed, 20 Nov 2013 15:41:19 +0400
parents 61da07eceaa1
children 54d319ca0237
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java
diffstat 3 files changed, 32 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java	Fri Nov 15 13:28:45 2013 +0100
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java	Wed Nov 20 15:41:19 2013 +0400
@@ -30,6 +30,7 @@
   String USER_FOR_TAG = "tagUsername";
   String DETECT_SUBREPO_CHANGES = "detectSubrepoChanges";
   String USE_TAGS_AS_BRANCHES = "useTagsAsBranches";
+  String INCLUDE_SUBREPOS_IN_PATCH = "includeSubreposInPatch";
 
   String GLOBAL_DETECT_SUBREPO_CHANGES = "teamcity.hg.detectSubrepoChanges";
 }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java	Fri Nov 15 13:28:45 2013 +0100
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java	Wed Nov 20 15:41:19 2013 +0400
@@ -43,6 +43,7 @@
   private File myCustomWorkingDir;
   private final boolean myDetectSubrepoChanges;
   private final boolean myUseTagsAsBranches;
+  private final boolean myIncludeSubreposInPatch;
 
   public HgVcsRoot(@NotNull final VcsRoot vcsRoot) {
     this(vcsRoot.getProperties());
@@ -59,6 +60,8 @@
     myAuthSettings = new AuthSettings(getProperty(Constants.USERNAME), getProperty(Constants.PASSWORD));
     myDetectSubrepoChanges = Boolean.parseBoolean(getProperty(Constants.DETECT_SUBREPO_CHANGES));
     myUseTagsAsBranches = Boolean.parseBoolean(getProperty(Constants.USE_TAGS_AS_BRANCHES));
+    String includeSubreposProp = getProperty(Constants.INCLUDE_SUBREPOS_IN_PATCH);
+    myIncludeSubreposInPatch = includeSubreposProp == null ? true : Boolean.parseBoolean(includeSubreposProp);//true by default
   }
 
   public HgVcsRoot withUrl(@NotNull String repositoryUrl) {
@@ -75,6 +78,10 @@
     return myRepository;
   }
 
+  public boolean includeSubreposInPatch() {
+    return myIncludeSubreposInPatch;
+  }
+
   /**
    * Returns name of the branch to use (returns 'default' if no branch specified)
    * @return see above
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Fri Nov 15 13:28:45 2013 +0100
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Wed Nov 20 15:41:19 2013 +0400
@@ -254,7 +254,8 @@
           }
         }
       }
-      buildSubrepoPatch(root, fromVer, toVer, builder, checkoutRules, repo);
+      if (root.includeSubreposInPatch())
+        buildSubrepoPatch(root, fromVer, toVer, builder, checkoutRules, repo);
     } finally {
       deleteDir(parentDir, Loggers.VCS);
     }
@@ -321,22 +322,28 @@
     File tempDir = HgFileUtil.createTempDir();
     try {
       HgRepo repo = createRepo(root);
-      Map<String, SubRepo> subrepos = repo.getSubrepositories(toVer);
-      if (!subrepos.isEmpty()) {
-        Loggers.VCS.debug("Repository '" + root.getRepository() + "' has submodules at revision " + toVer.getId() + ", use 'hg clone' to build clean patch");
-        File mirrorDir = getWorkingDir(root);
-        HgRepo cloneOfTheMirror = createRepo(root, tempDir);
-        cloneOfTheMirror.doClone().fromRepository(mirrorDir)
-                .setUpdateWorkingDir(false)
-                .setUsePullProtocol(false)
-                .useUncompressedTransfer(false)
-                .call();
-        cloneOfTheMirror.setDefaultPath(root.getRepository());
-        cloneSubrepos(root, tempDir, subrepos);
-        cloneOfTheMirror.update().toRevision(toVer).call();
-        buildPatchFromDirectory(builder, tempDir, checkoutRules, myIgnoreDotHgFilter);
+      if (root.includeSubreposInPatch()) {
+        Map<String, SubRepo> subrepos = repo.getSubrepositories(toVer);
+        if (!subrepos.isEmpty()) {
+          Loggers.VCS.debug("Repository '" + root.getRepository() + "' has subrepos at revision " + toVer.getId() + ", use 'hg clone' to build clean patch");
+          File mirrorDir = getWorkingDir(root);
+          HgRepo cloneOfTheMirror = createRepo(root, tempDir);
+          cloneOfTheMirror.doClone().fromRepository(mirrorDir)
+                  .setUpdateWorkingDir(false)
+                  .setUsePullProtocol(false)
+                  .useUncompressedTransfer(false)
+                  .call();
+          cloneOfTheMirror.setDefaultPath(root.getRepository());
+          cloneSubrepos(root, tempDir, subrepos);
+          cloneOfTheMirror.update().toRevision(toVer).call();
+          buildPatchFromDirectory(builder, tempDir, checkoutRules, myIgnoreDotHgFilter);
+        } else {
+          Loggers.VCS.debug("Repository '" + root.getRepository() + "' doesn't have subrepos at revision " + toVer.getId() + ", use 'hg archive' to build clean patch");
+          repo.archive().revision(toVer).toDir(tempDir).call();
+          buildPatchFromDirectory(builder, tempDir, checkoutRules, myAcceptAllFilter);
+        }
       } else {
-        Loggers.VCS.debug("Repository '" + root.getRepository() + "' doesn't have submodules at revision " + toVer.getId() + ", use 'hg archive' to build clean patch");
+        Loggers.VCS.debug("Subrepos disabled in VCS root, use 'hg archive' to build clean patch");
         repo.archive().revision(toVer).toDir(tempDir).call();
         buildPatchFromDirectory(builder, tempDir, checkoutRules, myAcceptAllFilter);
       }
@@ -647,6 +654,7 @@
     Map<String, String> rootProperties = root.getProperties();
     Map<String, String> repositoryProperties = new HashMap<String, String>();
     repositoryProperties.put(Constants.REPOSITORY_PROP, rootProperties.get(Constants.REPOSITORY_PROP));
+    repositoryProperties.put(Constants.INCLUDE_SUBREPOS_IN_PATCH, rootProperties.get(Constants.INCLUDE_SUBREPOS_IN_PATCH));
     return repositoryProperties;
   }