diff options
author | Thomas Wolf | 2019-06-19 14:29:12 +0000 |
---|---|---|
committer | Thomas Wolf | 2019-06-19 15:20:54 +0000 |
commit | ef65cda9018418ecc428dae8d4c4798d7148d770 (patch) | |
tree | 6509f7822ebd8926457b55cd5b49d085e2211137 | |
parent | 47fbfcbbd68c4e6c15b49a6b377b240a6a07d726 (diff) | |
download | egit-ef65cda9018418ecc428dae8d4c4798d7148d770.tar.gz egit-ef65cda9018418ecc428dae8d4c4798d7148d770.tar.xz egit-ef65cda9018418ecc428dae8d4c4798d7148d770.zip |
BranchOperation: fix progress monitor handling
Usage of progress monitors was rather strange. Use the well-
established pattern for using SubMonitors that re-distributes
work locally within one method properly. It's much easier to
allocate ticks correctly that way.
Change-Id: I92ef88067cb6996353a05ab4ac26551c245f4b59
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r-- | org.eclipse.egit.core/src/org/eclipse/egit/core/op/BranchOperation.java | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/BranchOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/BranchOperation.java index 5f65aae1e6..da20c9f48c 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/BranchOperation.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/BranchOperation.java @@ -120,22 +120,32 @@ public class BranchOperation implements IEGitOperation { @Override public void run(IProgressMonitor pm) throws CoreException { - int numberOfRepositories = repositories.length; - SubMonitor progress = SubMonitor.convert(pm, 4); - for (Repository repository : repositories) { - CheckoutResult result = checkoutRepository(repository, - progress, numberOfRepositories > 1); - if (result.getStatus() == Status.NONDELETED) { - retryDelete(repository, result.getUndeletedList()); + try { + pm.setTaskName(MessageFormat.format( + CoreText.BranchOperation_performingBranch, target)); + int numberOfRepositories = repositories.length; + SubMonitor progress = SubMonitor.convert(pm, + numberOfRepositories * 2); + for (Repository repository : repositories) { + CheckoutResult result = checkoutRepository(repository, + progress.newChild(1), numberOfRepositories > 1); + if (result.getStatus() == Status.NONDELETED) { + retryDelete(repository, result.getUndeletedList()); + } + results.put(repository, result); } - results.put(repository, result); + refreshAffectedProjects( + progress.newChild(numberOfRepositories)); + } finally { + pm.done(); } - refreshAffectedProjects(progress); } public CheckoutResult checkoutRepository(Repository repo, - SubMonitor progress, boolean logErrors) throws CoreException { - closeProjectsMissingAfterCheckout(repo, progress); + IProgressMonitor monitor, boolean logErrors) + throws CoreException { + SubMonitor progress = SubMonitor.convert(monitor, 2); + closeProjectsMissingAfterCheckout(repo, progress.newChild(1)); try (Git git = new Git(repo)) { CheckoutCommand co = git.checkout().setProgressMonitor( new EclipseGitProgressTransformer( @@ -160,15 +170,12 @@ public class BranchOperation implements IEGitOperation { } private void closeProjectsMissingAfterCheckout(Repository repo, - SubMonitor progress) throws CoreException { + IProgressMonitor monitor) throws CoreException { IProject[] missing = getMissingProjects(repo, target); - progress.setTaskName(MessageFormat.format( - CoreText.BranchOperation_performingBranch, target)); - progress.setWorkRemaining(missing.length > 0 ? 4 : 3); - if (missing.length > 0) { - SubMonitor closeMonitor = progress.newChild(1); + SubMonitor closeMonitor = SubMonitor.convert(monitor, + missing.length); closeMonitor.setWorkRemaining(missing.length); for (IProject project : missing) { closeMonitor.subTask(MessageFormat.format( @@ -179,15 +186,14 @@ public class BranchOperation implements IEGitOperation { } } - private void refreshAffectedProjects(SubMonitor progress) + private void refreshAffectedProjects(IProgressMonitor monitor) throws CoreException { IProject[] refreshProjects = results.entrySet().stream() .map(this::getAffectedProjects) .flatMap(arr -> Stream.of(arr)).distinct() .toArray(IProject[]::new); - ProjectUtil.refreshValidProjects(refreshProjects, delete, - progress.newChild(1)); + monitor); } private IProject[] getAffectedProjects( |