# HG changeset patch # User Pavel.Sher # Date 1255111425 -14400 # Node ID 2e9b1cfed366c4781375bc64e38e8171ec84c458 # Parent ac1dceb37faacff34e4e26ff5a65457641858736 fix checkout rules processing for server side patch diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Fri Oct 09 16:52:10 2009 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Fri Oct 09 22:03:45 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(); + } } } } diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Fri Oct 09 16:52:10 2009 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Fri Oct 09 22:03:45 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"); diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch1_checkout_rules/after/dir1/file1.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/patch1_checkout_rules/after/dir1/file1.txt Fri Oct 09 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +aaa \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch1_checkout_rules/after/dir1/file3.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/patch1_checkout_rules/after/dir1/file3.txt Fri Oct 09 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +ccc \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch1_checkout_rules/after/dir1/subdir/file2.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +bbb \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch1_checkout_rules/after/path/file3.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/patch1_checkout_rules/after/path/file3.txt Fri Oct 09 22:03:45 2009 +0400 @@ -0,0 +1,2 @@ +ccc +ddd diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch1_checkout_rules/before/dir1/file1.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/patch1_checkout_rules/before/dir1/file1.txt Fri Oct 09 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +aaa \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch1_checkout_rules/before/dir1/file3.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/testData/patch1_checkout_rules/before/dir1/file3.txt Fri Oct 09 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +ccc \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch1_checkout_rules/before/dir1/subdir/file2.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +bbb \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch3_checkout_rules1/after/path/dir with space/file with space.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +some text \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch3_checkout_rules1/after/path/dir1/file1.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +aaa \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch3_checkout_rules1/after/path/dir1/file3.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,2 @@ +ccc +ddd diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch3_checkout_rules1/after/path/dir1/subdir/file2.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,2 @@ +modified +bbb \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch3_checkout_rules1/after/path/file_in_branch.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +file from the test_branch \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch3_checkout_rules2/after/dir with space/file with space.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +some text \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch3_checkout_rules2/after/path/dir1/file1.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,1 @@ +aaa \ No newline at end of file diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch3_checkout_rules2/after/path/dir1/file3.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,2 @@ +ccc +ddd diff -r ac1dceb37faa -r 2e9b1cfed366 mercurial-tests/testData/patch3_checkout_rules2/after/path/dir1/subdir/file2.txt --- /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 22:03:45 2009 +0400 @@ -0,0 +1,2 @@ +modified +bbb \ No newline at end of file