Search in sources :

Example 1 with HgStatusCommand

use of org.zmlx.hg4idea.command.HgStatusCommand in project intellij-community by JetBrains.

the class HgUtil method getDiff.

@NotNull
public static List<Change> getDiff(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull final FilePath path, @Nullable final HgRevisionNumber revNum1, @Nullable final HgRevisionNumber revNum2) {
    HgStatusCommand statusCommand;
    if (revNum1 != null) {
        //rev2==null means "compare with local version"
        statusCommand = new HgStatusCommand.Builder(true).ignored(false).unknown(false).copySource(!path.isDirectory()).baseRevision(revNum1).targetRevision(revNum2).build(project);
    } else {
        //rev1 and rev2 can't be null both//
        LOG.assertTrue(revNum2 != null, "revision1 and revision2 can't both be null. Path: " + path);
        //get initial changes//
        statusCommand = new HgStatusCommand.Builder(true).ignored(false).unknown(false).copySource(false).baseRevision(revNum2).build(project);
    }
    Collection<HgChange> hgChanges = statusCommand.executeInCurrentThread(root, Collections.singleton(path));
    List<Change> changes = new ArrayList<>();
    //convert output changes to standard Change class
    for (HgChange hgChange : hgChanges) {
        FileStatus status = convertHgDiffStatus(hgChange.getStatus());
        if (status != FileStatus.UNKNOWN) {
            changes.add(HgHistoryUtil.createChange(project, root, hgChange.beforeFile().getRelativePath(), revNum1, hgChange.afterFile().getRelativePath(), revNum2, status));
        }
    }
    return changes;
}
Also used : FileStatus(com.intellij.openapi.vcs.FileStatus) Change(com.intellij.openapi.vcs.changes.Change) HgStatusCommand(org.zmlx.hg4idea.command.HgStatusCommand) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with HgStatusCommand

use of org.zmlx.hg4idea.command.HgStatusCommand in project intellij-community by JetBrains.

the class HgUtil method getFileNameInTargetRevision.

@NotNull
public static HgFile getFileNameInTargetRevision(Project project, HgRevisionNumber vcsRevisionNumber, HgFile localHgFile) {
    //get file name in target revision if it was moved/renamed
    // if file was moved but not committed then hg status would return nothing, so it's better to point working dir as '.' revision
    HgStatusCommand statCommand = new HgStatusCommand.Builder(false).copySource(true).baseRevision(vcsRevisionNumber).targetRevision(HgRevisionNumber.getInstance("", ".")).build(project);
    Set<HgChange> changes = statCommand.executeInCurrentThread(localHgFile.getRepo(), Collections.singletonList(localHgFile.toFilePath()));
    for (HgChange change : changes) {
        if (change.afterFile().equals(localHgFile)) {
            return change.beforeFile();
        }
    }
    return localHgFile;
}
Also used : HgStatusCommand(org.zmlx.hg4idea.command.HgStatusCommand) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with HgStatusCommand

use of org.zmlx.hg4idea.command.HgStatusCommand in project intellij-community by JetBrains.

the class HgCompareWithBranchAction method existInBranch.

private static boolean existInBranch(@NotNull HgRepository repository, @NotNull FilePath path, @NotNull HgRevisionNumber compareWithRevisionNumber) {
    HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).ignored(false).unknown(false).copySource(!path.isDirectory()).baseRevision(compareWithRevisionNumber).targetRevision(null).build(repository.getProject());
    statusCommand.cleanFilesOption(true);
    return !statusCommand.executeInCurrentThread(repository.getRoot(), Collections.singleton(path)).isEmpty();
}
Also used : HgStatusCommand(org.zmlx.hg4idea.command.HgStatusCommand)

Aggregations

HgStatusCommand (org.zmlx.hg4idea.command.HgStatusCommand)3 NotNull (org.jetbrains.annotations.NotNull)2 FileStatus (com.intellij.openapi.vcs.FileStatus)1 Change (com.intellij.openapi.vcs.changes.Change)1