changeset 334:01648f900892 Eluru-6.5.x

TW-16796, TW-16335 use hg archive to build full patch
author alex.davies
date Tue, 22 Nov 2011 10:30:40 +0000
parents d0edd172943f
children 092373ee11e5 e9aaa453b880
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ArchiveCommand.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java
diffstat 2 files changed, 97 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ArchiveCommand.java	Tue Nov 22 10:30:40 2011 +0000
@@ -0,0 +1,86 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
+
+import com.intellij.execution.configurations.GeneralCommandLine;
+import jetbrains.buildServer.ExecResult;
+import jetbrains.buildServer.util.FileUtil;
+import jetbrains.buildServer.vcs.VcsException;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+
+public class ArchiveCommand extends BaseCommand {
+  private File myDestDir;
+  private String myToId;
+
+  public ArchiveCommand(@NotNull final Settings settings, @NotNull final File workingDir) {
+    super(settings, workingDir);
+  }
+
+  public void setDestDir(@NotNull File destDir) {
+    myDestDir = destDir;
+  }
+
+  public void setToId(final String toId) {
+    myToId = toId;
+  }
+
+  public void execute() throws VcsException {
+    if (myDestDir == null)
+      throw new IllegalStateException("Destination dir must be specified");
+    GeneralCommandLine cli = createCommandLine();
+    cli.addParameter("archive");
+    setType(cli);
+    setRevision(cli);
+    setDestination(cli);
+    setSubRepos(cli);
+
+    ExecResult res = runCommand(cli);
+    failIfNotEmptyStdErr(cli, res);
+    deleteHgArchival();
+  }
+
+  private void setDestination(GeneralCommandLine cli) {
+    cli.addParameter(myDestDir.getAbsolutePath());
+  }
+
+  private void setRevision(GeneralCommandLine cli) {
+    cli.addParameter("-r");
+    if (myToId != null) {
+      cli.addParameter(myToId);
+    } else {
+      cli.addParameter("tip");
+    }
+  }
+
+  private void setType(GeneralCommandLine cli) {
+    cli.addParameter("-t");
+    cli.addParameter("files");
+  }
+
+  private void setSubRepos(GeneralCommandLine cli) {
+    cli.addParameter("-S");
+  }
+
+  /**
+   * hg archive generates .hg_archival.txt, delete it since original repository do not have such file
+   */
+  private void deleteHgArchival() {
+    if (myDestDir == null)
+      throw new IllegalStateException("Destination dir must be specified");
+    File hg_arhival = new File(myDestDir, ".hg_archival.txt");
+    FileUtil.delete(hg_arhival);
+  }
+}
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Thu Nov 03 10:28:00 2011 +0300
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Tue Nov 22 10:30:40 2011 +0000
@@ -33,7 +33,6 @@
 import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
-import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.*;
@@ -355,35 +354,22 @@
     File tempDir = FileUtil.createTempDirectory("mercurial", toVer.getId());
     try {
       File mirrorDir = getWorkingDir(settings);
-      final File repRoot = new File(tempDir, "rep");
-      CloneCommand cl = new CloneCommand(settings, repRoot);
-      // clone from the local repository
-      cl.setRepository(mirrorDir.getAbsolutePath());
-      cl.setToId(toVer.getId());
-      cl.setUpdateWorkingDir(false);
-      cl.setUsePullProtocol(myConfig.isUsePullProtocol());
-      cl.execute();
-
-      UpdateCommand up = new UpdateCommand(settings, repRoot);
-      up.setToId(toVer.getId());
-      up.execute();
-
-      buildPatchFromDirectory(builder, repRoot, new FileFilter() {
-        public boolean accept(final File file) {
-          return !(file.isDirectory() && ".hg".equals(file.getName()));
-        }
-      }, checkoutRules);
+      ArchiveCommand archive = new ArchiveCommand(settings, mirrorDir);
+      archive.setDestDir(tempDir);
+      archive.setToId(toVer.getId());
+      archive.execute();
+      buildPatchFromDirectory(builder, tempDir, checkoutRules);
     } finally {
       FileUtil.delete(tempDir);
     }
   }
 
-  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(final PatchBuilder builder, final File repRoot, final CheckoutRules checkoutRules) throws IOException {
+    buildPatchFromDirectory(repRoot, builder, repRoot, checkoutRules);
   }
 
-  private void buildPatchFromDirectory(File curDir, final PatchBuilder builder, final File repRoot, final FileFilter filter, final CheckoutRules checkoutRules) throws IOException {
-    File[] files = curDir.listFiles(filter);
+  private void buildPatchFromDirectory(File curDir, final PatchBuilder builder, final File repRoot, final CheckoutRules checkoutRules) throws IOException {
+    File[] files = curDir.listFiles();
     if (files != null) {
       for (File realFile: files) {
         String relPath = realFile.getAbsolutePath().substring(repRoot.getAbsolutePath().length());
@@ -392,7 +378,7 @@
           final File virtualFile = new File(mappedPath);
           if (realFile.isDirectory()) {
             builder.createDirectory(virtualFile);
-            buildPatchFromDirectory(realFile, builder, repRoot, filter, checkoutRules);
+            buildPatchFromDirectory(realFile, builder, repRoot, checkoutRules);
           } else {
             final FileInputStream is = new FileInputStream(realFile);
             try {
@@ -403,7 +389,7 @@
           }
         } else {
           if (realFile.isDirectory()) {
-            buildPatchFromDirectory(realFile, builder, repRoot, filter, checkoutRules);
+            buildPatchFromDirectory(realFile, builder, repRoot, checkoutRules);
           }
         }
       }