use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class RefreshWorker method partialDirRefresh.
private void partialDirRefresh(NewVirtualFileSystem fs, TObjectHashingStrategy<String> strategy, VirtualDirectoryImpl dir) {
while (true) {
// obtaining directory snapshot
List<VirtualFile> cached;
List<String> wanted;
AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
try {
cached = dir.getCachedChildren();
wanted = dir.getSuspiciousNames();
} finally {
token.finish();
}
OpenTHashSet<String> actualNames = null;
if (!fs.isCaseSensitive()) {
actualNames = new OpenTHashSet<>(strategy, VfsUtil.filterNames(fs.list(dir)));
}
if (LOG.isTraceEnabled()) {
LOG.trace("cached=" + cached + " actual=" + actualNames);
LOG.trace("suspicious=" + wanted);
}
// reading children attributes
List<Pair<VirtualFile, FileAttributes>> existingMap = ContainerUtil.newArrayListWithCapacity(cached.size());
for (VirtualFile child : cached) {
checkCancelled(dir);
existingMap.add(pair(child, fs.getAttributes(child)));
}
List<Pair<String, FileAttributes>> wantedMap = ContainerUtil.newArrayListWithCapacity(wanted.size());
for (String name : wanted) {
if (name.isEmpty())
continue;
checkCancelled(dir);
wantedMap.add(pair(name, fs.getAttributes(new FakeVirtualFile(dir, name))));
}
// generating events unless a directory was changed in between
token = ApplicationManager.getApplication().acquireReadActionLock();
try {
if (!cached.equals(dir.getCachedChildren()) || !wanted.equals(dir.getSuspiciousNames())) {
if (LOG.isDebugEnabled())
LOG.debug("retry: " + dir);
continue;
}
for (Pair<VirtualFile, FileAttributes> pair : existingMap) {
VirtualFile child = pair.first;
FileAttributes childAttributes = pair.second;
if (childAttributes != null) {
checkAndScheduleChildRefresh(dir, child, childAttributes);
checkAndScheduleFileNameChange(actualNames, child);
} else {
scheduleDeletion(child);
}
}
for (Pair<String, FileAttributes> pair : wantedMap) {
String name = pair.first;
FileAttributes childAttributes = pair.second;
if (childAttributes != null) {
scheduleCreation(dir, name, childAttributes.isDirectory(), false);
}
}
break;
} finally {
token.finish();
}
}
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class GitStash method perform.
/**
* {@inheritDoc}
*/
protected void perform(@NotNull final Project project, @NotNull final List<VirtualFile> gitRoots, @NotNull final VirtualFile defaultRoot) {
final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
if (changeListManager.isFreezedWithNotification("Can not stash changes now"))
return;
GitStashDialog d = new GitStashDialog(project, gitRoots, defaultRoot);
if (!d.showAndGet()) {
return;
}
VirtualFile root = d.getGitRoot();
final GitLineHandler h = d.handler();
AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
try {
GitHandlerUtil.doSynchronously(h, GitBundle.getString("stashing.title"), h.printableCommandLine());
} finally {
token.finish();
}
VfsUtil.markDirtyAndRefresh(false, true, false, root);
if (!h.errors().isEmpty()) {
showErrors(project, getActionName(), h.errors());
}
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class GitResetHead method perform.
/**
* {@inheritDoc}
*/
protected void perform(@NotNull Project project, @NotNull List<VirtualFile> gitRoots, @NotNull VirtualFile defaultRoot) {
GitResetDialog d = new GitResetDialog(project, gitRoots, defaultRoot);
if (!d.showAndGet()) {
return;
}
GitLineHandler h = d.handler();
AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
try {
GitHandlerUtil.doSynchronously(h, GitBundle.getString("resetting.title"), h.printableCommandLine());
} finally {
token.finish();
}
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
manager.updateRepository(d.getGitRoot());
VfsUtil.markDirtyAndRefresh(true, true, false, d.getGitRoot());
if (!h.errors().isEmpty()) {
showErrors(project, getActionName(), h.errors());
}
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class GitMergeOperation method execute.
@Override
protected void execute() {
LOG.info("starting");
saveAllDocuments();
boolean fatalErrorHappened = false;
int alreadyUpToDateRepositories = 0;
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
try {
while (hasMoreRepositories() && !fatalErrorHappened) {
final GitRepository repository = next();
LOG.info("next repository: " + repository);
VirtualFile root = repository.getRoot();
GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, GitLocalChangesWouldBeOverwrittenDetector.Operation.MERGE);
GitSimpleEventDetector unmergedFiles = new GitSimpleEventDetector(GitSimpleEventDetector.Event.UNMERGED_PREVENTING_MERGE);
GitUntrackedFilesOverwrittenByOperationDetector untrackedOverwrittenByMerge = new GitUntrackedFilesOverwrittenByOperationDetector(root);
GitSimpleEventDetector mergeConflict = new GitSimpleEventDetector(GitSimpleEventDetector.Event.MERGE_CONFLICT);
GitSimpleEventDetector alreadyUpToDateDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.ALREADY_UP_TO_DATE);
GitCommandResult result = myGit.merge(repository, myBranchToMerge, Collections.<String>emptyList(), localChangesDetector, unmergedFiles, untrackedOverwrittenByMerge, mergeConflict, alreadyUpToDateDetector);
if (result.success()) {
LOG.info("Merged successfully");
refresh(repository);
markSuccessful(repository);
if (alreadyUpToDateDetector.hasHappened()) {
alreadyUpToDateRepositories += 1;
}
} else if (unmergedFiles.hasHappened()) {
LOG.info("Unmerged files error!");
fatalUnmergedFilesError();
fatalErrorHappened = true;
} else if (localChangesDetector.wasMessageDetected()) {
LOG.info("Local changes would be overwritten by merge!");
boolean smartMergeSucceeded = proposeSmartMergePerformAndNotify(repository, localChangesDetector);
if (!smartMergeSucceeded) {
fatalErrorHappened = true;
}
} else if (mergeConflict.hasHappened()) {
LOG.info("Merge conflict");
myConflictedRepositories.put(repository, Boolean.FALSE);
refresh(repository);
markSuccessful(repository);
} else if (untrackedOverwrittenByMerge.wasMessageDetected()) {
LOG.info("Untracked files would be overwritten by merge!");
fatalUntrackedFilesError(repository.getRoot(), untrackedOverwrittenByMerge.getRelativeFilePaths());
fatalErrorHappened = true;
} else {
LOG.info("Unknown error. " + result);
fatalError(getCommonErrorTitle(), result.getErrorOutputAsJoinedString());
fatalErrorHappened = true;
}
}
if (fatalErrorHappened) {
notifyAboutRemainingConflicts();
} else {
boolean allConflictsResolved = resolveConflicts();
if (allConflictsResolved) {
if (alreadyUpToDateRepositories < getRepositories().size()) {
notifySuccess();
} else {
notifySuccess("Already up-to-date");
}
}
}
restoreLocalChanges();
} finally {
token.finish();
}
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class GitResetOperation method execute.
public void execute() {
saveAllDocuments();
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
Map<GitRepository, GitCommandResult> results = ContainerUtil.newHashMap();
try {
for (Map.Entry<GitRepository, Hash> entry : myCommits.entrySet()) {
GitRepository repository = entry.getKey();
VirtualFile root = repository.getRoot();
String target = entry.getValue().asString();
GitLocalChangesWouldBeOverwrittenDetector detector = new GitLocalChangesWouldBeOverwrittenDetector(root, RESET);
GitCommandResult result = myGit.reset(repository, myMode, target, detector);
if (!result.success() && detector.wasMessageDetected()) {
GitCommandResult smartResult = proposeSmartReset(detector, repository, target);
if (smartResult != null) {
result = smartResult;
}
}
results.put(repository, result);
repository.update();
VfsUtil.markDirtyAndRefresh(false, true, false, root);
VcsDirtyScopeManager.getInstance(myProject).dirDirtyRecursively(root);
}
} finally {
token.finish();
}
notifyResult(results);
}
Aggregations