aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-27 15:12:55 (EDT)
committerKevin Sawicki2011-04-27 15:12:55 (EDT)
commit4a28945a38994e519a6c5eb9b8dd3c1a82487dda (patch)
treedc2bf7f5aadcab40b491a9e2af2fb9b1a8194cbf
parent2771482d4f9975442e4f35f83d1eea64cbd7951d (diff)
downloadegit-4a28945a38994e519a6c5eb9b8dd3c1a82487dda.zip
egit-4a28945a38994e519a6c5eb9b8dd3c1a82487dda.tar.gz
egit-4a28945a38994e519a6c5eb9b8dd3c1a82487dda.tar.bz2
Add compare with previous revision menu.refs/changes/67/3267/3
This opens the compare editor for single file selections and the Git Tree compare view for non-file selections. Bug: 344026 Change-Id: Ibb1cadfdc56376a5cf0110b8cc0105d8067cd20d Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.egit.ui/plugin.properties4
-rw-r--r--org.eclipse.egit.ui/plugin.xml13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithPreviousAction.java26
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithPreviousActionHandler.java166
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties3
7 files changed, 223 insertions, 1 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index 936bbf5..77fd6da 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -263,4 +263,6 @@ RenameBranchMenu.label = Rename Branch...
DeleteBranchMenu.label = Delete Branch...
DeleteBranchCommand.name = Delete Branch
RenameBranchCommand.name = Rename Branch
-CompareInTreeCommand.name = Compare in Tree \ No newline at end of file
+CompareInTreeCommand.name = Compare in Tree
+CompareWithPreviousCommand.name = Compare with Previous Revision
+CompareWithPreviousAction.label = Previous Revision \ No newline at end of file
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 07fcff3..01551fe 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -116,6 +116,13 @@
label="%CompareWithBranchOrTagAction.label"
menubarPath="compareWithMenu/gitCompareWithGroup">
</action>
+ <action
+ class="org.eclipse.egit.ui.internal.actions.CompareWithPreviousAction"
+ definitionId="org.eclipse.egit.ui.team.CompareWithPrevious"
+ enablesFor="1"
+ id="org.eclipse.egit.ui.internal.actions.CompareWithPreviousAction"
+ label="%CompareWithPreviousAction.label"
+ menubarPath="compareWithMenu/gitCompareWithGroup"/>
<action
class="org.eclipse.egit.ui.internal.actions.CompareWithHeadAction"
id="org.eclipse.egit.ui.internal.actions.CompareWithHeadAction"
@@ -3130,6 +3137,12 @@
id="org.eclipse.egit.ui.team.CompareWithHead"
name="%CompareWithHeadCommand.name">
</command>
+ <command
+ categoryId="org.eclipse.egit.ui.commandCategory"
+ defaultHandler="org.eclipse.egit.ui.internal.actions.CompareWithPreviousActionHandler"
+ id="org.eclipse.egit.ui.team.CompareWithPrevious"
+ name="%CompareWithPreviousCommand.name">
+ </command>
<command
categoryId="org.eclipse.egit.ui.commandCategory"
id="org.eclipse.egit.ui.team.CompareWithRevision"
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 03cd122..17673ee 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
@@ -1741,6 +1741,15 @@ public class UIText extends NLS {
public static String CompareWithIndexAction_errorOnAddToIndex;
/** */
+ public static String CompareWithPreviousActionHandler_MessageRevisionNotFound;
+
+ /** */
+ public static String CompareWithPreviousActionHandler_TaskGeneratingInput;
+
+ /** */
+ public static String CompareWithPreviousActionHandler_TitleRevisionNotFound;
+
+ /** */
public static String ConfirmationPage_cantConnectToAnyTitle;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java
index e883a9c..6d4b5b5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java
@@ -41,6 +41,9 @@ public class ActionCommands {
/** "Compare with revision" action command id */
public static final String COMPARE_WITH_REVISION_ACTION = "org.eclipse.egit.ui.team.CompareWithRevision"; //$NON-NLS-1$
+ /** "Compare with previous" action command id */
+ public static final String COMPARE_WITH_PREVIOUS_ACTION = "org.eclipse.egit.ui.team.CompareWithPrevious"; //$NON-NLS-1$
+
/** "Configure Fetch" action command id */
public static final String CONFIGURE_FETCH = "org.eclipse.egit.ui.team.ConfigureFetch"; //$NON-NLS-1$
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithPreviousAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithPreviousAction.java
new file mode 100644
index 0000000..7128f8a
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithPreviousAction.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+/**
+ * Compare with previous revision action.
+ */
+public class CompareWithPreviousAction extends RepositoryAction {
+
+ /**
+ * Create compare with previous revision action
+ */
+ public CompareWithPreviousAction() {
+ super(ActionCommands.COMPARE_WITH_PREVIOUS_ACTION,
+ new CompareWithPreviousActionHandler());
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithPreviousActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithPreviousActionHandler.java
new file mode 100644
index 0000000..45267d1
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithPreviousActionHandler.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.compare.CompareUI;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.egit.core.op.IEGitOperation;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.CompareUtils;
+import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
+import org.eclipse.egit.ui.internal.dialogs.CompareTreeView;
+import org.eclipse.egit.ui.internal.job.JobUtil;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.FollowFilter;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Compare with previous revision action handler.
+ */
+public class CompareWithPreviousActionHandler extends RepositoryActionHandler {
+
+ private class CompareWithPreviousOperation implements IEGitOperation {
+
+ private ExecutionEvent event;
+
+ private Repository repository;
+
+ private IResource resource;
+
+ private CompareWithPreviousOperation(ExecutionEvent event,
+ Repository repository, IResource resource) {
+ this.event = event;
+ this.repository = repository;
+ this.resource = resource;
+ }
+
+ private String getRepositoryPath() {
+ return RepositoryMapping.getMapping(resource.getProject())
+ .getRepoRelativePath(resource);
+ }
+
+ public void execute(IProgressMonitor monitor) throws CoreException {
+ RevCommit previous = findPreviousCommit();
+ if (previous != null)
+ if (resource instanceof IFile) {
+ final ITypedElement base = SaveableCompareEditorInput
+ .createFileElement((IFile) resource);
+ ITypedElement next = CompareUtils
+ .getFileRevisionTypedElement(getRepositoryPath(),
+ previous, repository);
+ CompareEditorInput input = new GitCompareFileRevisionEditorInput(
+ base, next, null);
+ CompareUI.openCompareEditor(input);
+ } else
+ openCompareTreeView(previous);
+ else
+ showNotFoundDialog();
+ }
+
+ private void openCompareTreeView(final RevCommit previous) {
+ final Shell shell = HandlerUtil.getActiveShell(event);
+ shell.getDisplay().asyncExec(new Runnable() {
+
+ public void run() {
+ try {
+ CompareTreeView view = (CompareTreeView) PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().showView(CompareTreeView.ID);
+ view.setInput(new IResource[] { resource },
+ previous.name());
+ } catch (PartInitException e) {
+ Activator.handleError(e.getMessage(), e, true);
+ }
+ }
+ });
+ }
+
+ private RevCommit findPreviousCommit() {
+ RevWalk rw = new RevWalk(repository);
+ try {
+ String path = getRepositoryPath();
+ if (path.length() > 0)
+ rw.setTreeFilter(FollowFilter.create(path));
+ RevCommit headCommit = rw.parseCommit(repository.getRef(
+ Constants.HEAD).getObjectId());
+ rw.markStart(headCommit);
+ headCommit = rw.next();
+ if (headCommit != null)
+ return rw.next();
+ } catch (IOException e) {
+ Activator.handleError(e.getMessage(), e, true);
+ } finally {
+ rw.dispose();
+ }
+ return null;
+ }
+
+ private void showNotFoundDialog() {
+ final Shell shell = HandlerUtil.getActiveShell(event);
+ final String message = MessageFormat
+ .format(UIText.CompareWithPreviousActionHandler_MessageRevisionNotFound,
+ resource.getName());
+ shell.getDisplay().asyncExec(new Runnable() {
+
+ public void run() {
+ MessageDialog
+ .openWarning(
+ shell,
+ UIText.CompareWithPreviousActionHandler_TitleRevisionNotFound,
+ message);
+ }
+ });
+ }
+
+ public ISchedulingRule getSchedulingRule() {
+ return resource;
+ }
+ }
+
+ /**
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Repository repository = getRepository(true, event);
+ if (repository == null)
+ return null;
+
+ IResource[] resources = getSelectedResources(event);
+ if (resources.length == 1)
+ JobUtil.scheduleUserJob(
+ new CompareWithPreviousOperation(event, repository,
+ resources[0]),
+ UIText.CompareWithPreviousActionHandler_TaskGeneratingInput,
+ null);
+ return null;
+ }
+}
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 453ca1c..86ecfe9 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
@@ -567,6 +567,9 @@ CommitMessageViewer_GettingPreviousTagTaskName=Getting previous tag
CommitMessageViewer_parent=Parent
CommitMessageViewer_SelectOneCommitMessage=Please select exactly one commit
CompareWithIndexAction_errorOnAddToIndex=Error during adding to index
+CompareWithPreviousActionHandler_MessageRevisionNotFound=No previous revision of {0} could be found in the repository.
+CompareWithPreviousActionHandler_TaskGeneratingInput=Generating comparison with previous revision
+CompareWithPreviousActionHandler_TitleRevisionNotFound=Previous revision not found
ConfirmationPage_cantConnectToAnyTitle=Can't Connect
ConfirmationPage_cantConnectToAny=Can't connect to any URI: {0}