summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorBernard Leach2011-05-25 23:14:42 (EDT)
committer Chris Aniszczyk2011-06-01 09:46:20 (EDT)
commit9ca67d3bc62e1e85ec059a0c87046b96239fcac5 (patch)
tree253c738a5f58252b4d280221400c0fe5596c3e13
parent0d431cd13fd8699cae5ace94be148a960d0f98af (diff)
downloadegit-9ca67d3bc62e1e85ec059a0c87046b96239fcac5.zip
egit-9ca67d3bc62e1e85ec059a0c87046b96239fcac5.tar.gz
egit-9ca67d3bc62e1e85ec059a0c87046b96239fcac5.tar.bz2
Move StagingView reload to asynchronous jobrefs/changes/11/3611/2
Bug: 346445 Change-Id: I44bf628f916bbf3f9f7d391156a3ee685782fdf0 Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java84
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties1
4 files changed, 87 insertions, 4 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index 932c83f..cfd84d4 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -3779,6 +3779,9 @@ public class UIText extends NLS {
public static String StagingView_OpenNewCommits;
/** */
+ public static String StagingView_IndexDiffReload;
+
+ /** */
public static String SynchronizeWithMenu_custom;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
index ca3c3ec..c3d3e9e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
@@ -15,6 +15,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ParameterizedCommand;
@@ -22,8 +23,16 @@ import org.eclipse.core.commands.common.CommandException;
import org.eclipse.core.expressions.EvaluationContext;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.egit.core.EclipseGitProgressTransformer;
import org.eclipse.egit.core.IteratorService;
import org.eclipse.egit.core.op.CommitOperation;
import org.eclipse.egit.core.project.RepositoryMapping;
@@ -101,6 +110,7 @@ import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.forms.IFormColors;
@@ -110,6 +120,7 @@ import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
/**
* A GitX style staging view with embedded commit dialog.
@@ -689,17 +700,82 @@ public class StagingView extends ViewPart {
return false;
}
- // TODO move to a Job?
- private IndexDiff reload(final Repository repository) {
- final boolean repositoryChanged = repository != currentRepository;
+ private void reload(final Repository repository) {
+ final boolean repositoryChanged = currentRepository == repository;
+
+ final AtomicReference<IndexDiff> results = new AtomicReference<IndexDiff>();
+
+ final String jobTitle = MessageFormat.format(UIText.StagingView_IndexDiffReload,
+ StagingView.getRepositoryName(repository));
+
+ Job job = new Job(jobTitle) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ IndexDiff indexDiff = doReload(repository, monitor, jobTitle);
+ results.set(indexDiff);
+ return Status.OK_STATUS;
+ }
+ };
+
+ job.setUser(true);
+ job.setRule(ResourcesPlugin.getWorkspace().getRoot());
+
+ job.addJobChangeListener(new JobChangeAdapter() {
+ public void done(final IJobChangeEvent event) {
+ form.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (form.isDisposed())
+ return;
+
+ final IndexDiff indexDiff = results.get();
+ unstagedTableViewer.setInput(new Object[] { repository,
+ indexDiff });
+ stagedTableViewer
+ .setInput(new Object[] { repository, indexDiff });
+ commitAction.setEnabled(repository.getRepositoryState()
+ .canCommit());
+ form.setText(StagingView.getRepositoryName(repository));
+ if (repositoryChanged) {
+ updateCommitMessageComponent(repositoryChanged);
+ clearCommitMessageToggles();
+ }
+ updateSectionText();
+ }
+
+ });
+ }
+ });
+
+ schedule(job);
+ }
+
+ private void schedule(final Job j) {
+ IWorkbenchPartSite site = getSite();
+ if (site != null) {
+ final IWorkbenchSiteProgressService p;
+ p = (IWorkbenchSiteProgressService) site
+ .getAdapter(IWorkbenchSiteProgressService.class);
+ if (p != null) {
+ p.schedule(j, 0, true /* use half-busy cursor */);
+ return;
+ }
+ }
+ j.schedule();
+ }
+
+ private IndexDiff doReload(final Repository repository, IProgressMonitor monitor, String jobTitle) {
currentRepository = repository;
+ final boolean repositoryChanged = currentRepository == repository;
+
+ EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(
+ monitor);
final IndexDiff indexDiff;
try {
WorkingTreeIterator iterator = IteratorService
.createInitialIterator(repository);
indexDiff = new IndexDiff(repository, Constants.HEAD, iterator);
- indexDiff.diff();
+ indexDiff.diff(jgitMonitor, 0, 0, jobTitle);
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java
index 192934f..9d73116 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java
@@ -40,6 +40,9 @@ public class StagingViewContentProvider implements
Repository repository = (Repository)((Object[])newInput)[0];
IndexDiff indexDiff = (IndexDiff)((Object[])newInput)[1];
+ if (repository == null || indexDiff == null)
+ return;
+
Set<StagingEntry> nodes = new TreeSet<StagingEntry>(new Comparator<StagingEntry>() {
public int compare(StagingEntry o1, StagingEntry o2) {
return o1.getPath().compareTo(o2.getPath());
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
index 329098d..fdb5b51 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
@@ -1312,6 +1312,7 @@ StagingView_headCommitChanged=\# WARNING: head commit changed in the meantime
StagingView_noStagedFiles=There are no staged files
StagingView_NoSelectionTitle=No repository selected
StagingView_OpenNewCommits=Open new commits
+StagingView_IndexDiffReload=Staging view reindexing repository {0}
SynchronizeWithMenu_custom=&Custom...
SynchronizeFetchJob_JobName=Fetching changes before synchronization launch