Mercurial > hg > mercurial
view mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/StatusCommand.java @ 977:38adef4f1b8f Indore-2017.2.x
Update copyright
author | pavel.sher |
---|---|
date | Mon, 22 Jan 2018 11:40:45 +0100 |
parents | e467e67d5892 |
children | 10dc26b32c35 |
line wrap: on
line source
/* * Copyright 2000-2018 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 jetbrains.buildServer.vcs.VcsException; import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.ArrayList; import java.util.List; import static com.intellij.openapi.util.text.StringUtil.isEmpty; public class StatusCommand extends VcsRootCommand { private String myFromId; private String myToId; private boolean myShowAllFiles = false; private boolean myHideStatus = false; public StatusCommand(@NotNull CommandSettings commandSettings, @NotNull String hgPath, @NotNull File workingDir, @NotNull AuthSettings authSettings) { super(commandSettings, hgPath, workingDir, authSettings); } @NotNull public StatusCommand fromRevision(@NotNull ChangeSet fromCset) { myFromId = fromCset.getId(); return this; } @NotNull public StatusCommand fromRevision(@NotNull String fromRevision) { myFromId = new ChangeSet(fromRevision).getId(); return this; } @NotNull public StatusCommand toRevision(@NotNull ChangeSet toCset) { myToId = toCset.getId(); return this; } @NotNull public StatusCommand toRevision(@NotNull String toRevision) { myToId = new ChangeSet(toRevision).getId(); return this; } /** * Adds option -A (--all) * @return self */ @NotNull public StatusCommand showAllFiles() { myShowAllFiles = true; return this; } /** * Adds option -n (--no-status) * @return self */ @NotNull public StatusCommand hideStatus() { myHideStatus = true; return this; } @NotNull public List<FileStatus> call() throws VcsException { final MercurialCommandLine cli = createCommandLine(); cli.addParameter("status"); if (myShowAllFiles) { cli.addParameter("-A"); } if (myHideStatus) { cli.addParameter("-n"); } cli.addParameter("--rev"); String from = myFromId; if (from == null) from = "0"; String to = myToId; if (to == null) { to = "0"; } cli.addParameter(from + ":" + to); final CommandResult res = runCommand(cli); return parseFiles(res.getRawStdout()); } @NotNull private List<FileStatus> parseFiles(@NotNull final String stdout) { final List<FileStatus> result = new ArrayList<FileStatus>(); String[] lines = stdout.split("\n"); for (String line : lines) { if (isEmpty(line)) continue; FileStatus fileStatus = parseLine(line); if (!myHideStatus && fileStatus.getStatus() == Status.UNKNOWN) continue; result.add(fileStatus); } return result; } @NotNull private FileStatus parseLine(@NotNull final String line) { if (myHideStatus) return new FileStatus(Status.UNKNOWN, line); final char modifier = line.charAt(0); final String path = line.substring(2); final Status status = Status.makeStatus(modifier); return new FileStatus(status, path); } @NotNull @Override protected String getDescription() { return "hg status"; } }