Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2017-01-14 22:59:52 +0000
committerAndrey Loskutov2017-01-15 20:15:29 +0000
commit08d562d057ee9e7b149cd9c5c0e325f1a83fa659 (patch)
tree174fc347a0fd76ede2d8ec694e7805fcf0fd4c53
parente0fadc28d9dbb941d5ec54aa97bcd9adb86356d2 (diff)
downloadegit-08d562d057ee9e7b149cd9c5c0e325f1a83fa659.tar.gz
egit-08d562d057ee9e7b149cd9c5c0e325f1a83fa659.tar.xz
egit-08d562d057ee9e7b149cd9c5c0e325f1a83fa659.zip
Provide a way to configure RepositoryChangeScanner interval
RepositoryChangeScanner was triggered every 10 seconds if the UI was active. This is an overkill and causes unneeded CPU load by idling Eclipse. This change increases the interval to 5 minutes, adds new "Refresh interval" preference to the root Git preference page and changes the job in the way that it listens to the preference change. If the preference is set to 0, the job stops automatic repositories change check. Change-Id: I02751334d4cb6dea97f575d24a5fa24c6832eee4 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/Activator.java105
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java1
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitPreferenceRoot.java22
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties2
6 files changed, 105 insertions, 34 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/Activator.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/Activator.java
index 4ebf1c565c..f45d76d289 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/Activator.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/Activator.java
@@ -386,8 +386,8 @@ public class Activator extends AbstractUIPlugin implements DebugOptionsListener
@Override
public void windowActivated(IWorkbenchWindow window) {
updateUiState();
- if (rcs.doReschedule)
- rcs.schedule();
+ // 500: give the UI task a chance to update the active state
+ rcs.schedule(500);
refreshJob.triggerRefresh();
}
};
@@ -589,16 +589,35 @@ public class Activator extends AbstractUIPlugin implements DebugOptionsListener
* A Job that looks at the repository meta data and triggers a refresh of
* the resources in the affected projects.
*/
- static class RepositoryChangeScanner extends Job {
+ private static class RepositoryChangeScanner extends Job
+ implements IPropertyChangeListener {
+
+ // volatile in order to ensure thread synchronization
+ private volatile boolean doReschedule;
+
+ private int interval;
+
+ private final RepositoryCache repositoryCache;
+
RepositoryChangeScanner() {
super(UIText.Activator_repoScanJobName);
setRule(new RepositoryCacheRule());
+ setSystem(true);
+ setUser(false);
+ repositoryCache = org.eclipse.egit.core.Activator.getDefault()
+ .getRepositoryCache();
+ updateRefreshInterval();
}
- // FIXME, need to be more intelligent about this to avoid too much work
- private static final long REPO_SCAN_INTERVAL = 10000L;
- // volatile in order to ensure thread synchronization
- private volatile boolean doReschedule = true;
+ @Override
+ public boolean shouldSchedule() {
+ return doReschedule;
+ }
+
+ @Override
+ public boolean shouldRun() {
+ return doReschedule;
+ }
void setReschedule(boolean reschedule){
doReschedule = reschedule;
@@ -606,20 +625,10 @@ public class Activator extends AbstractUIPlugin implements DebugOptionsListener
@Override
protected IStatus run(IProgressMonitor monitor) {
- if (!doReschedule)
- return Status.OK_STATUS;
-
- // The core plugin might have been stopped before we could cancel
- // this job.
- RepositoryCache repositoryCache = org.eclipse.egit.core.Activator
- .getDefault().getRepositoryCache();
- if (repositoryCache == null)
- return Status.OK_STATUS;
-
// When people use Git from the command line a lot of changes
// may happen. Don't scan when inactive depending on the user's
// choice.
- if (Activator.getDefault().getPreferenceStore()
+ if (getDefault().getPreferenceStore()
.getBoolean(UIPreferences.REFESH_ONLY_WHEN_ACTIVE)) {
if (!isActive()) {
monitor.done();
@@ -628,48 +637,76 @@ public class Activator extends AbstractUIPlugin implements DebugOptionsListener
}
Repository[] repos = repositoryCache.getAllRepositories();
- if (repos.length == 0)
+ if (repos.length == 0) {
return Status.OK_STATUS;
+ }
monitor.beginTask(UIText.Activator_scanningRepositories,
repos.length);
try {
for (Repository repo : repos) {
- if (monitor.isCanceled())
+ if (monitor.isCanceled()) {
break;
- if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
+ }
+ if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive()) {
GitTraceLocation.getTrace().trace(
GitTraceLocation.REPOSITORYCHANGESCANNER
.getLocation(),
"Scanning " + repo + " for changes"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
repo.scanForRepoChanges();
monitor.worked(1);
}
} catch (IOException e) {
- if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
+ if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive()) {
GitTraceLocation.getTrace().trace(
GitTraceLocation.REPOSITORYCHANGESCANNER
.getLocation(),
"Stopped rescheduling " + getName() + "job"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
return createErrorStatus(UIText.Activator_scanError, e);
} finally {
monitor.done();
}
- if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
+ if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive()) {
GitTraceLocation.getTrace().trace(
GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
"Rescheduling " + getName() + " job"); //$NON-NLS-1$ //$NON-NLS-2$
- if (doReschedule)
- schedule(REPO_SCAN_INTERVAL);
+ }
+ schedule(interval);
return Status.OK_STATUS;
}
+
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (!UIPreferences.REFESH_INDEX_INTERVAL
+ .equals(event.getProperty())) {
+ return;
+ }
+ updateRefreshInterval();
+ }
+
+ private void updateRefreshInterval() {
+ interval = getRefreshIndexInterval();
+ setReschedule(interval > 0);
+ cancel();
+ schedule(interval);
+ }
+
+ /**
+ * @return interval in milliseconds for automatic index check, 0 is if
+ * check should be disabled
+ */
+ private static int getRefreshIndexInterval() {
+ return 1000 * getDefault().getPreferenceStore()
+ .getInt(UIPreferences.REFESH_INDEX_INTERVAL);
+ }
}
private void setupRepoChangeScanner() {
rcs = new RepositoryChangeScanner();
- rcs.setSystem(true);
- rcs.schedule(RepositoryChangeScanner.REPO_SCAN_INTERVAL);
+ getPreferenceStore().addPropertyChangeListener(rcs);
}
@Override
@@ -680,32 +717,36 @@ public class Activator extends AbstractUIPlugin implements DebugOptionsListener
}
if (focusListener != null) {
- if (PlatformUI.isWorkbenchRunning())
+ if (PlatformUI.isWorkbenchRunning()) {
PlatformUI.getWorkbench().removeWindowListener(focusListener);
+ }
focusListener = null;
}
- if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
+ if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive()) {
GitTraceLocation.getTrace().trace(
GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
"Trying to cancel " + rcs.getName() + " job"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ getPreferenceStore().removePropertyChangeListener(rcs);
rcs.setReschedule(false);
-
rcs.cancel();
- if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
+ if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive()) {
GitTraceLocation.getTrace().trace(
GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
"Trying to cancel " + refreshJob.getName() + " job"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
refreshJob.cancel();
rcs.join();
refreshJob.join();
- if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
+ if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive()) {
GitTraceLocation.getTrace().trace(
GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
"Jobs terminated"); //$NON-NLS-1$
+ }
if (resourceManager != null) {
resourceManager.dispose();
resourceManager = null;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
index 7fdaa9bf13..a2a2d0380f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
@@ -99,6 +99,7 @@ public class PluginPreferenceInitializer extends AbstractPreferenceInitializer {
store.setDefault(UIPreferences.COMMIT_DIALOG_WARN_ABOUT_MESSAGE_SECOND_LINE, true);
store.setDefault(UIPreferences.COMMIT_DIALOG_SIGNED_OFF_BY, false);
+ store.setDefault(UIPreferences.REFESH_INDEX_INTERVAL, 5 * 60);
store.setDefault(UIPreferences.REFESH_ON_INDEX_CHANGE, true);
store.setDefault(UIPreferences.REFESH_ONLY_WHEN_ACTIVE, true);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
index 5029cc2482..96d582f197 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
@@ -163,6 +163,9 @@ public class UIPreferences {
public static final String DEFAULT_DATE_FORMAT_CHOICE = DATE_FORMAT_CUSTOM;
/** */
public static final String DEFAULT_CHANGESET_FORMAT = "[{author}] ({date}) {short_message}"; //$NON-NLS-1$
+
+ /** interval in seconds to check for repositories index changes */
+ public static final String REFESH_INDEX_INTERVAL = "refesh_index_interval"; //$NON-NLS-1$
/** */
public static final String REFESH_ON_INDEX_CHANGE = "refesh_on_index_change"; //$NON-NLS-1$
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index 75c4231755..538075eedd 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -4620,6 +4620,12 @@ public class UIText extends NLS {
public static String RemoteConnectionPreferencePage_ZeroValueTooltip;
/** */
+ public static String RefreshPreferencesPage_RefreshIndexInterval;
+
+ /** */
+ public static String RefreshPreferencesPage_RefreshIndexIntervalTooltip;
+
+ /** */
public static String RefreshPreferencesPage_RefreshOnlyWhenActive;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitPreferenceRoot.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitPreferenceRoot.java
index 72d3b7fb60..7291f3c3bc 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitPreferenceRoot.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitPreferenceRoot.java
@@ -194,12 +194,30 @@ public class GitPreferenceRoot extends DoublePreferencesPreferencePage
.applyTo(repoChangeScannerGroup);
repoChangeScannerGroup
.setText(UIText.GitPreferenceRoot_RepoChangeScannerGroupHeader);
+
+ IntegerFieldEditor intervalField = new IntegerFieldEditor(
+ UIPreferences.REFESH_INDEX_INTERVAL,
+ UIText.RefreshPreferencesPage_RefreshIndexInterval,
+ repoChangeScannerGroup);
+ intervalField.getLabelControl(repoChangeScannerGroup).setToolTipText(
+ UIText.RefreshPreferencesPage_RefreshIndexIntervalTooltip);
+ addField(intervalField);
addField(new BooleanFieldEditor(UIPreferences.REFESH_ON_INDEX_CHANGE,
UIText.RefreshPreferencesPage_RefreshWhenIndexChange,
- repoChangeScannerGroup));
+ repoChangeScannerGroup) {
+ @Override
+ public int getNumberOfControls() {
+ return 2;
+ }
+ });
addField(new BooleanFieldEditor(UIPreferences.REFESH_ONLY_WHEN_ACTIVE,
UIText.RefreshPreferencesPage_RefreshOnlyWhenActive,
- repoChangeScannerGroup));
+ repoChangeScannerGroup) {
+ @Override
+ public int getNumberOfControls() {
+ return 2;
+ }
+ });
updateMargins(repoChangeScannerGroup);
Group mergeGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index feee632e2a..47b6330890 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -1019,6 +1019,8 @@ ProjectsPreferencePage_AutoShareProjects=Automatically share projects located in
ProjectsPreferencePage_RestoreBranchProjects=Track each branch's imported projects and restore on checkout
ProjectsPreferencePage_AutoIgnoreDerivedResources=Automatically ignore derived resources by adding them to .gitignore
+RefreshPreferencesPage_RefreshIndexInterval=Refre&sh interval (seconds):
+RefreshPreferencesPage_RefreshIndexIntervalTooltip=0 is equivalent to no refresh
RefreshPreferencesPage_RefreshOnlyWhenActive=Refresh only when workbench is &active
RefreshPreferencesPage_RefreshWhenIndexChange=Refresh resources when &index changes
RefUpdateElement_CommitCountDecoration=({0})

Back to the top