diff options
author | Andrey Loskutov | 2015-01-14 14:11:03 +0000 |
---|---|---|
committer | Matthias Sohn | 2015-01-15 23:18:53 +0000 |
commit | e091484329031a4049f98931b9de57bff046932a (patch) | |
tree | f9703293dec115dd264aab152d09b1d82a696bc4 | |
parent | 82d35fb45d3945a24f39e278dc21e13278e7b527 (diff) | |
download | egit-e091484329031a4049f98931b9de57bff046932a.tar.gz egit-e091484329031a4049f98931b9de57bff046932a.tar.xz egit-e091484329031a4049f98931b9de57bff046932a.zip |
[stagingView] Don't run stage/unstage operations in UI thread
Partial implementation of the bug 457255 which only converts
stage/unstage operations to non-blocking.
Bug: 457255
Change-Id: I3d8570563d14fa69b8f2fc610ad23739b1b16586
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
3 files changed, 124 insertions, 47 deletions
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 2d37db2616..c80b53c0e7 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 @@ -5078,6 +5078,15 @@ public class UIText extends NLS { public static String StagingView_MergeTool; /** */ + public static String StagingView_AddJob; + + /** */ + public static String StagingView_RemoveJob; + + /** */ + public static String StagingView_ResetJob; + + /** */ public static String StagingViewContentProvider_SubmoduleError; /** */ 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 07f8ed102a..805425f20c 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 @@ -30,7 +30,10 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +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; @@ -42,9 +45,11 @@ import org.eclipse.egit.core.RepositoryUtil; import org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry; import org.eclipse.egit.core.internal.indexdiff.IndexDiffChangedListener; import org.eclipse.egit.core.internal.indexdiff.IndexDiffData; +import org.eclipse.egit.core.internal.job.RuleUtil; import org.eclipse.egit.core.op.CommitOperation; import org.eclipse.egit.core.project.RepositoryMapping; import org.eclipse.egit.ui.Activator; +import org.eclipse.egit.ui.JobFamilies; import org.eclipse.egit.ui.UIPreferences; import org.eclipse.egit.ui.UIUtils; import org.eclipse.egit.ui.internal.CommonUtils; @@ -1866,10 +1871,10 @@ public class StagingView extends ViewPart implements IShowInSource { private void stage(IStructuredSelection selection) { StagingViewContentProvider contentProvider = getContentProvider(unstagedViewer); - Git git = new Git(currentRepository); + final Git git = new Git(currentRepository); Iterator iterator = selection.iterator(); - List<String> addPaths = new ArrayList<String>(); - List<String> rmPaths = new ArrayList<String>(); + final List<String> addPaths = new ArrayList<String>(); + final List<String> rmPaths = new ArrayList<String>(); resetPathsToExpand(); while (iterator.hasNext()) { Object element = iterator.next(); @@ -1901,34 +1906,64 @@ public class StagingView extends ViewPart implements IShowInSource { } } - if (!addPaths.isEmpty()) - try { - AddCommand add = git.add(); - for (String addPath : addPaths) - add.addFilepattern(addPath); - add.call(); - } catch (NoFilepatternException e1) { - // cannot happen - } catch (JGitInternalException e1) { - Activator.handleError(e1.getCause().getMessage(), - e1.getCause(), true); - } catch (Exception e1) { - Activator.handleError(e1.getMessage(), e1, true); - } - if (!rmPaths.isEmpty()) - try { - RmCommand rm = git.rm().setCached(true); - for (String rmPath : rmPaths) - rm.addFilepattern(rmPath); - rm.call(); - } catch (NoFilepatternException e) { - // cannot happen - } catch (JGitInternalException e) { - Activator.handleError(e.getCause().getMessage(), e.getCause(), - true); - } catch (Exception e) { - Activator.handleError(e.getMessage(), e, true); - } + // start long running operations + if (!addPaths.isEmpty()) { + Job addJob = new Job(UIText.StagingView_AddJob) { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + AddCommand add = git.add(); + for (String addPath : addPaths) + add.addFilepattern(addPath); + add.call(); + } catch (NoFilepatternException e1) { + // cannot happen + } catch (JGitInternalException e1) { + Activator.handleError(e1.getCause().getMessage(), + e1.getCause(), true); + } catch (Exception e1) { + Activator.handleError(e1.getMessage(), e1, true); + } + return Status.OK_STATUS; + } + + @Override + public boolean belongsTo(Object family) { + return family == JobFamilies.ADD_TO_INDEX; + } + }; + + schedule(addJob, true); + } + + if (!rmPaths.isEmpty()) { + Job removeJob = new Job(UIText.StagingView_RemoveJob) { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + RmCommand rm = git.rm().setCached(true); + for (String rmPath : rmPaths) + rm.addFilepattern(rmPath); + rm.call(); + } catch (NoFilepatternException e) { + // cannot happen + } catch (JGitInternalException e) { + Activator.handleError(e.getCause().getMessage(), + e.getCause(), true); + } catch (Exception e) { + Activator.handleError(e.getMessage(), e, true); + } + return Status.OK_STATUS; + } + + @Override + public boolean belongsTo(Object family) { + return family == JobFamilies.REMOVE_FROM_INDEX; + } + }; + + schedule(removeJob, true); + } } private void selectEntryForStaging(StagingEntry entry, @@ -1957,19 +1992,32 @@ public class StagingView extends ViewPart implements IShowInSource { if (selection.isEmpty()) return; - List<String> paths = processUnstageSelection(selection); + final List<String> paths = processUnstageSelection(selection); if (paths.isEmpty()) return; - try { - Git git = new Git(currentRepository); - ResetCommand reset = git.reset(); - for (String path : paths) - reset.addPath(path); - reset.call(); - } catch (GitAPIException e) { - Activator.handleError(e.getMessage(), e, true); - } + final Git git = new Git(currentRepository); + + Job resetJob = new Job(UIText.StagingView_ResetJob) { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + ResetCommand reset = git.reset(); + for (String path : paths) + reset.addPath(path); + reset.call(); + } catch (GitAPIException e) { + Activator.handleError(e.getMessage(), e, true); + } + return Status.OK_STATUS; + } + + @Override + public boolean belongsTo(Object family) { + return family == JobFamilies.RESET; + } + }; + schedule(resetJob, true); } private List<String> processUnstageSelection(IStructuredSelection selection) { @@ -2452,17 +2500,33 @@ public class StagingView extends ViewPart implements IShowInSource { } }); - IWorkbenchSiteProgressService service = CommonUtils.getService(getSite(), IWorkbenchSiteProgressService.class); - if (service != null) - service.schedule(commitJob, 0, true); - else - commitJob.schedule(); + schedule(commitJob, true); CommitMessageHistory.saveCommitHistory(commitMessage); clearCommitMessageToggles(); commitMessageText.setText(EMPTY_STRING); } + /** + * Schedule given job in context of the current view. The view will indicate + * progress as long as job is running. + * + * @param job + * non null + * @param useRepositoryRule + * true to use current repository rule for the given job, false + * to not enforce any rule on the job + */ + private void schedule(Job job, boolean useRepositoryRule) { + if (useRepositoryRule) + job.setRule(RuleUtil.getRule(currentRepository)); + IWorkbenchSiteProgressService service = CommonUtils.getService(getSite(), IWorkbenchSiteProgressService.class); + if (service != null) + service.schedule(job, 0, true); + else + job.schedule(); + } + private boolean isCommitWithoutFilesAllowed() { if (stagedViewer.getTree().getItemCount() > 0) return true; @@ -2503,7 +2567,7 @@ public class StagingView extends ViewPart implements IShowInSource { return disposed; } - private void syncExec(Runnable runnable) { + private static void syncExec(Runnable runnable) { PlatformUI.getWorkbench().getDisplay().syncExec(runnable); } 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 0fd7be4ff2..a34f27797a 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 @@ -1769,6 +1769,10 @@ StagingView_Tree=Tree StagingView_CompactTree=Compact Tree StagingView_Find=Filter files StagingView_MergeTool=Merge Tool +StagingView_AddJob=Adding files to index... +StagingView_RemoveJob=Removing files from index... +StagingView_ResetJob=Unstaging files... + StagingViewContentProvider_SubmoduleError=Unhandled exception while analyzing submodules StagingViewLabelProvider_SymlinkError=Unhandled exception while checking symlink target StashApplyCommand_applyFailed=Applying stashed commit ''{0}'' failed due to ''{1}'' |