From a0270b1245dd66c3c242e94043b68759070bee5d Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Thu, 3 Aug 2017 00:19:59 +0200 Subject: [PATCH] Clean-up: resolve duplicate code in RebaseInteractiveCurrentHandler A Hudson build for https://git.eclipse.org/r/102415 reported a fixed duplicate code finding. On closer inspection, that report was bogus: the analysis considered the duplication fixed because a change made in one class resulted in two smaller duplicate blocks below the reporting threshold. In reality, the same change should have been made in the other class, too... instead resolve the code duplication properly. Change-Id: Ia39ca913bb0e8f5eef3506051537f62571b33056 Signed-off-by: Thomas Wolf --- .../AbstractRebaseHistoryCommandHandler.java | 2 +- .../command/RebaseInteractiveCurrentHandler.java | 43 +++++----------------- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractRebaseHistoryCommandHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractRebaseHistoryCommandHandler.java index c4924dd63..d8dce1189 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractRebaseHistoryCommandHandler.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractRebaseHistoryCommandHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 SAP AG. + * Copyright (c) 2010, 2017 SAP AG and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RebaseInteractiveCurrentHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RebaseInteractiveCurrentHandler.java index a20d85130..2d16b227a 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RebaseInteractiveCurrentHandler.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RebaseInteractiveCurrentHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 SAP AG. + * Copyright (c) 2013, 2017 SAP AG and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,15 +12,11 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.egit.core.op.RebaseOperation; import org.eclipse.egit.ui.Activator; -import org.eclipse.egit.ui.internal.UIText; -import org.eclipse.egit.ui.internal.commands.shared.AbstractRebaseCommandHandler; +import org.eclipse.egit.ui.internal.branch.LaunchFinder; import org.eclipse.egit.ui.internal.rebase.RebaseInteractiveHandler; import org.eclipse.egit.ui.internal.rebase.RebaseInteractiveView; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.RepositoryState; -import org.eclipse.jgit.revplot.PlotCommit; -import org.eclipse.osgi.util.NLS; import org.eclipse.ui.PartInitException; import org.eclipse.ui.handlers.HandlerUtil; @@ -31,37 +27,16 @@ import org.eclipse.ui.handlers.HandlerUtil; public class RebaseInteractiveCurrentHandler extends AbstractRebaseHistoryCommandHandler { @Override - public boolean isEnabled() { - final Repository repository = getRepository(getPage()); - if (repository == null) - return false; - return repository.getRepositoryState().equals(RepositoryState.SAFE); - } - - @Override public Object execute(ExecutionEvent event) throws ExecutionException { - - PlotCommit commit = (PlotCommit) getSelection(event).getFirstElement(); final Repository repository = getRepository(event); - if (repository == null) + if (repository == null) { return null; - - String currentBranch = getCurrentBranch(repository); - final Ref ref = getRef(commit, repository, currentBranch); - - String jobname = NLS.bind( - UIText.RebaseCurrentRefCommand_RebasingCurrentJobName, - currentBranch, ref.getName()); - AbstractRebaseCommandHandler rebaseCurrentRef = new AbstractRebaseCommandHandler( - jobname, UIText.RebaseCurrentRefCommand_RebaseCanceledMessage) { - @Override - protected RebaseOperation createRebaseOperation( - Repository repository2) throws ExecutionException { - return new RebaseOperation(repository2, ref, - RebaseInteractiveHandler.INSTANCE); - } - }; - rebaseCurrentRef.execute(repository); + } + if (LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, + null)) { + return null; + } + super.execute(event); try { RebaseInteractiveView rebaseInteractiveView = (RebaseInteractiveView) HandlerUtil .getActiveWorkbenchWindowChecked(event).getActivePage() -- 2.11.4.GIT