changeset 412:5d4351306d57

Build full patch if cannot build incremental one
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Tue, 20 Mar 2012 18:49:33 +0400
parents 490024d8e5fd
children aa76a036b6b6
files mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java mercurial-tests/testData/patch6/after/dir with space/file with space.txt mercurial-tests/testData/patch6/after/file_in_branch.txt mercurial-tests/testData/patch6/after/path/dir1/file1.txt mercurial-tests/testData/patch6/after/path/dir1/file3.txt mercurial-tests/testData/patch6/after/path/dir1/subdir/file2.txt mercurial-tests/testData/patch6/before/dir with space/file with space.txt mercurial-tests/testData/patch6/before/file_in_branch.txt
diffstat 9 files changed, 39 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Tue Mar 20 18:25:43 2012 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Tue Mar 20 18:49:33 2012 +0400
@@ -51,7 +51,7 @@
  * <p>Personal builds (remote runs) are not yet supported, they require corresponding functionality from the IDE.
  */
 public class MercurialVcsSupport extends ServerVcsSupport implements LabelingSupport, VcsFileContentProvider, BranchSupport,
-        CollectChangesBetweenRoots {
+        CollectChangesBetweenRoots, BuildPatchByCheckoutRules {
   private final VcsManager myVcsManager;
   private final File myDefaultWorkFolderParent;
   private final MirrorManager myMirrorManager;
@@ -617,21 +617,30 @@
 
   @NotNull
   public BuildPatchPolicy getBuildPatchPolicy() {
-    return new BuildPatchByCheckoutRules() {
-      public void buildPatch(@NotNull final VcsRoot root,
-                             @Nullable final String fromVersion,
-                             @NotNull final String toVersion,
-                             @NotNull final PatchBuilder builder,
-                             @NotNull final CheckoutRules checkoutRules) throws IOException, VcsException {
-        Settings settings = createSettings(root);
-        syncRepository(settings);
-        if (fromVersion == null) {
-          buildFullPatch(settings, new ChangeSet(toVersion), builder, checkoutRules);
-        } else {
-          buildIncrementalPatch(settings, new ChangeSet(fromVersion), new ChangeSet(toVersion), builder, checkoutRules);
-        }
+    return this;
+  }
+
+  public void buildPatch(@NotNull VcsRoot root, @Nullable String fromVersion, @NotNull String toVersion, @NotNull PatchBuilder builder, @NotNull CheckoutRules checkoutRules) throws IOException, VcsException {
+    Settings settings = createSettings(root);
+    syncRepository(settings);
+    ChangeSet to = new ChangeSet(toVersion);
+    if (fromVersion == null) {
+      buildFullPatch(settings, new ChangeSet(toVersion), builder, checkoutRules);
+    } else {
+      ChangeSet from = new ChangeSet(fromVersion);
+      HgRepo repo = createRepo(settings);
+      if (!repo.containsRevision(from)) {
+        Loggers.VCS.info("Cannot find revision " + fromVersion + " in repository " + settings.getRepository() + ", will build a full patch");
+        cleanCheckoutDir(builder, checkoutRules);
+        buildFullPatch(settings, to, builder, checkoutRules);
+      } else {
+        buildIncrementalPatch(settings, new ChangeSet(fromVersion), new ChangeSet(toVersion), builder, checkoutRules);
       }
-    };
+    }
+  }
+
+  private void cleanCheckoutDir(@NotNull PatchBuilder builder, @NotNull CheckoutRules checkoutRules) throws IOException {
+    builder.deleteDirectory(new File(checkoutRules.map("")), true);
   }
 
   private void lockWorkDir(@NotNull File workDir) {
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Tue Mar 20 18:25:43 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Tue Mar 20 18:49:33 2012 +0400
@@ -125,8 +125,7 @@
   private ByteArrayOutputStream buildPatch(VcsRoot vcsRoot, String from, String to, CheckoutRules rules) throws IOException, VcsException {
     final ByteArrayOutputStream output = new ByteArrayOutputStream();
     final PatchBuilderImpl builder = new PatchBuilderImpl(output);
-
-    ((BuildPatchByCheckoutRules)myVcs.getBuildPatchPolicy()).buildPatch(vcsRoot, from, to, builder, rules);
+    myVcs.buildPatch(vcsRoot, from, to, builder, rules);
     builder.close();
     return output;
   }
@@ -398,6 +397,13 @@
     checkPatchResult(output.toByteArray());
   }
 
+  public void build_patch_from_unknown_revision() throws Exception {
+    setName("patch6");
+    VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
+    ByteArrayOutputStream output = buildPatch(vcsRoot, "6:hahahahahaha", "3:9522278aa38d", new CheckoutRules("+:.=>path"));
+    checkPatchResult(output.toByteArray());
+  }
+
   private String mergeCommittsRepo() {
     return new File("mercurial-tests/testData/rep2").getAbsolutePath();
   }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/patch6/after/dir with space/file with space.txt	Tue Mar 20 18:49:33 2012 +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/patch6/after/file_in_branch.txt	Tue Mar 20 18:49:33 2012 +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/patch6/after/path/dir1/file1.txt	Tue Mar 20 18:49:33 2012 +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/patch6/after/path/dir1/file3.txt	Tue Mar 20 18:49:33 2012 +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/patch6/after/path/dir1/subdir/file2.txt	Tue Mar 20 18:49:33 2012 +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/patch6/before/dir with space/file with space.txt	Tue Mar 20 18:49:33 2012 +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/patch6/before/file_in_branch.txt	Tue Mar 20 18:49:33 2012 +0400
@@ -0,0 +1,1 @@
+file from the test_branch
\ No newline at end of file