Mercurial > hg > mercurial
view mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CatCommand.java @ 338:d31d7c81b637 Eluru-6.5.x
Support subrepositories while building clean patch.
Use 'hg clone' instead of 'hg archive' if repository contains
subrepositories.
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Fri, 02 Dec 2011 15:12:49 +0300 |
parents | 0ea2ad14ce97 |
children | b799355b4016 3b799724b82b |
line wrap: on
line source
/* * Copyright 2000-2011 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.command; import com.intellij.execution.configurations.GeneralCommandLine; import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.vcs.VcsException; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; import java.util.LinkedList; import java.util.List; import java.util.Queue; public class CatCommand extends BaseCommand { private String myRevId; private final static int MAX_CMD_LEN = 900; private boolean myLogErrorsInDebug = false; public CatCommand(@NotNull Settings settings, @NotNull File workingDir) { super(settings, workingDir); } public void setRevId(final String revId) { myRevId = revId; } public void setLogErrorsInDebug(boolean doLogErrorsInDebug) { myLogErrorsInDebug = doLogErrorsInDebug; } public File execute(List<String> relPaths) throws VcsException { File tempDir; try { tempDir = FileUtil.createTempDirectory("mercurial", "catresult"); } catch (IOException e) { throw new VcsException("Unable to create temporary directory"); } for (String path: relPaths) { final File parentFile = new File(tempDir, path).getParentFile(); if (!parentFile.isDirectory() && !parentFile.mkdirs()) { throw new VcsException("Failed to create directory: " + parentFile.getAbsolutePath()); } } Queue<String> paths = new LinkedList<String>(relPaths); while (!paths.isEmpty()) { GeneralCommandLine cli = createCommandLine(tempDir); int cmdSize = cli.getCommandLineString().length(); do { String path = paths.poll(); cli.addParameter(path); cmdSize += path.length(); } while (cmdSize < MAX_CMD_LEN && !paths.isEmpty()); runCommand(cli, myLogErrorsInDebug); } return tempDir; } private GeneralCommandLine createCommandLine(final File tempDir) { GeneralCommandLine cli = createCommandLine(); cli.addParameter("cat"); cli.addParameter("-o"); cli.addParameter(tempDir.getAbsolutePath() + File.separator + "%p"); if (myRevId != null) { cli.addParameter("-r"); cli.addParameter(myRevId); } return cli; } }