changeset 743:ff89f023a3c8

change Cat command commandline size (select max possible value)
author eugene.petrenko@jetbrains.com
date Mon, 27 Jan 2014 17:35:50 +0100
parents 091667cc54d5
children 789802ac672d
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OS.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CatCommand.java
diffstat 2 files changed, 50 insertions(+), 4 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/OS.java	Mon Jan 27 17:35:50 2014 +0100
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * 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;
+
+import jetbrains.buildServer.serverSide.TeamCityProperties;
+
+/**
+ * Created 27.01.14 17:21
+ *
+ * @author Eugene Petrenko (eugene.petrenko@jetbrains.com)
+ */
+public class OS {
+  private static final int COMMAND_LINE_LIMIT = _COMMAND_LINE_LIMIT();
+
+  private static int _COMMAND_LINE_LIMIT() {
+    final String OS_NAME = System.getProperty("os.name").toLowerCase();
+    ///http://partmaps.org/era/unix/arg-max.html
+    if (!OS_NAME.startsWith("windows")) return 128 * 1024 - 1; //128kb
+
+    //http://support.microsoft.com/kb/830473/en-us
+    if (OS_NAME.matches("windows\\s+(2000|xp|nt)")) {
+      return 2047;
+    }
+
+    return 8191;
+  }
+
+  public static int getMaxCommandLineSize() {
+    return TeamCityProperties.getInteger("teamcity.mercurial.maxCommandLineSize", COMMAND_LINE_LIMIT);
+  }
+}
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CatCommand.java	Mon Jan 27 13:27:26 2014 +0100
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CatCommand.java	Mon Jan 27 17:35:50 2014 +0100
@@ -16,6 +16,7 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgFileUtil;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.OS;
 import jetbrains.buildServer.log.Loggers;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
@@ -32,7 +33,7 @@
 
 public class CatCommand extends VcsRootCommand {
   private String myRevId;
-  private final static int MAX_CMD_LEN = 900;
+
   private List<String> myRelativePaths = new ArrayList<String>();
   private boolean myCheckForFailure = true;
 
@@ -109,13 +110,13 @@
     Queue<String> paths = new LinkedList<String>(relPaths);
     while (!paths.isEmpty()) {
       MercurialCommandLine cli = createCommandLine(tempDir);
-      int cmdSize = cli.getCommandLineString().length();
+      int cmdSize = cli.getCommandLineString().length() + 42;
 
       do {
         String path = paths.poll();
         cli.addParameter(path);
-        cmdSize += path.length();
-      } while (cmdSize < MAX_CMD_LEN && !paths.isEmpty());
+        cmdSize += path.length() + 3; //quotes + space
+      } while (cmdSize < OS.getMaxCommandLineSize() && !paths.isEmpty());
 
       runCommand(cli, myCommandSettings.setCheckForFailure(checkFailure));
     }