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