Search in sources :

Example 76 with FilePath

use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.

the class GitContentRevision method createRevisionForTypeChange.

public static ContentRevision createRevisionForTypeChange(@NotNull Project project, @NotNull VirtualFile vcsRoot, @NotNull String path, @Nullable VcsRevisionNumber revisionNumber, boolean unescapePath) throws VcsException {
    final FilePath filePath;
    if (revisionNumber == null) {
        File file = new File(makeAbsolutePath(vcsRoot, path, unescapePath));
        VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
        filePath = virtualFile == null ? VcsUtil.getFilePath(file, false) : VcsUtil.getFilePath(virtualFile);
    } else {
        filePath = createPath(vcsRoot, path, false, false, unescapePath);
    }
    return createRevision(filePath, revisionNumber, project);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 77 with FilePath

use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.

the class GitUtil method sortFilePathsByGitRoot.

/**
   * Sort files by vcs root
   *
   * @param files        files to sort.
   * @param ignoreNonGit if true, non-git files are ignored
   * @return the map from root to the files under the root
   * @throws VcsException if non git files are passed when {@code ignoreNonGit} is false
   */
@NotNull
public static Map<VirtualFile, List<FilePath>> sortFilePathsByGitRoot(@NotNull Collection<FilePath> files, boolean ignoreNonGit) throws VcsException {
    Map<VirtualFile, List<FilePath>> rc = new HashMap<>();
    for (FilePath p : files) {
        VirtualFile root = getGitRootOrNull(p);
        if (root == null) {
            if (ignoreNonGit) {
                continue;
            } else {
                throw new VcsException("The file " + p.getPath() + " is not under Git");
            }
        }
        List<FilePath> l = rc.get(root);
        if (l == null) {
            l = new ArrayList<>();
            rc.put(root, l);
        }
        l.add(p);
    }
    return rc;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) VcsException(com.intellij.openapi.vcs.VcsException) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) GitCommittedChangeList(git4idea.changes.GitCommittedChangeList) NotNull(org.jetbrains.annotations.NotNull) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull)

Example 78 with FilePath

use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.

the class GitLogRecord method getFilePaths.

@NotNull
public List<FilePath> getFilePaths(@NotNull VirtualFile root) throws VcsException {
    List<FilePath> res = new ArrayList<>();
    String prefix = root.getPath() + "/";
    for (String strPath : getPaths()) {
        final String subPath = GitUtil.unescapePath(strPath);
        final FilePath revisionPath = VcsUtil.getFilePathForDeletedFile(prefix + subPath, false);
        res.add(revisionPath);
    }
    return res;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with FilePath

use of com.intellij.openapi.vcs.FilePath 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)

Example 80 with FilePath

use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.

the class GitCheckinEnvironment method reset.

private static void reset(@NotNull Project project, @NotNull VirtualFile root, @NotNull Collection<Change> changes) throws VcsException {
    Set<FilePath> paths = new HashSet<>();
    paths.addAll(mapNotNull(changes, ChangesUtil::getAfterPath));
    paths.addAll(mapNotNull(changes, ChangesUtil::getBeforePath));
    GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.RESET);
    handler.endOptions();
    handler.addRelativePaths(paths);
    handler.run();
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) GitSimpleHandler(git4idea.commands.GitSimpleHandler)

Aggregations

FilePath (com.intellij.openapi.vcs.FilePath)167 VirtualFile (com.intellij.openapi.vfs.VirtualFile)68 NotNull (org.jetbrains.annotations.NotNull)43 VcsException (com.intellij.openapi.vcs.VcsException)34 File (java.io.File)30 Change (com.intellij.openapi.vcs.changes.Change)26 Nullable (org.jetbrains.annotations.Nullable)22 Project (com.intellij.openapi.project.Project)20 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)15 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)13 FileStatus (com.intellij.openapi.vcs.FileStatus)10 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)8 GitRepository (git4idea.repo.GitRepository)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Test (org.junit.Test)6 StringUtil (com.intellij.openapi.util.text.StringUtil)5 Logger (com.intellij.openapi.diagnostic.Logger)4