Search in sources :

Example 1 with GitBranchesSearcher

use of git4idea.GitBranchesSearcher in project intellij-community by JetBrains.

the class GitOutgoingChangesProvider method filterLocalChangesBasedOnLocalCommits.

public Collection<Change> filterLocalChangesBasedOnLocalCommits(final Collection<Change> localChanges, final VirtualFile vcsRoot) throws VcsException {
    final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, true);
    if (searcher.getLocal() == null || searcher.getRemote() == null) {
        // no information, better strict approach (see getOutgoingChanges() code)
        return new ArrayList<>(localChanges);
    }
    final GitRevisionNumber base;
    try {
        base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
    } catch (VcsException e) {
        LOG.info(e);
        return new ArrayList<>(localChanges);
    }
    if (base == null) {
        // no information, better strict approach (see getOutgoingChanges() code)
        return new ArrayList<>(localChanges);
    }
    final List<Pair<SHAHash, Date>> hashes = GitHistoryUtils.onlyHashesHistory(myProject, VcsUtil.getFilePath(vcsRoot), vcsRoot, (base.asString() + "..HEAD"));
    // no local commits
    if (hashes.isEmpty())
        return Collections.emptyList();
    // optimization
    final String first = hashes.get(0).getFirst().getValue();
    final Set<String> localHashes = new HashSet<>();
    for (Pair<SHAHash, Date> hash : hashes) {
        localHashes.add(hash.getFirst().getValue());
    }
    final Collection<Change> result = new ArrayList<>();
    for (Change change : localChanges) {
        if (change.getBeforeRevision() != null) {
            final String changeBeforeRevision = change.getBeforeRevision().getRevisionNumber().asString().trim();
            if (first.equals(changeBeforeRevision) || localHashes.contains(changeBeforeRevision)) {
                result.add(change);
            }
        }
    }
    return result;
}
Also used : SHAHash(git4idea.history.browser.SHAHash) Change(com.intellij.openapi.vcs.changes.Change) GitBranchesSearcher(git4idea.GitBranchesSearcher) GitRevisionNumber(git4idea.GitRevisionNumber) Pair(com.intellij.openapi.util.Pair)

Example 2 with GitBranchesSearcher

use of git4idea.GitBranchesSearcher in project intellij-community by JetBrains.

the class GitOutgoingChangesProvider method getOutgoingChanges.

public Pair<VcsRevisionNumber, List<CommittedChangeList>> getOutgoingChanges(final VirtualFile vcsRoot, final boolean findRemote) throws VcsException {
    LOG.debug("getOutgoingChanges root: " + vcsRoot.getPath());
    final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, findRemote);
    if (searcher.getLocal() == null || searcher.getRemote() == null) {
        return new Pair<>(null, Collections.<CommittedChangeList>emptyList());
    }
    final GitRevisionNumber base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
    if (base == null) {
        return new Pair<>(null, Collections.<CommittedChangeList>emptyList());
    }
    final List<GitCommittedChangeList> lists = GitUtil.getLocalCommittedChanges(myProject, vcsRoot, new Consumer<GitSimpleHandler>() {

        public void consume(final GitSimpleHandler handler) {
            handler.addParameters(base.asString() + "..HEAD");
        }
    });
    return new Pair<>(base, ObjectsConvertor.convert(lists, new Convertor<GitCommittedChangeList, CommittedChangeList>() {

        @Override
        public CommittedChangeList convert(GitCommittedChangeList o) {
            return o;
        }
    }));
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitBranchesSearcher(git4idea.GitBranchesSearcher) Pair(com.intellij.openapi.util.Pair) Convertor(com.intellij.util.containers.Convertor)

Example 3 with GitBranchesSearcher

use of git4idea.GitBranchesSearcher in project intellij-community by JetBrains.

the class GitOutgoingChangesProvider method getMergeBaseNumber.

@Nullable
public VcsRevisionNumber getMergeBaseNumber(final VirtualFile anyFileUnderRoot) throws VcsException {
    LOG.debug("getMergeBaseNumber parameter: " + anyFileUnderRoot.getPath());
    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
    final VirtualFile root = vcsManager.getVcsRootFor(anyFileUnderRoot);
    if (root == null) {
        LOG.info("VCS root not found");
        return null;
    }
    final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, root, true);
    if (searcher.getLocal() == null || searcher.getRemote() == null) {
        LOG.info("local or remote not found");
        return null;
    }
    final GitRevisionNumber base = getMergeBase(myProject, root, searcher.getLocal(), searcher.getRemote());
    LOG.debug("found base: " + ((base == null) ? null : base.asString()));
    return base;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRevisionNumber(git4idea.GitRevisionNumber) GitBranchesSearcher(git4idea.GitBranchesSearcher) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GitBranchesSearcher (git4idea.GitBranchesSearcher)3 GitRevisionNumber (git4idea.GitRevisionNumber)3 Pair (com.intellij.openapi.util.Pair)2 Change (com.intellij.openapi.vcs.changes.Change)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Convertor (com.intellij.util.containers.Convertor)1 GitSimpleHandler (git4idea.commands.GitSimpleHandler)1 SHAHash (git4idea.history.browser.SHAHash)1 Nullable (org.jetbrains.annotations.Nullable)1