{"thread":{"id":"17725","subject":"[PATCH JGIT] Add \"compare with index\" action.","startedAt":"2009-02-11T15:44:17Z","lastAt":"2009-02-11T15:44:17Z","messageCount":1,"participants":["Yann Simon"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"104199","messageId":"4992F251.9090901@gmail.com","threadId":"17725","inReplyTo":null,"subject":"[PATCH JGIT] Add \"compare with index\" action.","fromName":"Yann Simon","fromEmail":"yann.simon.fr@gmail.com","sentAt":"2009-02-11T15:44:17Z","receivedAt":"2009-02-11T15:44:17Z","isPatch":true,"sender":{"key":"yann.simon.fr@gmail.com","avatar":"https://gravatar.com/avatar/2d926895d27ac988c5c8e591887e5a6a4c7036390403c74fce92519119b887a0?d=mp&s=160"},"body":"In the Compare With... menu, the \"compare with index\" action opens\na diff editor that compares the workspace version of a file and its\nindex version.\n\nSigned-off-by: Yann Simon <yann.simon.fr@gmail.com>\n---\nMy plan with the compare editor is to allow to add some contents into\nthe index (partial commits).\nI do not know yet how to achieve this.\n\nI did not find how to commit only the index with the eclipse interface.\nSo I guess comparing with index does not bring a lot of value for the\nmoment.\n\n-- yann\n\n .../core/internal/storage/GitFileRevision.java     |   24 ++++++\n org.spearce.egit.ui/plugin.properties              |    3 +\n org.spearce.egit.ui/plugin.xml                     |    7 ++\n .../internal/actions/CompareWithIndexAction.java   |   87\n++++++++++++++++++++\n 4 files changed, 121 insertions(+), 0 deletions(-)\n create mode 100644\norg.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CompareWithIndexAction.java\n\ndiff --git\na/org.spearce.egit.core/src/org/spearce/egit/core/internal/storage/GitFileRevision.java\nb/org.spearce.egit.core/src/org/spearce/egit/core/internal/storage/GitFileRevision.java\nindex 21ba19e..3c78dfc 100644\n---\na/org.spearce.egit.core/src/org/spearce/egit/core/internal/storage/GitFileRevision.java\n+++\nb/org.spearce.egit.core/src/org/spearce/egit/core/internal/storage/GitFileRevision.java\n@@ -11,6 +11,7 @@\n import java.net.URI;\n import java.net.URISyntaxException;\n \n+import org.eclipse.core.resources.IResource;\n import org.eclipse.core.runtime.CoreException;\n import org.eclipse.core.runtime.IProgressMonitor;\n import org.eclipse.team.core.history.IFileRevision;\n@@ -49,6 +50,29 @@ public static GitFileRevision inCommit(final\nRepository db,\n         return new CommitFileRevision(db, commit, path, blobId);\n     }\n \n+    /**\n+     * Obtain a file revision for a file in the working repository.\n+     *\n+     * @param resource\n+     *            resource identifying the file in the working repository.\n+     * @return revision implementation for the resource in the working\n+     *         repository.\n+     */\n+    public static GitFileRevision inWorkspace(final IResource resource) {\n+        return new WorkspaceFileRevision(resource);\n+    }\n+\n+    /**\n+     * @param db\n+     *            the repository which contains the index to use.\n+     * @param path\n+     *            path of the resource in the index\n+     * @return revision implementation for the given path in the index\n+     */\n+    public static GitFileRevision inIndex(final Repository db, final\nString path) {\n+        return new IndexFileRevision(db, path);\n+    }\n+\n     private final String path;\n \n     GitFileRevision(final String fileName) {\ndiff --git a/org.spearce.egit.ui/plugin.properties\nb/org.spearce.egit.ui/plugin.properties\nindex fa043f1..0fc869b 100644\n--- a/org.spearce.egit.ui/plugin.properties\n+++ b/org.spearce.egit.ui/plugin.properties\n@@ -31,6 +31,9 @@ Decorator_description=Shows Git specific information\non resources in projects un\n CompareWithRevisionAction_label=Compare With Git Revision\n CompareWithRevisionAction_tooltip=Compare With a Git Revision\n \n+CompareWithIndexAction_label=Compare with index version\n+CompareWithIndexAction_tooltip=Compare with index version\n+\n ShowResourceInHistoryAction_label=Show in Resource History\n ShowResourceInHistoryAction_tooltip=Show selected files in the resource\nhistory view.\n \ndiff --git a/org.spearce.egit.ui/plugin.xml b/org.spearce.egit.ui/plugin.xml\nindex 869108c..c706309 100644\n--- a/org.spearce.egit.ui/plugin.xml\n+++ b/org.spearce.egit.ui/plugin.xml\n@@ -108,6 +108,13 @@\n                label=\"%CommitAction_label\"\n                menubarPath=\"team.main/group1\"\n                tooltip=\"%CommitAction_tooltip\"/>\n+         <action\n+              \nclass=\"org.spearce.egit.ui.internal.actions.CompareWithIndexAction\"\n+              \nid=\"org.spearce.egit.ui.internal.actions.CompareWithIndexAction\"\n+               label=\"%CompareWithIndexAction_label\"\n+               menubarPath=\"compareWithMenu/gitCompareWithGroup\"\n+               tooltip=\"&amp;CompareWithIndexAction_tooltip\">\n+         </action>\n       </objectContribution>\n       <objectContribution\n          id=\"org.spearce.egit.ui.resetto\"\ndiff --git\na/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CompareWithIndexAction.java\nb/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CompareWithIndexAction.java\nnew file mode 100644\nindex 0000000..a4af944\n--- /dev/null\n+++\nb/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CompareWithIndexAction.java\n@@ -0,0 +1,87 @@\n+/*\n+ * Copyright (C) 2009, Yann Simon <yann.simon.fr@gmail.com>\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.egit.ui.internal.actions;\n+\n+import org.eclipse.compare.CompareUI;\n+import org.eclipse.compare.ITypedElement;\n+import org.eclipse.core.resources.IResource;\n+import org.eclipse.jface.action.IAction;\n+import org.eclipse.team.core.history.IFileRevision;\n+import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;\n+import org.spearce.egit.core.internal.storage.GitFileRevision;\n+import org.spearce.egit.core.project.RepositoryMapping;\n+import org.spearce.egit.ui.internal.GitCompareFileRevisionEditorInput;\n+import org.spearce.jgit.lib.Repository;\n+\n+/**\n+ * The \"compare with index\" action. This action opens a diff editor\ncomparing\n+ * the file as found in the working directory and the version found in\nthe index\n+ * of the repository.\n+ */\n+@SuppressWarnings(\"restriction\")\n+public class CompareWithIndexAction extends RepositoryAction {\n+\n+    @Override\n+    public void execute(IAction action) {\n+        final IResource resource = getSelectedResources()[0];\n+        final RepositoryMapping mapping =\nRepositoryMapping.getMapping(resource.getProject());\n+        final Repository repository = mapping.getRepository();\n+        final String gitPath = mapping.getRepoRelativePath(resource);\n+\n+        final IFileRevision baseFile =\nGitFileRevision.inWorkspace(resource);\n+        final IFileRevision nextFile =\nGitFileRevision.inIndex(repository, gitPath);\n+\n+        final ITypedElement base = new FileRevisionTypedElement(baseFile);\n+        final ITypedElement next = new FileRevisionTypedElement(nextFile);\n+\n+        final GitCompareFileRevisionEditorInput in = new\nGitCompareFileRevisionEditorInput(\n+                base, next, null);\n+        CompareUI.openCompareEditor(in);\n+    }\n+\n+    @Override\n+    public boolean isEnabled() {\n+        final IResource[] selectedResources = getSelectedResources();\n+        if (selectedResources.length != 1)\n+            return false;\n+        final IResource resource = selectedResources[0];\n+        final RepositoryMapping mapping =\nRepositoryMapping.getMapping(resource.getProject());\n+        return mapping != null;\n+    }\n+\n+}\n\\ No newline at end of file\n-- \n1.6.0.4\n"}]}