use of com.intellij.openapi.vcs.FilePath 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.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class HgHistoryUtil method getOriginalHgFile.
public static HgFile getOriginalHgFile(Project project, VirtualFile root) {
HgFile hgFile = new HgFile(root, VcsUtil.getFilePath(root.getPath()));
if (project.isDisposed()) {
return hgFile;
}
FilePath originalFileName = HgUtil.getOriginalFileName(hgFile.toFilePath(), ChangeListManager.getInstance(project));
return new HgFile(hgFile.getRepo(), originalFileName);
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class HgHistoryProvider method getHistory.
public static List<HgFileRevision> getHistory(@NotNull FilePath filePath, @NotNull VirtualFile vcsRoot, @NotNull Project project, @Nullable HgRevisionNumber revisionNumber, int limit) {
/* The standard way to get history following renames is to call hg log --follow. However:
1. It is broken in case of uncommitted rename (i.e. if the file is currently renamed in the working dir):
in this case we use a special python template "follow(path)" which handles this case.
2. We don't use this python "follow(path)" function for all cases, because it is fully supported only since hg 2.6,
and it is a bit slower and possibly less reliable than plain --follow parameter.
3. It doesn't work with "-r": in this case --follow is simply ignored (hg commit 24208:8b4b9ee6001a).
As a workaround we could use the same follow(path) python, but this function requires current name of the file,
which is unknown in case of "-r", and identifying it would be very slow.
As a result we don't follow renames in annotate called from diff or from an old revision, which we can survive.
*/
FilePath originalFilePath = HgUtil.getOriginalFileName(filePath, ChangeListManager.getInstance(project));
if (revisionNumber == null && !filePath.isDirectory() && !filePath.equals(originalFilePath)) {
// uncommitted renames detected
return getHistoryForUncommittedRenamed(originalFilePath, vcsRoot, project, limit);
}
final HgLogCommand logCommand = new HgLogCommand(project);
logCommand.setFollowCopies(!filePath.isDirectory());
logCommand.setIncludeRemoved(true);
List<String> args = new ArrayList<>();
if (revisionNumber != null) {
args.add("--rev");
args.add("reverse(0::" + revisionNumber.getChangeset() + ")");
}
return logCommand.execute(new HgFile(vcsRoot, filePath), limit, false, args);
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class HgLocalIgnoredHolder method removeIgnoredFiles.
@NotNull
public List<FilePath> removeIgnoredFiles(@NotNull Collection<FilePath> files) {
List<FilePath> removedIgnoredFiles = ContainerUtil.newArrayList();
try {
SET_LOCK.writeLock().lock();
Iterator<VirtualFile> iter = myIgnoredSet.iterator();
while (iter.hasNext()) {
FilePath filePath = VcsUtil.getFilePath(iter.next());
if (files.contains(filePath)) {
iter.remove();
removedIgnoredFiles.add(filePath);
}
}
} finally {
SET_LOCK.writeLock().unlock();
}
return removedIgnoredFiles;
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class SvnTestDirtyScopeStateTest method testOkToAddScopeUnderWriteAction.
@Test
public void testOkToAddScopeUnderWriteAction() throws Exception {
enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
final VcsDirtyScopeManagerImpl vcsDirtyScopeManager = (VcsDirtyScopeManagerImpl) VcsDirtyScopeManager.getInstance(myProject);
final VirtualFile file = createFileInCommand("a.txt", "old content");
final VirtualFile fileB = createFileInCommand("b.txt", "old content");
final VirtualFile fileC = createFileInCommand("c.txt", "old content");
final VirtualFile fileD = createFileInCommand("d.txt", "old content");
final List<FilePath> list = ObjectsConvertor.vf2fp(Arrays.asList(file, fileB, fileC, fileD));
vcsDirtyScopeManager.retrieveScopes();
vcsDirtyScopeManager.changesProcessed();
new WriteCommandAction.Simple(myProject) {
@Override
protected void run() throws Throwable {
vcsDirtyScopeManager.fileDirty(file);
vcsDirtyScopeManager.fileDirty(fileB);
}
}.execute().throwException();
final FilePath fp = VcsUtil.getFilePath(file);
final FilePath fpB = VcsUtil.getFilePath(fileB);
final long start = System.currentTimeMillis();
while (System.currentTimeMillis() < (start + 3000)) {
synchronized (this) {
try {
wait(50);
} catch (InterruptedException e) {
//
}
}
final Collection<FilePath> dirty1 = vcsDirtyScopeManager.whatFilesDirty(list);
if (dirty1.contains(fp) && dirty1.contains(fpB))
return;
}
Assert.assertTrue(false);
}
Aggregations