From 914f26ecfee149920f5fef585b56a6bf618d7883 Mon Sep 17 00:00:00 2001 From: Irina Chernushina Date: Wed, 23 Sep 2009 18:37:36 +0400 Subject: [PATCH] VCS: option to turn off background checks for "changed on server" --- .../src/messages/VcsBundle.properties | 1 + .../com/intellij/openapi/vcs/VcsConfiguration.java | 1 + .../openapi/vcs/changes/ControlledCycle.java | 62 +++++++++++++++++++ .../openapi/vcs/changes/RemoteRevisionsCache.java | 69 +++++++--------------- .../VcsBackgroundOperationsConfigurationPanel.form | 10 +++- .../VcsBackgroundOperationsConfigurationPanel.java | 10 ++++ 6 files changed, 103 insertions(+), 50 deletions(-) create mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ControlledCycle.java diff --git a/platform/platform-resources-en/src/messages/VcsBundle.properties b/platform/platform-resources-en/src/messages/VcsBundle.properties index 648a5e8097..4abb9820f2 100644 --- a/platform/platform-resources-en/src/messages/VcsBundle.properties +++ b/platform/platform-resources-en/src/messages/VcsBundle.properties @@ -532,3 +532,4 @@ annotation.switch.to.merged.text=Show merge sources all.vcs.init.message.text=Initializing VCS... switch.to.changelist=Switch &to changelist (''{0}'') move.to.changelist=&Move changes to active changelist (''{0}'') +vcs.config.track.changed.on.server=Check "changed on server" conflicts in background diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java index ab3c1b5331..88efdf966a 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java @@ -61,6 +61,7 @@ public final class VcsConfiguration implements PersistentStateComponent public boolean PERFORM_CHECKOUT_IN_BACKGROUND = true; public boolean PERFORM_ADD_REMOVE_IN_BACKGROUND = true; public boolean PERFORM_ROLLBACK_IN_BACKGROUND = false; + public volatile boolean CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND = true; public VcsShowConfirmationOption.Value MOVE_TO_FAILED_COMMIT_CHANGELIST = VcsShowConfirmationOption.Value.SHOW_CONFIRMATION; public enum StandardOption { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ControlledCycle.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ControlledCycle.java new file mode 100644 index 0000000000..527589bb58 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ControlledCycle.java @@ -0,0 +1,62 @@ +package com.intellij.openapi.vcs.changes; + +import com.intellij.lifecycle.ControlledAlarmFactory; +import com.intellij.lifecycle.SlowlyClosingAlarm; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Getter; +import com.intellij.util.Alarm; + +import java.util.concurrent.atomic.AtomicBoolean; + +public class ControlledCycle implements Runnable { + private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.ControlledCycle"); + + private final Alarm mySimpleAlarm; + private final SlowlyClosingAlarm myControlledAlarm; + // this interval is also to check for not initialized paths, so it is rather small + private static final int ourRefreshInterval = 10000; + private final Runnable myRunnable; + + private final AtomicBoolean myActive; + + public ControlledCycle(final Project project, final Getter runnable) { + myActive = new AtomicBoolean(false); + myRunnable = new Runnable() { + boolean shouldBeContinued = true; + public void run() { + try { + shouldBeContinued = Boolean.TRUE.equals(runnable.get()); + } catch (ProcessCanceledException e) { + // + } catch (RuntimeException e) { + LOG.info(e); + } + if (! shouldBeContinued) { + myActive.set(false); + } else { + mySimpleAlarm.addRequest(ControlledCycle.this, ourRefreshInterval); + } + } + }; + mySimpleAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD, project); + myControlledAlarm = ControlledAlarmFactory.createOnApplicationPooledThread(project); + } + + public void start() { + final boolean wasSet = myActive.compareAndSet(false, true); + if (wasSet) { + mySimpleAlarm.addRequest(this, ourRefreshInterval); + } + } + + public void run() { + try { + myControlledAlarm.checkShouldExit(); + myControlledAlarm.addRequest(myRunnable); + } catch (ProcessCanceledException e) { + // + } + } +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsCache.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsCache.java index d2bd7ffae1..3ceb555610 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsCache.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsCache.java @@ -1,20 +1,17 @@ package com.intellij.openapi.vcs.changes; -import com.intellij.lifecycle.ControlledAlarmFactory; -import com.intellij.lifecycle.SlowlyClosingAlarm; import com.intellij.openapi.Disposable; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.Getter; import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.changes.ui.RemoteStatusChangeNodeDecorator; import com.intellij.openapi.vcs.update.UpdateFilesHelper; import com.intellij.openapi.vcs.update.UpdatedFiles; import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.util.Alarm; import com.intellij.util.Consumer; import com.intellij.util.messages.Topic; @@ -38,6 +35,7 @@ public class RemoteRevisionsCache implements PlusMinus private final Project myProject; private final Object myLock; private final Map myKinds; + private ControlledCycle myControlledCycle; public static RemoteRevisionsCache getInstance(final Project project) { return ServiceManager.getService(project, RemoteRevisionsCache.class); @@ -62,16 +60,27 @@ public class RemoteRevisionsCache implements PlusMinus } }); updateKinds(); - final MyRecursiveUpdateRequest request = new MyRecursiveUpdateRequest(project, new Runnable() { - public void run() { - boolean somethingChanged = myRemoteRevisionsNumbersCache.updateStep(); - somethingChanged |= myRemoteRevisionsStateCache.updateStep(); - if (somethingChanged) { - myProject.getMessageBus().syncPublisher(REMOTE_VERSION_CHANGED).run(); + myControlledCycle = new ControlledCycle(project, new Getter() { + public Boolean get() { + final boolean shouldBeDone = VcsConfiguration.getInstance(myProject).CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND; + if (shouldBeDone) { + boolean somethingChanged = myRemoteRevisionsNumbersCache.updateStep(); + somethingChanged |= myRemoteRevisionsStateCache.updateStep(); + if (somethingChanged) { + myProject.getMessageBus().syncPublisher(REMOTE_VERSION_CHANGED).run(); + } } + return shouldBeDone; } }); - request.start(); + if ((! myProject.isDefault()) && VcsConfiguration.getInstance(myProject).CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND) { + myControlledCycle.start(); + } + } + + public void startRefreshInBackground() { + if (myProject.isDefault()) return; + myControlledCycle.start(); } private void updateKinds() { @@ -86,44 +95,6 @@ public class RemoteRevisionsCache implements PlusMinus } } - private static class MyRecursiveUpdateRequest implements Runnable { - private final Alarm mySimpleAlarm; - private final SlowlyClosingAlarm myControlledAlarm; - // this interval is also to check for not initialized paths, so it is rather small - private static final int ourRefreshInterval = 1000; - private final Runnable myRunnable; - - private MyRecursiveUpdateRequest(final Project project, final Runnable runnable) { - myRunnable = new Runnable() { - public void run() { - try { - runnable.run(); - } catch (ProcessCanceledException e) { - // - } catch (RuntimeException e) { - LOG.info(e); - } - mySimpleAlarm.addRequest(MyRecursiveUpdateRequest.this, ourRefreshInterval); - } - }; - mySimpleAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD, project); - myControlledAlarm = ControlledAlarmFactory.createOnApplicationPooledThread(project); - } - - public void start() { - mySimpleAlarm.addRequest(this, ourRefreshInterval); - } - - public void run() { - try { - myControlledAlarm.checkShouldExit(); - myControlledAlarm.addRequest(myRunnable); - } catch (ProcessCanceledException e) { - // - } - } - } - public void directoryMappingChanged() { updateKinds(); myRemoteRevisionsNumbersCache.directoryMappingChanged(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.form b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.form index 2edfc730bc..c00dd1be23 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.form +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.form @@ -16,7 +16,7 @@ - + @@ -84,6 +84,14 @@ + + + + + + + + diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.java index 6e892fdea2..d791cb3651 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.java @@ -5,6 +5,7 @@ import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.openapi.vcs.VcsShowOptionsSettingImpl; +import com.intellij.openapi.vcs.changes.RemoteRevisionsCache; import org.jetbrains.annotations.Nls; import javax.swing.*; @@ -23,6 +24,7 @@ public class VcsBackgroundOperationsConfigurationPanel implements Configurable { private JCheckBox myCbAddRemoveInBackground; private JCheckBox myCbCheckoutInBackground; private JCheckBox myPerformRevertInBackgroundCheckBox; + private JCheckBox myTrackChangedOnServer; public VcsBackgroundOperationsConfigurationPanel(final Project project) { @@ -40,6 +42,10 @@ public class VcsBackgroundOperationsConfigurationPanel implements Configurable { settings.PERFORM_EDIT_IN_BACKGROUND = myCbEditInBackground.isSelected(); settings.PERFORM_ADD_REMOVE_IN_BACKGROUND = myCbAddRemoveInBackground.isSelected(); settings.PERFORM_ROLLBACK_IN_BACKGROUND = myPerformRevertInBackgroundCheckBox.isSelected(); + if ((! settings.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND) && myTrackChangedOnServer.isSelected()) { + RemoteRevisionsCache.getInstance(myProject).startRefreshInBackground(); + } + settings.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND = myTrackChangedOnServer.isSelected(); for (VcsShowOptionsSettingImpl setting : myPromptOptions.keySet()) { setting.setValue(myPromptOptions.get(setting).isSelected()); @@ -71,6 +77,9 @@ public class VcsBackgroundOperationsConfigurationPanel implements Configurable { if (settings.PERFORM_ROLLBACK_IN_BACKGROUND != myPerformRevertInBackgroundCheckBox.isSelected()) { return true; } + if (settings.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND != myTrackChangedOnServer.isSelected()) { + return true; + } return false; } @@ -83,6 +92,7 @@ public class VcsBackgroundOperationsConfigurationPanel implements Configurable { myCbEditInBackground.setSelected(settings.PERFORM_EDIT_IN_BACKGROUND); myCbAddRemoveInBackground.setSelected(settings.PERFORM_ADD_REMOVE_IN_BACKGROUND); myPerformRevertInBackgroundCheckBox.setSelected(settings.PERFORM_ROLLBACK_IN_BACKGROUND); + myTrackChangedOnServer.setSelected(settings.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND); for (VcsShowOptionsSettingImpl setting : myPromptOptions.keySet()) { myPromptOptions.get(setting).setSelected(setting.getValue()); } -- 2.11.4.GIT