Search in sources :

Example 16 with AccessToken

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();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FakeVirtualFile(com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) AccessToken(com.intellij.openapi.application.AccessToken) FakeVirtualFile(com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Pair(com.intellij.openapi.util.Pair)

Example 17 with AccessToken

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());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitLineHandler(git4idea.commands.GitLineHandler) GitStashDialog(git4idea.ui.GitStashDialog) AccessToken(com.intellij.openapi.application.AccessToken) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager)

Example 18 with AccessToken

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());
    }
}
Also used : GitLineHandler(git4idea.commands.GitLineHandler) GitResetDialog(git4idea.ui.GitResetDialog) AccessToken(com.intellij.openapi.application.AccessToken) GitRepositoryManager(git4idea.repo.GitRepositoryManager)

Example 19 with AccessToken

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();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) AccessToken(com.intellij.openapi.application.AccessToken)

Example 20 with AccessToken

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) GitLocalChangesWouldBeOverwrittenDetector(git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector) AccessToken(com.intellij.openapi.application.AccessToken) GitCommandResult(git4idea.commands.GitCommandResult) Hash(com.intellij.vcs.log.Hash) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)13 Project (com.intellij.openapi.project.Project)12 Document (com.intellij.openapi.editor.Document)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)9 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)6 File (java.io.File)5 IOException (java.io.IOException)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)4 PsiFile (com.intellij.psi.PsiFile)4 List (java.util.List)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 ReadAction (com.intellij.openapi.application.ReadAction)3 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3