Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2011-12-06 23:03:55 +0000
committerMatthias Sohn2011-12-09 00:41:38 +0000
commita0a5a859344531e9d0d890b0603f19131bd07e48 (patch)
treeadd52af8542f7b16f99d6cdfa3c8dcd519f315c0
parent9a4d4680eaa0972429f63ba898100460303364db (diff)
downloadegit-a0a5a859344531e9d0d890b0603f19131bd07e48.tar.gz
egit-a0a5a859344531e9d0d890b0603f19131bd07e48.tar.xz
egit-a0a5a859344531e9d0d890b0603f19131bd07e48.zip
[reflogView] Extract getSelectedCommit()
This allows to reuse this method in other command handlers used in the Reflog View. Change-Id: Ic0ef23d555ac75a78b0191b0258bc863d541bf97 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/AbstractReflogCommandHandler.java31
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/CheckoutHandler.java18
2 files changed, 32 insertions, 17 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/AbstractReflogCommandHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/AbstractReflogCommandHandler.java
index ed44024ebd..2c21b9b5ac 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/AbstractReflogCommandHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/AbstractReflogCommandHandler.java
@@ -8,12 +8,18 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.reflog.command;
+import java.io.IOException;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.reflog.ReflogView;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.storage.file.ReflogEntry;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
@@ -49,4 +55,29 @@ abstract class AbstractReflogCommandHandler extends AbstractHandler {
return null;
return (ReflogView) part;
}
+
+ /**
+ * @param event
+ * @param repo
+ * @return commit selected in Reflog View
+ * @throws ExecutionException
+ */
+ protected RevCommit getSelectedCommit(ExecutionEvent event, Repository repo)
+ throws ExecutionException {
+ ReflogEntry entry = (ReflogEntry) ((IStructuredSelection) HandlerUtil
+ .getCurrentSelectionChecked(event)).getFirstElement();
+ if (entry == null)
+ return null;
+
+ RevCommit commit = null;
+ RevWalk w = new RevWalk(repo);
+ try {
+ commit = w.parseCommit(entry.getNewId());
+ } catch (IOException e) {
+ throw new ExecutionException(e.getMessage(), e);
+ } finally {
+ w.release();
+ }
+ return commit;
+ }
} \ No newline at end of file
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/CheckoutHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/CheckoutHandler.java
index c85bdc01d1..be122f8c8e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/CheckoutHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/command/CheckoutHandler.java
@@ -8,17 +8,12 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.reflog.command;
-import java.io.IOException;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.egit.ui.internal.branch.BranchOperationUI;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
-import org.eclipse.jgit.storage.file.ReflogEntry;
-import org.eclipse.ui.handlers.HandlerUtil;
/**
* Checkout handler
@@ -26,19 +21,8 @@ import org.eclipse.ui.handlers.HandlerUtil;
public class CheckoutHandler extends AbstractReflogCommandHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
- ReflogEntry entry = (ReflogEntry) ((IStructuredSelection) HandlerUtil
- .getCurrentSelectionChecked(event)).getFirstElement();
- if (entry == null)
- return null;
-
Repository repo = getRepository(event);
- RevCommit commit = null;
- try {
- RevWalk w = new RevWalk(repo);
- commit = w.parseCommit(entry.getNewId());
- } catch (IOException e) {
- throw new ExecutionException(e.getMessage(), e);
- }
+ RevCommit commit = getSelectedCommit(event, repo);
if (commit != null) {
final BranchOperationUI op = BranchOperationUI.checkout(repo,
commit.name());

Back to the top