Search in sources :

Example 11 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgActionFromMqPatches method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final HgMqUnAppliedPatchesPanel patchInfo = e.getRequiredData(HgMqUnAppliedPatchesPanel.MQ_PATCHES);
    final List<String> names = patchInfo.getSelectedPatchNames();
    final HgRepository repository = patchInfo.getRepository();
    Runnable task = new Runnable() {

        @Override
        public void run() {
            ProgressManager.getInstance().getProgressIndicator().setText(getTitle());
            executeInCurrentThread(repository, names);
        }
    };
    patchInfo.updatePatchSeriesInBackground(task);
}
Also used : HgMqUnAppliedPatchesPanel(org.zmlx.hg4idea.ui.HgMqUnAppliedPatchesPanel) HgRepository(org.zmlx.hg4idea.repo.HgRepository)

Example 12 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgCheckinEnvironment method getFilesByRepository.

@NotNull
private Map<HgRepository, Set<HgFile>> getFilesByRepository(List<Change> changes) {
    Map<HgRepository, Set<HgFile>> result = new HashMap<>();
    for (Change change : changes) {
        ContentRevision afterRevision = change.getAfterRevision();
        ContentRevision beforeRevision = change.getBeforeRevision();
        if (afterRevision != null) {
            addFile(result, afterRevision);
        }
        if (beforeRevision != null) {
            addFile(result, beforeRevision);
        }
    }
    return result;
}
Also used : HgCurrentBinaryContentRevision(org.zmlx.hg4idea.provider.HgCurrentBinaryContentRevision) HgRepository(org.zmlx.hg4idea.repo.HgRepository) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgCheckinEnvironment method addFile.

private void addFile(Map<HgRepository, Set<HgFile>> result, ContentRevision contentRevision) {
    FilePath filePath = contentRevision.getFile();
    // try to find repository from hgFile from change: to be able commit sub repositories as expected
    HgRepository repo = HgUtil.getRepositoryForFile(myProject, contentRevision instanceof HgCurrentBinaryContentRevision ? ((HgCurrentBinaryContentRevision) contentRevision).getRepositoryRoot() : ChangesUtil.findValidParentAccurately(filePath));
    if (repo == null) {
        return;
    }
    Set<HgFile> hgFiles = result.get(repo);
    if (hgFiles == null) {
        hgFiles = new HashSet<>();
        result.put(repo, hgFiles);
    }
    hgFiles.add(new HgFile(repo.getRoot(), filePath));
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgCurrentBinaryContentRevision(org.zmlx.hg4idea.provider.HgCurrentBinaryContentRevision)

Example 14 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgLogProvider method getCommitsMatchingFilter.

@NotNull
@Override
public List<TimedVcsCommit> getCommitsMatchingFilter(@NotNull final VirtualFile root, @NotNull VcsLogFilterCollection filterCollection, int maxCount) throws VcsException {
    List<String> filterParameters = ContainerUtil.newArrayList();
    // branch filter and user filter may be used several times without delimiter
    VcsLogBranchFilter branchFilter = filterCollection.getBranchFilter();
    if (branchFilter != null) {
        HgRepository repository = myRepositoryManager.getRepositoryForRoot(root);
        if (repository == null) {
            LOG.error("Repository not found for root " + root);
            return Collections.emptyList();
        }
        Collection<String> branchNames = repository.getBranches().keySet();
        Collection<String> bookmarkNames = HgUtil.getNamesWithoutHashes(repository.getBookmarks());
        Collection<String> predefinedNames = ContainerUtil.list(TIP_REFERENCE);
        boolean atLeastOneBranchExists = false;
        for (String branchName : ContainerUtil.concat(branchNames, bookmarkNames, predefinedNames)) {
            if (branchFilter.matches(branchName)) {
                filterParameters.add(HgHistoryUtil.prepareParameter("branch", branchName));
                atLeastOneBranchExists = true;
            }
        }
        if (branchFilter.matches(HEAD_REFERENCE)) {
            filterParameters.add(HgHistoryUtil.prepareParameter("branch", "."));
            filterParameters.add("-r");
            //all ancestors for current revision;
            filterParameters.add("::.");
            atLeastOneBranchExists = true;
        }
        if (!atLeastOneBranchExists) {
            // no such branches => filter matches nothing
            return Collections.emptyList();
        }
    }
    if (filterCollection.getUserFilter() != null) {
        filterParameters.add("-r");
        String authorFilter = StringUtil.join(ContainerUtil.map(ContainerUtil.map(filterCollection.getUserFilter().getUsers(root), VcsUserUtil::toExactString), UserNameRegex.EXTENDED_INSTANCE), "|");
        filterParameters.add("user('re:" + authorFilter + "')");
    }
    if (filterCollection.getDateFilter() != null) {
        StringBuilder args = new StringBuilder();
        final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        filterParameters.add("-d");
        VcsLogDateFilter filter = filterCollection.getDateFilter();
        if (filter.getAfter() != null) {
            if (filter.getBefore() != null) {
                args.append(dateFormatter.format(filter.getAfter())).append(" to ").append(dateFormatter.format(filter.getBefore()));
            } else {
                args.append('>').append(dateFormatter.format(filter.getAfter()));
            }
        } else if (filter.getBefore() != null) {
            args.append('<').append(dateFormatter.format(filter.getBefore()));
        }
        filterParameters.add(args.toString());
    }
    if (filterCollection.getTextFilter() != null) {
        String textFilter = filterCollection.getTextFilter().getText();
        if (filterCollection.getTextFilter().isRegex()) {
            filterParameters.add("-r");
            filterParameters.add("grep(r'" + textFilter + "')");
        } else if (filterCollection.getTextFilter().matchesCase()) {
            filterParameters.add("-r");
            filterParameters.add("grep(r'" + StringUtil.escapeChars(textFilter, UserNameRegex.EXTENDED_REGEX_CHARS) + "')");
        } else {
            filterParameters.add(HgHistoryUtil.prepareParameter("keyword", textFilter));
        }
    }
    if (filterCollection.getStructureFilter() != null) {
        for (FilePath file : filterCollection.getStructureFilter().getFiles()) {
            filterParameters.add(file.getPath());
        }
    }
    return HgHistoryUtil.readAllHashes(myProject, root, Consumer.EMPTY_CONSUMER, filterParameters);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VcsUserUtil(com.intellij.vcs.log.util.VcsUserUtil) HgRepository(org.zmlx.hg4idea.repo.HgRepository) SimpleDateFormat(java.text.SimpleDateFormat) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with HgRepository

use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.

the class HgUpdateCommand method updateTo.

public static void updateTo(@NotNull final String targetRevision, @NotNull List<HgRepository> repos, @Nullable final Runnable callInAwtLater) {
    FileDocumentManager.getInstance().saveAllDocuments();
    for (HgRepository repo : repos) {
        final VirtualFile repository = repo.getRoot();
        Project project = repo.getProject();
        updateRepoTo(project, repository, targetRevision, callInAwtLater);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) HgRepository(org.zmlx.hg4idea.repo.HgRepository)

Aggregations

HgRepository (org.zmlx.hg4idea.repo.HgRepository)36 NotNull (org.jetbrains.annotations.NotNull)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Project (com.intellij.openapi.project.Project)7 VcsException (com.intellij.openapi.vcs.VcsException)5 FilePath (com.intellij.openapi.vcs.FilePath)4 HgCommitCommand (org.zmlx.hg4idea.command.HgCommitCommand)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 File (java.io.File)3 HgFile (org.zmlx.hg4idea.HgFile)3 HgCommandException (org.zmlx.hg4idea.execution.HgCommandException)3 Task (com.intellij.openapi.progress.Task)2 AbstractVcsVirtualFile (com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile)2 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 HgFileRevision (org.zmlx.hg4idea.HgFileRevision)2 HgNameWithHashInfo (org.zmlx.hg4idea.HgNameWithHashInfo)2 HgLogCommand (org.zmlx.hg4idea.command.HgLogCommand)2