Search in sources :

Example 11 with StopWatch

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

the class GitLogProvider method readBranches.

@NotNull
private Set<VcsRef> readBranches(@NotNull GitRepository repository) {
    StopWatch sw = StopWatch.start("readBranches in " + repository.getRoot().getName());
    VirtualFile root = repository.getRoot();
    repository.update();
    GitBranchesCollection branches = repository.getBranches();
    Collection<GitLocalBranch> localBranches = branches.getLocalBranches();
    Collection<GitRemoteBranch> remoteBranches = branches.getRemoteBranches();
    Set<VcsRef> refs = new THashSet<>(localBranches.size() + remoteBranches.size());
    for (GitLocalBranch localBranch : localBranches) {
        Hash hash = branches.getHash(localBranch);
        assert hash != null;
        refs.add(myVcsObjectsFactory.createRef(hash, localBranch.getName(), GitRefManager.LOCAL_BRANCH, root));
    }
    for (GitRemoteBranch remoteBranch : remoteBranches) {
        Hash hash = branches.getHash(remoteBranch);
        assert hash != null;
        refs.add(myVcsObjectsFactory.createRef(hash, remoteBranch.getNameForLocalOperations(), GitRefManager.REMOTE_BRANCH, root));
    }
    String currentRevision = repository.getCurrentRevision();
    if (currentRevision != null) {
        // null => fresh repository
        refs.add(myVcsObjectsFactory.createRef(HashImpl.build(currentRevision), "HEAD", GitRefManager.HEAD, root));
    }
    sw.report();
    return refs;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitBranchesCollection(git4idea.branch.GitBranchesCollection) THashSet(gnu.trove.THashSet) OpenTHashSet(com.intellij.util.containers.OpenTHashSet) StopWatch(com.intellij.vcs.log.util.StopWatch) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with StopWatch

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

the class GitLogProvider method readFirstBlock.

@NotNull
@Override
public DetailedLogData readFirstBlock(@NotNull VirtualFile root, @NotNull Requirements requirements) throws VcsException {
    if (!isRepositoryReady(root)) {
        return LogDataImpl.empty();
    }
    GitRepository repository = ObjectUtils.assertNotNull(myRepositoryManager.getRepositoryForRoot(root));
    // need to query more to sort them manually; this doesn't affect performance: it is equal for -1000 and -2000
    int commitCount = requirements.getCommitCount() * 2;
    String[] params = new String[] { "HEAD", "--branches", "--remotes", "--max-count=" + commitCount };
    // NB: not specifying --tags, because it introduces great slowdown if there are many tags,
    // but makes sense only if there are heads without branch or HEAD labels (rare case). Such cases are partially handled below.
    boolean refresh = requirements instanceof VcsLogProviderRequirementsEx && ((VcsLogProviderRequirementsEx) requirements).isRefresh();
    DetailedLogData data = GitHistoryUtils.loadMetadata(myProject, root, params);
    Set<VcsRef> safeRefs = data.getRefs();
    Set<VcsRef> allRefs = new OpenTHashSet<>(safeRefs, DONT_CONSIDER_SHA);
    Set<VcsRef> branches = readBranches(repository);
    addNewElements(allRefs, branches);
    Collection<VcsCommitMetadata> allDetails;
    Set<String> currentTagNames = null;
    DetailedLogData commitsFromTags = null;
    if (!refresh) {
        allDetails = data.getCommits();
    } else {
        // on refresh: get new tags, which point to commits not from the first block; then get history, walking down just from these tags
        // on init: just ignore such tagged-only branches. The price for speed-up.
        VcsLogProviderRequirementsEx rex = (VcsLogProviderRequirementsEx) requirements;
        currentTagNames = readCurrentTagNames(root);
        addOldStillExistingTags(allRefs, currentTagNames, rex.getPreviousRefs());
        allDetails = newHashSet(data.getCommits());
        Set<String> previousTags = newHashSet(ContainerUtil.mapNotNull(rex.getPreviousRefs(), GET_TAG_NAME));
        Set<String> safeTags = newHashSet(ContainerUtil.mapNotNull(safeRefs, GET_TAG_NAME));
        Set<String> newUnmatchedTags = remove(currentTagNames, previousTags, safeTags);
        if (!newUnmatchedTags.isEmpty()) {
            commitsFromTags = loadSomeCommitsOnTaggedBranches(root, commitCount, newUnmatchedTags);
            addNewElements(allDetails, commitsFromTags.getCommits());
            addNewElements(allRefs, commitsFromTags.getRefs());
        }
    }
    StopWatch sw = StopWatch.start("sorting commits in " + root.getName());
    List<VcsCommitMetadata> sortedCommits = VcsLogSorter.sortByDateTopoOrder(allDetails);
    sortedCommits = sortedCommits.subList(0, Math.min(sortedCommits.size(), requirements.getCommitCount()));
    sw.report();
    if (LOG.isDebugEnabled()) {
        validateDataAndReportError(root, allRefs, sortedCommits, data, branches, currentTagNames, commitsFromTags);
    }
    return new LogDataImpl(allRefs, sortedCommits);
}
Also used : StopWatch(com.intellij.vcs.log.util.StopWatch) LogDataImpl(com.intellij.vcs.log.impl.LogDataImpl) GitRepository(git4idea.repo.GitRepository) OpenTHashSet(com.intellij.util.containers.OpenTHashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

StopWatch (com.intellij.vcs.log.util.StopWatch)12 NotNull (org.jetbrains.annotations.NotNull)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 VcsException (com.intellij.openapi.vcs.VcsException)2 OpenTHashSet (com.intellij.util.containers.OpenTHashSet)2 Attachment (com.intellij.openapi.diagnostic.Attachment)1 Hash (com.intellij.vcs.log.Hash)1 GraphColorManagerImpl (com.intellij.vcs.log.graph.GraphColorManagerImpl)1 GraphCommit (com.intellij.vcs.log.graph.GraphCommit)1 LogDataImpl (com.intellij.vcs.log.impl.LogDataImpl)1 GitBranchesCollection (git4idea.branch.GitBranchesCollection)1 GitRepository (git4idea.repo.GitRepository)1 THashSet (gnu.trove.THashSet)1 Map (java.util.Map)1