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