changeset 79:2e57d4e3f7b7

support checkout rules for server side patch
author Pavel.Sher
date Fri, 09 Oct 2009 21:42:55 +0400
parents 1dcede89a079
children da3083345824
files mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OldTeamCityVersionSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java mercurial-tests/testData/patch1_checkout_rules/after/dir1/file1.txt mercurial-tests/testData/patch1_checkout_rules/after/dir1/file3.txt mercurial-tests/testData/patch1_checkout_rules/after/dir1/subdir/file2.txt mercurial-tests/testData/patch1_checkout_rules/after/path/file3.txt mercurial-tests/testData/patch1_checkout_rules/before/dir1/file1.txt mercurial-tests/testData/patch1_checkout_rules/before/dir1/file3.txt mercurial-tests/testData/patch1_checkout_rules/before/dir1/subdir/file2.txt mercurial-tests/testData/patch3_checkout_rules1/after/path/dir with space/file with space.txt mercurial-tests/testData/patch3_checkout_rules1/after/path/dir1/file1.txt mercurial-tests/testData/patch3_checkout_rules1/after/path/dir1/file3.txt mercurial-tests/testData/patch3_checkout_rules1/after/path/dir1/subdir/file2.txt mercurial-tests/testData/patch3_checkout_rules1/after/path/file_in_branch.txt mercurial-tests/testData/patch3_checkout_rules2/after/dir with space/file with space.txt mercurial-tests/testData/patch3_checkout_rules2/after/path/dir1/file1.txt mercurial-tests/testData/patch3_checkout_rules2/after/path/dir1/file3.txt mercurial-tests/testData/patch3_checkout_rules2/after/path/dir1/subdir/file2.txt mercurial.ipr
diffstat 20 files changed, 98 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Fri Oct 09 17:51:26 2009 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Fri Oct 09 21:42:55 2009 +0400
@@ -289,14 +289,14 @@
     syncClonedRepository(root);
     Settings settings = createSettings(root);
     if (fromVersion == null) {
-      buildFullPatch(settings, new ChangeSet(toVersion), builder);
+      buildFullPatch(settings, new ChangeSet(toVersion), builder, checkoutRules);
     } else {
-      buildIncrementalPatch(settings, new ChangeSet(fromVersion), new ChangeSet(toVersion), builder);
+      buildIncrementalPatch(settings, new ChangeSet(fromVersion), new ChangeSet(toVersion), builder, checkoutRules);
     }
   }
 
   // builds patch from version to version
-  private void buildIncrementalPatch(final Settings settings, @NotNull final ChangeSet fromVer, @NotNull final ChangeSet toVer, final PatchBuilder builder)
+  private void buildIncrementalPatch(final Settings settings, @NotNull final ChangeSet fromVer, @NotNull final ChangeSet toVer, final PatchBuilder builder, final CheckoutRules checkoutRules)
     throws VcsException, IOException {
     StatusCommand st = new StatusCommand(settings);
     st.setFromRevId(fromVer.getId());
@@ -317,7 +317,9 @@
 
     try {
       for (ModifiedFile f: modifiedFiles) {
-        final File virtualFile = new File(f.getPath());
+        String mappedPath = checkoutRules.map(f.getPath());
+        if (mappedPath == null) continue; // skip
+        final File virtualFile = new File(mappedPath);
         if (f.getStatus() == ModifiedFile.Status.REMOVED) {
           builder.deleteFile(virtualFile, true);
         } else {
@@ -336,7 +338,7 @@
   }
 
   // builds patch by exporting files using specified version
-  private void buildFullPatch(final Settings settings, @NotNull final ChangeSet toVer, final PatchBuilder builder)
+  private void buildFullPatch(final Settings settings, @NotNull final ChangeSet toVer, final PatchBuilder builder, final CheckoutRules checkoutRules)
     throws IOException, VcsException {
     CloneCommand cl = new CloneCommand(settings);
     // clone from the local repository
@@ -358,31 +360,34 @@
         public boolean accept(final File file) {
           return !(file.isDirectory() && ".hg".equals(file.getName()));
         }
-      });
+      }, checkoutRules);
     } finally {
       FileUtil.delete(tempDir);
     }
   }
 
-  private void buildPatchFromDirectory(final PatchBuilder builder, final File repRoot, final FileFilter filter) throws IOException {
-    buildPatchFromDirectory(repRoot, builder, repRoot, filter);
+  private void buildPatchFromDirectory(final PatchBuilder builder, final File repRoot, final FileFilter filter, final CheckoutRules checkoutRules) throws IOException {
+    buildPatchFromDirectory(repRoot, builder, repRoot, filter, checkoutRules);
   }
 
-  private void buildPatchFromDirectory(File curDir, final PatchBuilder builder, final File repRoot, final FileFilter filter) throws IOException {
+  private void buildPatchFromDirectory(File curDir, final PatchBuilder builder, final File repRoot, final FileFilter filter, final CheckoutRules checkoutRules) throws IOException {
     File[] files = curDir.listFiles(filter);
     if (files != null) {
       for (File realFile: files) {
         String relPath = realFile.getAbsolutePath().substring(repRoot.getAbsolutePath().length());
-        final File virtualFile = new File(relPath);
-        if (realFile.isDirectory()) {
-          builder.createDirectory(virtualFile);
-          buildPatchFromDirectory(realFile, builder, repRoot, filter);
-        } else {
-          final FileInputStream is = new FileInputStream(realFile);
-          try {
-            builder.createBinaryFile(virtualFile, null, is, realFile.length());
-          } finally {
-            is.close();
+        String mappedPath = checkoutRules.map(relPath);
+        if (mappedPath != null) {
+          final File virtualFile = new File(mappedPath);
+          if (realFile.isDirectory()) {
+            builder.createDirectory(virtualFile);
+            buildPatchFromDirectory(realFile, builder, repRoot, filter, checkoutRules);
+          } else {
+            final FileInputStream is = new FileInputStream(realFile);
+            try {
+              builder.createBinaryFile(virtualFile, null, is, realFile.length());
+            } finally {
+              is.close();
+            }
           }
         }
       }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OldTeamCityVersionSupport.java	Fri Oct 09 17:51:26 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-package jetbrains.buildServer.buildTriggers.vcs.mercurial;
-
-import jetbrains.buildServer.serverSide.SBuildServer;
-import jetbrains.buildServer.web.openapi.WebResourcesManager;
-
-/**
- * In previous versions of TeamCity jar files with web resources must be registered explicitly.
- */
-public class OldTeamCityVersionSupport {
-  public OldTeamCityVersionSupport(SBuildServer server, WebResourcesManager resManager) {
-    // register mercurial-server.jar for 3.x version of TeamCity only
-    if (server.getServerMajorVersion() == 3) {
-      resManager.addPluginResources(Constants.VCS_NAME, "mercurial.jar");
-    }
-  }
-}
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Fri Oct 09 17:51:26 2009 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Fri Oct 09 21:42:55 2009 +0400
@@ -150,6 +150,19 @@
     checkPatchResult(output.toByteArray());
   }
 
+  public void test_build_incremental_patch_checkout_rules() throws IOException, VcsException {
+    setName("patch1_checkout_rules");
+    VcsRootImpl vcsRoot = createVcsRoot();
+
+    final ByteArrayOutputStream output = new ByteArrayOutputStream();
+    final PatchBuilderImpl builder = new PatchBuilderImpl(output);
+
+    myVcs.buildPatch(vcsRoot, "3:9522278aa38d", "4:b06a290a363b", builder, new CheckoutRules("+:dir1=>path"));
+    builder.close();
+
+    checkPatchResult(output.toByteArray());
+  }
+
   public void test_build_incremental_patch_file_with_space() throws IOException, VcsException {
     setName("patch2");
     VcsRootImpl vcsRoot = createVcsRoot();
@@ -263,6 +276,32 @@
     checkPatchResult(output.toByteArray());
   }
 
+  public void test_full_patch_from_branch_with_checkout_rules() throws IOException, VcsException {
+    setName("patch3_checkout_rules1");
+    VcsRootImpl vcsRoot = createVcsRoot("test_branch");
+
+    final ByteArrayOutputStream output = new ByteArrayOutputStream();
+    final PatchBuilderImpl builder = new PatchBuilderImpl(output);
+
+    myVcs.buildPatch(vcsRoot, null, "7:376dcf05cd2a", builder, new CheckoutRules("+:.=>path"));
+    builder.close();
+
+    checkPatchResult(output.toByteArray());
+  }
+
+  public void test_full_patch_from_branch_with_checkout_rules_mapped_and_skipped() throws IOException, VcsException {
+    setName("patch3_checkout_rules2");
+    VcsRootImpl vcsRoot = createVcsRoot("test_branch");
+
+    final ByteArrayOutputStream output = new ByteArrayOutputStream();
+    final PatchBuilderImpl builder = new PatchBuilderImpl(output);
+
+    myVcs.buildPatch(vcsRoot, null, "7:376dcf05cd2a", builder, new CheckoutRules("+:dir1=>path/dir1\n+:dir with space"));
+    builder.close();
+
+    checkPatchResult(output.toByteArray());
+  }
+
   public void test_incremental_patch_from_branch() throws IOException, VcsException {
     setName("patch4");
     VcsRootImpl vcsRoot = createVcsRoot("test_branch");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch1_checkout_rules/after/dir1/file1.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+aaa
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch1_checkout_rules/after/dir1/file3.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+ccc
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch1_checkout_rules/after/dir1/subdir/file2.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+bbb
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch1_checkout_rules/after/path/file3.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,2 @@
+ccc
+ddd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch1_checkout_rules/before/dir1/file1.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+aaa
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch1_checkout_rules/before/dir1/file3.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+ccc
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch1_checkout_rules/before/dir1/subdir/file2.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+bbb
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch3_checkout_rules1/after/path/dir with space/file with space.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+some text
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch3_checkout_rules1/after/path/dir1/file1.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+aaa
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch3_checkout_rules1/after/path/dir1/file3.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,2 @@
+ccc
+ddd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch3_checkout_rules1/after/path/dir1/subdir/file2.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,2 @@
+modified
+bbb
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch3_checkout_rules1/after/path/file_in_branch.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+file from the test_branch
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch3_checkout_rules2/after/dir with space/file with space.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+some text
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch3_checkout_rules2/after/path/dir1/file1.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,1 @@
+aaa
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch3_checkout_rules2/after/path/dir1/file3.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,2 @@
+ccc
+ddd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch3_checkout_rules2/after/path/dir1/subdir/file2.txt	Fri Oct 09 21:42:55 2009 +0400
@@ -0,0 +1,2 @@
+modified
+bbb
\ No newline at end of file
--- a/mercurial.ipr	Fri Oct 09 17:51:26 2009 +0400
+++ b/mercurial.ipr	Fri Oct 09 21:42:55 2009 +0400
@@ -97,6 +97,20 @@
   </component>
   <component name="IdProvider" IDEtalkID="317BB29ECB7DA19EFFA340ECF52563C6" />
   <component name="InspectionProjectProfileManager">
+    <profiles>
+      <profile version="1.0" is_locked="false">
+        <option name="myName" value="Project Default" />
+        <option name="myLocal" value="false" />
+        <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
+          <option name="processCode" value="true" />
+          <option name="processLiterals" value="true" />
+          <option name="processComments" value="true" />
+        </inspection_tool>
+      </profile>
+    </profiles>
+    <option name="PROJECT_PROFILE" value="Project Default" />
+    <option name="USE_PROJECT_PROFILE" value="true" />
+    <version value="1.0" />
     <list size="5">
       <item index="0" class="java.lang.String" itemvalue="TYPO" />
       <item index="1" class="java.lang.String" itemvalue="INFO" />