From 1d508d78ee3b88413c598218d337f43453cde34b Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 28 Oct 2014 13:15:46 +0300 Subject: [PATCH] HeavyProcessLatch API slightly changed to handle overlapping processes correctly --- .../ProjectStructureConfigurable.java | 5 ++-- .../src/com/intellij/dvcs/DvcsUtil.java | 10 ++++--- .../ide/startup/impl/StartupManagerImpl.java | 5 ++-- .../application/impl/ApplicationImpl.java | 4 +-- .../components/impl/ServiceManagerImpl.java | 5 ++-- .../openapi/project/DumbServiceImpl.java | 9 +++--- .../openapi/vfs/newvfs/RefreshQueueImpl.java | 5 ++-- .../util/io/storage/HeavyProcessLatch.java | 22 ++++++++++---- .../src/git4idea/actions/GitMergeAction.java | 5 ++-- .../src/git4idea/actions/GitRebaseAbort.java | 7 +++-- .../git4idea/actions/GitRebaseActionBase.java | 7 +++-- .../src/git4idea/actions/GitResetHead.java | 7 +++-- .../src/git4idea/actions/GitStash.java | 7 +++-- .../git4idea/branch/GitCheckoutOperation.java | 7 +++-- .../git4idea/branch/GitMergeOperation.java | 7 +++-- .../git4idea/cherrypick/GitCherryPicker.java | 7 +++-- .../src/git4idea/rebase/GitRebaser.java | 11 +++---- .../src/git4idea/reset/GitResetOperation.java | 5 ++-- .../rollback/GitRollbackEnvironment.java | 7 +++-- .../src/git4idea/ui/GitUnstashDialog.java | 7 +++-- .../src/git4idea/update/GitUpdateProcess.java | 7 +++-- .../plugins/github/GithubRebaseAction.java | 29 +++++++++++-------- .../zmlx/hg4idea/command/HgMergeCommand.java | 5 ++-- .../zmlx/hg4idea/command/HgRebaseCommand.java | 5 ++-- .../zmlx/hg4idea/command/HgUpdateCommand.java | 5 ++-- .../provider/HgRollbackEnvironment.java | 9 +++--- 26 files changed, 124 insertions(+), 85 deletions(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index d72269f41733..21626c32a7cf 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -19,6 +19,7 @@ import com.intellij.compiler.server.BuildManager; import com.intellij.facet.Facet; import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; @@ -352,7 +353,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se public void reset() { // need this to ensure VFS operations will not block because of storage flushing // and other maintenance IO tasks run in background - HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure"); + AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure"); try { myWasUiDisposed = false; @@ -387,7 +388,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se } } finally { - HeavyProcessLatch.INSTANCE.processFinished(); + token.finish(); } } diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java b/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java index bd30a10362b3..14643c274702 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java @@ -18,6 +18,7 @@ package com.intellij.dvcs; import com.intellij.dvcs.repo.Repository; import com.intellij.dvcs.repo.RepositoryManager; import com.intellij.ide.file.BatchFileChangeListener; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; @@ -189,13 +190,14 @@ public class DvcsUtil { return DateFormatUtil.formatPrettyDateTime(commit.getTimestamp()) + " "; } - public static void workingTreeChangeStarted(@NotNull Project project) { - HeavyProcessLatch.INSTANCE.processStarted("Changing DVCS working tree"); + @NotNull + public static AccessToken workingTreeChangeStarted(@NotNull Project project) { ApplicationManager.getApplication().getMessageBus().syncPublisher(BatchFileChangeListener.TOPIC).batchChangeStarted(project); + return HeavyProcessLatch.INSTANCE.processStarted("Changing DVCS working tree"); } - public static void workingTreeChangeFinished(@NotNull Project project) { - HeavyProcessLatch.INSTANCE.processFinished(); + public static void workingTreeChangeFinished(@NotNull Project project, @NotNull AccessToken token) { + token.finish(); ApplicationManager.getApplication().getMessageBus().syncPublisher(BatchFileChangeListener.TOPIC).batchChangeCompleted(project); } diff --git a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java index b4128553a480..b3b23dc86a56 100644 --- a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java @@ -17,6 +17,7 @@ package com.intellij.ide.startup.impl; import com.intellij.ide.caches.CacheUpdater; import com.intellij.ide.startup.StartupManagerEx; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.application.ApplicationManager; @@ -113,7 +114,7 @@ public class StartupManagerImpl extends StartupManagerEx { @Override @SuppressWarnings("SynchronizeOnThis") public void run() { - HeavyProcessLatch.INSTANCE.processStarted("Running Startup Activities"); + AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Running Startup Activities"); try { runActivities(myPreStartupActivities); @@ -133,7 +134,7 @@ public class StartupManagerImpl extends StartupManagerEx { } } finally { - HeavyProcessLatch.INSTANCE.processFinished(); + token.finish(); } } }); diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 7194dbddaecb..4a500fc2a321 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -502,7 +502,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App myIsFiringLoadingEvent = false; } - HeavyProcessLatch.INSTANCE.processStarted("Loading application components"); + AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Loading application components"); try { store.load(); } @@ -510,7 +510,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App throw new IOException(e.getMessage()); } finally { - HeavyProcessLatch.INSTANCE.processFinished(); + token.finish(); } myLoaded = true; diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/ServiceManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/ServiceManagerImpl.java index a315e8f2560c..b568ce9e6bad 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/ServiceManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/ServiceManagerImpl.java @@ -16,6 +16,7 @@ package com.intellij.openapi.components.impl; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.BaseComponent; import com.intellij.openapi.components.ComponentConfig; @@ -199,7 +200,7 @@ public class ServiceManagerImpl implements BaseComponent { @Override public Object compute() { // prevent storages from flushing and blocking FS - HeavyProcessLatch.INSTANCE.processStarted("Creating component '" + myDescriptor.getImplementation()+"'"); + AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Creating component '" + myDescriptor.getImplementation() + "'"); try { synchronized (MyComponentAdapter.this) { Object instance = myInitializedComponentInstance; @@ -209,7 +210,7 @@ public class ServiceManagerImpl implements BaseComponent { } } finally { - HeavyProcessLatch.INSTANCE.processFinished(); + token.finish(); } } }); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java index 7860d4364f9d..18d0f692e6ad 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java @@ -18,6 +18,7 @@ package com.intellij.openapi.project; import com.intellij.ide.IdeBundle; import com.intellij.ide.caches.CacheUpdater; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; @@ -152,12 +153,12 @@ public class DumbServiceImpl extends DumbService implements Disposable { if (indicator != null) { indicator.pushState(); } + AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Performing indexing task"); try { - HeavyProcessLatch.INSTANCE.processStarted("Performing indexing task"); task.performInDumbMode(indicator != null ? indicator : new EmptyProgressIndicator()); } finally { - HeavyProcessLatch.INSTANCE.processFinished(); + token.finish(); if (indicator != null) { indicator.popState(); } @@ -336,8 +337,8 @@ public class DumbServiceImpl extends DumbService implements Disposable { public void run(@NotNull final ProgressIndicator visibleIndicator) { final ShutDownTracker shutdownTracker = ShutDownTracker.getInstance(); final Thread self = Thread.currentThread(); + AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Performing indexing tasks"); try { - HeavyProcessLatch.INSTANCE.processStarted("Performing indexing tasks"); shutdownTracker.registerStopperThread(self); if (visibleIndicator instanceof ProgressIndicatorEx) { @@ -362,7 +363,7 @@ public class DumbServiceImpl extends DumbService implements Disposable { } finally { shutdownTracker.unregisterStopperThread(self); - HeavyProcessLatch.INSTANCE.processFinished(); + token.finish(); } } }); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java index 8c777e75d21e..12765fedb7a7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.vfs.newvfs; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; @@ -74,12 +75,12 @@ public class RefreshQueueImpl extends RefreshQueue { public void run() { try { myRefreshIndicator.start(); - HeavyProcessLatch.INSTANCE.processStarted("Doing file refresh. "+session.toString()); + AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Doing file refresh. " + session.toString()); try { doScan(session); } finally { - HeavyProcessLatch.INSTANCE.processFinished(); + token.finish(); myRefreshIndicator.stop(); } } diff --git a/platform/util/src/com/intellij/util/io/storage/HeavyProcessLatch.java b/platform/util/src/com/intellij/util/io/storage/HeavyProcessLatch.java index 29e77633c756..4042844974f6 100644 --- a/platform/util/src/com/intellij/util/io/storage/HeavyProcessLatch.java +++ b/platform/util/src/com/intellij/util/io/storage/HeavyProcessLatch.java @@ -20,16 +20,18 @@ package com.intellij.util.io.storage; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.AccessToken; import com.intellij.util.EventDispatcher; +import com.intellij.util.containers.ConcurrentHashSet; import org.jetbrains.annotations.NotNull; import java.util.EventListener; -import java.util.Stack; +import java.util.Set; public class HeavyProcessLatch { public static final HeavyProcessLatch INSTANCE = new HeavyProcessLatch(); - private final Stack myHeavyProcesses = new Stack(); + private final Set myHeavyProcesses = new ConcurrentHashSet(); private final EventDispatcher myEventDispatcher = EventDispatcher.create(HeavyProcessListener.class); private HeavyProcessLatch() { @@ -43,13 +45,21 @@ public class HeavyProcessLatch { processStarted(""); } - public void processStarted(@NotNull String operationName) { - myHeavyProcesses.push(operationName); + @NotNull + public AccessToken processStarted(@NotNull final String operationName) { + myHeavyProcesses.add(operationName); myEventDispatcher.getMulticaster().processStarted(); + return new AccessToken() { + @Override + public void finish() { + myHeavyProcesses.remove(operationName); + } + }; } + @Deprecated // use processStarted(String) public void processFinished() { - myHeavyProcesses.pop(); + myHeavyProcesses.remove(""); myEventDispatcher.getMulticaster().processFinished(); } @@ -59,7 +69,7 @@ public class HeavyProcessLatch { public String getRunningOperationName() { synchronized (myHeavyProcesses) { - return myHeavyProcesses.isEmpty() ? null : myHeavyProcesses.peek(); + return myHeavyProcesses.isEmpty() ? null : myHeavyProcesses.iterator().next(); } } diff --git a/plugins/git4idea/src/git4idea/actions/GitMergeAction.java b/plugins/git4idea/src/git4idea/actions/GitMergeAction.java index c2e172525307..6a730eac7e83 100644 --- a/plugins/git4idea/src/git4idea/actions/GitMergeAction.java +++ b/plugins/git4idea/src/git4idea/actions/GitMergeAction.java @@ -18,6 +18,7 @@ package git4idea.actions; import com.intellij.dvcs.DvcsUtil; import com.intellij.history.Label; import com.intellij.history.LocalHistory; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; @@ -86,7 +87,7 @@ abstract class GitMergeAction extends GitRepositoryAction { final GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(selectedRoot); - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { GitCommandResult result = git.runCommand(new Computable() { @Override @@ -109,7 +110,7 @@ abstract class GitMergeAction extends GitRepositoryAction { handleResult(result, project, localChangesDetector, untrackedFilesDetector, repository, currentRev, affectedRoots, beforeLabel); } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } } diff --git a/plugins/git4idea/src/git4idea/actions/GitRebaseAbort.java b/plugins/git4idea/src/git4idea/actions/GitRebaseAbort.java index 3edd559a8e51..b36055c118ab 100644 --- a/plugins/git4idea/src/git4idea/actions/GitRebaseAbort.java +++ b/plugins/git4idea/src/git4idea/actions/GitRebaseAbort.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package git4idea.actions; import com.intellij.dvcs.DvcsUtil; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vcs.VcsException; @@ -75,12 +76,12 @@ public class GitRebaseAbort extends GitRepositoryAction { GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.REBASE); h.setStdoutSuppressed(false); h.addParameters("--abort"); - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { GitHandlerUtil.doSynchronously(h, getActionName(), h.printableCommandLine()); } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } } diff --git a/plugins/git4idea/src/git4idea/actions/GitRebaseActionBase.java b/plugins/git4idea/src/git4idea/actions/GitRebaseActionBase.java index 95246459fc1d..19de14769081 100644 --- a/plugins/git4idea/src/git4idea/actions/GitRebaseActionBase.java +++ b/plugins/git4idea/src/git4idea/actions/GitRebaseActionBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package git4idea.actions; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vcs.VcsException; @@ -65,7 +66,7 @@ public abstract class GitRebaseActionBase extends GitRepositoryAction { task.executeInBackground(false, new GitTaskResultHandlerAdapter() { @Override protected void run(GitTaskResult taskResult) { - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { editor.close(); GitRepositoryManager manager = GitUtil.getRepositoryManager(project); @@ -74,7 +75,7 @@ public abstract class GitRebaseActionBase extends GitRepositoryAction { notifyAboutErrorResult(taskResult, resultListener, exceptions, project); } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } } }); diff --git a/plugins/git4idea/src/git4idea/actions/GitResetHead.java b/plugins/git4idea/src/git4idea/actions/GitResetHead.java index 0aa7180fba92..3a739d0e473f 100644 --- a/plugins/git4idea/src/git4idea/actions/GitResetHead.java +++ b/plugins/git4idea/src/git4idea/actions/GitResetHead.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package git4idea.actions; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; @@ -57,12 +58,12 @@ public class GitResetHead extends GitRepositoryAction { } GitLineHandler h = d.handler(); affectedRoots.add(d.getGitRoot()); - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { GitHandlerUtil.doSynchronously(h, GitBundle.getString("resetting.title"), h.printableCommandLine()); } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } GitRepositoryManager manager = GitUtil.getRepositoryManager(project); manager.updateRepository(d.getGitRoot()); diff --git a/plugins/git4idea/src/git4idea/actions/GitStash.java b/plugins/git4idea/src/git4idea/actions/GitStash.java index 20fd525929ea..b5a4892a30fd 100644 --- a/plugins/git4idea/src/git4idea/actions/GitStash.java +++ b/plugins/git4idea/src/git4idea/actions/GitStash.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package git4idea.actions; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsException; @@ -54,12 +55,12 @@ public class GitStash extends GitRepositoryAction { VirtualFile root = d.getGitRoot(); affectedRoots.add(root); final GitLineHandler h = d.handler(); - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { GitHandlerUtil.doSynchronously(h, GitBundle.getString("stashing.title"), h.printableCommandLine()); } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } ServiceManager.getService(project, GitPlatformFacade.class).hardRefresh(root); } diff --git a/plugins/git4idea/src/git4idea/branch/GitCheckoutOperation.java b/plugins/git4idea/src/git4idea/branch/GitCheckoutOperation.java index 5e0a10c039ee..8327a614725c 100644 --- a/plugins/git4idea/src/git4idea/branch/GitCheckoutOperation.java +++ b/plugins/git4idea/src/git4idea/branch/GitCheckoutOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package git4idea.branch; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; @@ -65,7 +66,7 @@ class GitCheckoutOperation extends GitBranchOperation { protected void execute() { saveAllDocuments(); boolean fatalErrorHappened = false; - DvcsUtil.workingTreeChangeStarted(myProject); + AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { while (hasMoreRepositories() && !fatalErrorHappened) { final GitRepository repository = next(); @@ -104,7 +105,7 @@ class GitCheckoutOperation extends GitBranchOperation { } } finally { - DvcsUtil.workingTreeChangeFinished(myProject); + DvcsUtil.workingTreeChangeFinished(myProject, token); } if (!fatalErrorHappened) { diff --git a/plugins/git4idea/src/git4idea/branch/GitMergeOperation.java b/plugins/git4idea/src/git4idea/branch/GitMergeOperation.java index db92107629cf..5a0d6a031f98 100644 --- a/plugins/git4idea/src/git4idea/branch/GitMergeOperation.java +++ b/plugins/git4idea/src/git4idea/branch/GitMergeOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package git4idea.branch; import com.intellij.dvcs.DvcsUtil; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -73,7 +74,7 @@ class GitMergeOperation extends GitBranchOperation { saveAllDocuments(); boolean fatalErrorHappened = false; int alreadyUpToDateRepositories = 0; - DvcsUtil.workingTreeChangeStarted(myProject); + AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { while (hasMoreRepositories() && !fatalErrorHappened) { final GitRepository repository = next(); @@ -147,7 +148,7 @@ class GitMergeOperation extends GitBranchOperation { restoreLocalChanges(); } finally { - DvcsUtil.workingTreeChangeFinished(myProject); + DvcsUtil.workingTreeChangeFinished(myProject, token); } } diff --git a/plugins/git4idea/src/git4idea/cherrypick/GitCherryPicker.java b/plugins/git4idea/src/git4idea/cherrypick/GitCherryPicker.java index 4e3c3183cf16..77196722f24a 100644 --- a/plugins/git4idea/src/git4idea/cherrypick/GitCherryPicker.java +++ b/plugins/git4idea/src/git4idea/cherrypick/GitCherryPicker.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package git4idea.cherrypick; import com.intellij.dvcs.DvcsUtil; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -90,7 +91,7 @@ public class GitCherryPicker { public void cherryPick(@NotNull Map> commitsInRoots) { List successfulCommits = ContainerUtil.newArrayList(); List alreadyPicked = ContainerUtil.newArrayList(); - DvcsUtil.workingTreeChangeStarted(myProject); + AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { for (Map.Entry> entry : commitsInRoots.entrySet()) { GitRepository repository = entry.getKey(); @@ -103,7 +104,7 @@ public class GitCherryPicker { notifyResult(successfulCommits, alreadyPicked); } finally { - DvcsUtil.workingTreeChangeFinished(myProject); + DvcsUtil.workingTreeChangeFinished(myProject, token); } } diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaser.java b/plugins/git4idea/src/git4idea/rebase/GitRebaser.java index d44988c48aac..75e28742b965 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaser.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package git4idea.rebase; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; @@ -91,8 +92,8 @@ public class GitRebaser { rebaseTask.setProgressAnalyzer(new GitStandardProgressAnalyzer()); final AtomicReference updateResult = new AtomicReference(); final AtomicBoolean failure = new AtomicBoolean(); + AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { - DvcsUtil.workingTreeChangeStarted(myProject); rebaseTask.executeInBackground(true, new GitTaskResultHandlerAdapter() { @Override protected void onSuccess() { @@ -118,7 +119,7 @@ public class GitRebaser { } } finally { - DvcsUtil.workingTreeChangeFinished(myProject); + DvcsUtil.workingTreeChangeFinished(myProject, token); } return updateResult.get(); } @@ -146,7 +147,7 @@ public class GitRebaser { * @return true if rebase successfully finished. */ public boolean continueRebase(@NotNull Collection rebasingRoots) { - DvcsUtil.workingTreeChangeStarted(myProject); + AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { boolean success = true; for (VirtualFile root : rebasingRoots) { @@ -155,7 +156,7 @@ public class GitRebaser { return success; } finally { - DvcsUtil.workingTreeChangeFinished(myProject); + DvcsUtil.workingTreeChangeFinished(myProject, token); } } diff --git a/plugins/git4idea/src/git4idea/reset/GitResetOperation.java b/plugins/git4idea/src/git4idea/reset/GitResetOperation.java index 528a9e1277f3..802137737c89 100644 --- a/plugins/git4idea/src/git4idea/reset/GitResetOperation.java +++ b/plugins/git4idea/src/git4idea/reset/GitResetOperation.java @@ -17,6 +17,7 @@ package git4idea.reset; import com.intellij.dvcs.DvcsUtil; import com.intellij.dvcs.repo.RepositoryUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.ProgressIndicator; @@ -76,7 +77,7 @@ public class GitResetOperation { public void execute() { saveAllDocuments(); - DvcsUtil.workingTreeChangeStarted(myProject); + AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); Map results = ContainerUtil.newHashMap(); try { for (Map.Entry entry : myCommits.entrySet()) { @@ -99,7 +100,7 @@ public class GitResetOperation { } } finally { - DvcsUtil.workingTreeChangeFinished(myProject); + DvcsUtil.workingTreeChangeFinished(myProject, token); } notifyResult(results); } diff --git a/plugins/git4idea/src/git4idea/rollback/GitRollbackEnvironment.java b/plugins/git4idea/src/git4idea/rollback/GitRollbackEnvironment.java index 87b256db62d6..ea4570ce30e9 100644 --- a/plugins/git4idea/src/git4idea/rollback/GitRollbackEnvironment.java +++ b/plugins/git4idea/src/git4idea/rollback/GitRollbackEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package git4idea.rollback; import com.intellij.dvcs.DvcsUtil; import com.intellij.lifecycle.PeriodicalTasksCloser; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsException; @@ -142,7 +143,7 @@ public class GitRollbackEnvironment implements RollbackEnvironment { } } // revert files from HEAD - DvcsUtil.workingTreeChangeStarted(myProject); + AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { for (Map.Entry> entry : toRevert.entrySet()) { listener.accept(entry.getValue()); @@ -155,7 +156,7 @@ public class GitRollbackEnvironment implements RollbackEnvironment { } } finally { - DvcsUtil.workingTreeChangeFinished(myProject); + DvcsUtil.workingTreeChangeFinished(myProject,token); } LocalFileSystem lfs = LocalFileSystem.getInstance(); HashSet filesToRefresh = new HashSet(); diff --git a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java index 18f1f5ea6d5a..93278d15ee21 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java +++ b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import com.intellij.dvcs.DvcsUtil; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.ServiceManager; @@ -357,7 +358,7 @@ public class GitUnstashDialog extends DialogWrapper { h.addLineListener(untrackedFilesDetector); h.addLineListener(localChangesDetector); - DvcsUtil.workingTreeChangeStarted(myProject); + AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { final Ref result = Ref.create(); ProgressManager.getInstance().run(new Task.Modal(h.project(), GitBundle.getString("unstash.unstashing"), false) { @@ -384,7 +385,7 @@ public class GitUnstashDialog extends DialogWrapper { } } finally { - DvcsUtil.workingTreeChangeFinished(myProject); + DvcsUtil.workingTreeChangeFinished(myProject, token); } super.doOKAction(); } diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java index c7423b2a2112..636ad2c920c2 100644 --- a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java +++ b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package git4idea.update; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.EmptyProgressIndicator; @@ -133,12 +134,12 @@ public class GitUpdateProcess { GitComplexProcess.Operation updateOperation = new GitComplexProcess.Operation() { @Override public void run(ContinuationContext continuationContext) { - DvcsUtil.workingTreeChangeStarted(myProject); + AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); try { myResult = updateImpl(updateMethod, continuationContext); } finally { - DvcsUtil.workingTreeChangeFinished(myProject); + DvcsUtil.workingTreeChangeFinished(myProject, token); } } }; diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java index 7b7bfabf73c8..3efd666d3ed7 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.jetbrains.plugins.github; import com.intellij.dvcs.DvcsUtil; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; @@ -229,18 +230,22 @@ public class GithubRebaseAction extends DumbAwareAction { @NotNull final ProgressIndicator indicator) { final Git git = ServiceManager.getService(project, Git.class); final GitPlatformFacade facade = ServiceManager.getService(project, GitPlatformFacade.class); - DvcsUtil.workingTreeChangeStarted(project); - GitPreservingProcess process = - new GitPreservingProcess(project, facade, git, Collections.singletonList(gitRepository), "Rebasing", "upstream/master", indicator, - new Runnable() { - @Override - public void run() { - doRebaseCurrentBranch(project, gitRepository.getRoot(), indicator); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); + try { + GitPreservingProcess process = + new GitPreservingProcess(project, facade, git, Collections.singletonList(gitRepository), "Rebasing", "upstream/master", indicator, + new Runnable() { + @Override + public void run() { + doRebaseCurrentBranch(project, gitRepository.getRoot(), indicator); + } } - } - ); - process.execute(); - DvcsUtil.workingTreeChangeFinished(project); + ); + process.execute(); + } + finally { + DvcsUtil.workingTreeChangeFinished(project, token); + } } private static void doRebaseCurrentBranch(@NotNull final Project project, diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java index 16c8b7fe0a8b..0a428a9d759e 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java @@ -13,6 +13,7 @@ package org.zmlx.hg4idea.command; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -50,7 +51,7 @@ public class HgMergeCommand { arguments.add("--rev"); arguments.add(revision); } - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { final HgCommandResult result = commandExecutor.executeInCurrentThread(repo, "merge", arguments); @@ -58,7 +59,7 @@ public class HgMergeCommand { return result; } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRebaseCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRebaseCommand.java index 05a5ebda6d7a..25d174cfcaf0 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRebaseCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRebaseCommand.java @@ -13,6 +13,7 @@ package org.zmlx.hg4idea.command; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; @@ -50,7 +51,7 @@ public class HgRebaseCommand { @Nullable private HgCommandResult performRebase(@NotNull String... args) { - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { HgCommandResult result = new HgCommandExecutor(project) @@ -60,7 +61,7 @@ public class HgRebaseCommand { return result; } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgUpdateCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgUpdateCommand.java index 0be4e1602b1e..4e8c06a680dd 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgUpdateCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgUpdateCommand.java @@ -13,6 +13,7 @@ package org.zmlx.hg4idea.command; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.text.StringUtil; @@ -75,7 +76,7 @@ public class HgUpdateCommand { final HgPromptCommandExecutor executor = new HgPromptCommandExecutor(project); executor.setShowOutput(true); HgCommandResult result; - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { result = executor.executeInCurrentThread(repo, "update", arguments); @@ -89,7 +90,7 @@ public class HgUpdateCommand { } } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } project.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(project, null); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgRollbackEnvironment.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgRollbackEnvironment.java index 958bac8ef515..3b536c2fecb7 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgRollbackEnvironment.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgRollbackEnvironment.java @@ -13,6 +13,7 @@ package org.zmlx.hg4idea.provider; import com.intellij.dvcs.DvcsUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vcs.FilePath; @@ -71,7 +72,7 @@ public class HgRollbackEnvironment implements RollbackEnvironment { } } } - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { revert(filePaths); for (FilePath file : toDelete) { @@ -92,18 +93,18 @@ public class HgRollbackEnvironment implements RollbackEnvironment { } } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } } public void rollbackMissingFileDeletion(List files, List exceptions, RollbackProgressListener listener) { - DvcsUtil.workingTreeChangeStarted(project); + AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { revert(files); } finally { - DvcsUtil.workingTreeChangeFinished(project); + DvcsUtil.workingTreeChangeFinished(project, token); } }