Search in sources :

Example 1 with VcsUserUtil

use of com.intellij.vcs.log.util.VcsUserUtil 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 2 with VcsUserUtil

use of com.intellij.vcs.log.util.VcsUserUtil in project intellij-community by JetBrains.

the class GitLogProvider method getCommitsMatchingFilter.

@NotNull
@Override
public List<TimedVcsCommit> getCommitsMatchingFilter(@NotNull final VirtualFile root, @NotNull VcsLogFilterCollection filterCollection, int maxCount) throws VcsException {
    if (!isRepositoryReady(root)) {
        return Collections.emptyList();
    }
    List<String> filterParameters = ContainerUtil.newArrayList();
    VcsLogBranchFilter branchFilter = filterCollection.getBranchFilter();
    if (branchFilter != null) {
        GitRepository repository = getRepository(root);
        assert repository != null : "repository is null for root " + root + " but was previously reported as 'ready'";
        Collection<GitBranch> branches = ContainerUtil.newArrayList(ContainerUtil.concat(repository.getBranches().getLocalBranches(), repository.getBranches().getRemoteBranches()));
        Collection<String> branchNames = GitBranchUtil.convertBranchesToNames(branches);
        Collection<String> predefinedNames = ContainerUtil.list("HEAD");
        boolean atLeastOneBranchExists = false;
        for (String branchName : ContainerUtil.concat(branchNames, predefinedNames)) {
            if (branchFilter.matches(branchName)) {
                filterParameters.add(branchName);
                atLeastOneBranchExists = true;
            }
        }
        if (!atLeastOneBranchExists) {
            // no such branches in this repository => filter matches nothing
            return Collections.emptyList();
        }
    } else {
        filterParameters.addAll(GitHistoryUtils.LOG_ALL);
    }
    if (filterCollection.getDateFilter() != null) {
        // assuming there is only one date filter, until filter expressions are defined
        VcsLogDateFilter filter = filterCollection.getDateFilter();
        if (filter.getAfter() != null) {
            filterParameters.add(prepareParameter("after", filter.getAfter().toString()));
        }
        if (filter.getBefore() != null) {
            filterParameters.add(prepareParameter("before", filter.getBefore().toString()));
        }
    }
    boolean regexp = true;
    boolean caseSensitive = false;
    if (filterCollection.getTextFilter() != null) {
        regexp = filterCollection.getTextFilter().isRegex();
        caseSensitive = filterCollection.getTextFilter().matchesCase();
        String textFilter = filterCollection.getTextFilter().getText();
        filterParameters.add(prepareParameter("grep", textFilter));
    }
    filterParameters.add(regexp ? "--extended-regexp" : "--fixed-strings");
    if (!caseSensitive) {
        // affects case sensitivity of any filter (except file filter)
        filterParameters.add("--regexp-ignore-case");
    }
    if (filterCollection.getUserFilter() != null) {
        Collection<String> names = ContainerUtil.map(filterCollection.getUserFilter().getUsers(root), VcsUserUtil::toExactString);
        if (regexp) {
            List<String> authors = ContainerUtil.map(names, UserNameRegex.EXTENDED_INSTANCE);
            if (GitVersionSpecialty.LOG_AUTHOR_FILTER_SUPPORTS_VERTICAL_BAR.existsIn(myVcs.getVersion())) {
                filterParameters.add(prepareParameter("author", StringUtil.join(authors, "|")));
            } else {
                filterParameters.addAll(authors.stream().map(a -> prepareParameter("author", a)).collect(Collectors.toList()));
            }
        } else {
            filterParameters.addAll(ContainerUtil.map(names, a -> prepareParameter("author", StringUtil.escapeBackSlashes(a))));
        }
    }
    if (maxCount > 0) {
        filterParameters.add(prepareParameter("max-count", String.valueOf(maxCount)));
    }
    // note: structure filter must be the last parameter, because it uses "--" which separates parameters from paths
    if (filterCollection.getStructureFilter() != null) {
        Collection<FilePath> files = filterCollection.getStructureFilter().getFiles();
        if (!files.isEmpty()) {
            filterParameters.add("--full-history");
            filterParameters.add("--simplify-merges");
            filterParameters.add("--");
            for (FilePath file : files) {
                filterParameters.add(file.getPath());
            }
        }
    }
    List<TimedVcsCommit> commits = ContainerUtil.newArrayList();
    GitHistoryUtils.readCommits(myProject, root, filterParameters, EmptyConsumer.getInstance(), EmptyConsumer.getInstance(), new CollectConsumer<>(commits));
    return commits;
}
Also used : java.util(java.util) ThrowableNotNullFunction(com.intellij.openapi.util.ThrowableNotNullFunction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogDataImpl(com.intellij.vcs.log.impl.LogDataImpl) GitVersionSpecialty(git4idea.config.GitVersionSpecialty) GitRepositoryManager(git4idea.repo.GitRepositoryManager) THashSet(gnu.trove.THashSet) VcsKey(com.intellij.openapi.vcs.VcsKey) ContainerUtil(com.intellij.util.containers.ContainerUtil) GitBranchUtil(git4idea.branch.GitBranchUtil) GraphColorManager(com.intellij.vcs.log.graph.GraphColorManager) PermanentGraphImpl(com.intellij.vcs.log.graph.impl.facade.PermanentGraphImpl) TObjectHashingStrategy(gnu.trove.TObjectHashingStrategy) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) GitHistoryUtils(git4idea.history.GitHistoryUtils) UserNameRegex(com.intellij.vcs.log.util.UserNameRegex) Project(com.intellij.openapi.project.Project) VcsFileUtil(com.intellij.vcsUtil.VcsFileUtil) Logger(com.intellij.openapi.diagnostic.Logger) VcsException(com.intellij.openapi.vcs.VcsException) GitRepository(git4idea.repo.GitRepository) FilePath(com.intellij.openapi.vcs.FilePath) git4idea(git4idea) VcsLogSorter(com.intellij.vcs.log.data.VcsLogSorter) GraphCommit(com.intellij.vcs.log.graph.GraphCommit) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.vcs.log(com.intellij.vcs.log) OpenTHashSet(com.intellij.util.containers.OpenTHashSet) Collectors(java.util.stream.Collectors) Disposable(com.intellij.openapi.Disposable) Nullable(org.jetbrains.annotations.Nullable) GitBranchesCollection(git4idea.branch.GitBranchesCollection) HashImpl(com.intellij.vcs.log.impl.HashImpl) StopWatch(com.intellij.vcs.log.util.StopWatch) VcsUserUtil(com.intellij.vcs.log.util.VcsUserUtil) Attachment(com.intellij.openapi.diagnostic.Attachment) Registry(com.intellij.openapi.util.registry.Registry) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) FilePath(com.intellij.openapi.vcs.FilePath) VcsUserUtil(com.intellij.vcs.log.util.VcsUserUtil) GitRepository(git4idea.repo.GitRepository) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FilePath (com.intellij.openapi.vcs.FilePath)2 VcsUserUtil (com.intellij.vcs.log.util.VcsUserUtil)2 NotNull (org.jetbrains.annotations.NotNull)2 Disposable (com.intellij.openapi.Disposable)1 Attachment (com.intellij.openapi.diagnostic.Attachment)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Project (com.intellij.openapi.project.Project)1 ThrowableNotNullFunction (com.intellij.openapi.util.ThrowableNotNullFunction)1 Registry (com.intellij.openapi.util.registry.Registry)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 VcsException (com.intellij.openapi.vcs.VcsException)1 VcsKey (com.intellij.openapi.vcs.VcsKey)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 com.intellij.util (com.intellij.util)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 OpenTHashSet (com.intellij.util.containers.OpenTHashSet)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 com.intellij.vcs.log (com.intellij.vcs.log)1 VcsLogSorter (com.intellij.vcs.log.data.VcsLogSorter)1 GraphColorManager (com.intellij.vcs.log.graph.GraphColorManager)1