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;
}
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;
}
}));
}
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;
}
Aggregations