{"thread":{"id":"17901","subject":"[PATCH JGIT] Add \"compare with index\" action.","startedAt":"2009-02-19T15:54:10Z","lastAt":"2009-02-20T08:12:34Z","messageCount":2,"participants":["Yann Simon"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"105475","messageId":"499D80A2.7030205@gmail.com","threadId":"17901","inReplyTo":null,"subject":"[PATCH JGIT] Add \"compare with index\" action.","fromName":"Yann Simon","fromEmail":"yann.simon.fr@gmail.com","sentAt":"2009-02-19T15:54:10Z","receivedAt":"2009-02-19T15:54:10Z","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\nThe local file can be modified and saved.\n\nThe staged version can be modified and saved. This updates the index.\nFor this, add methods into GitIndex to allow to specify a content\ndifferent from the file.\n\nSigned-off-by: Yann Simon <yann.simon.fr@gmail.com>\n---\nThis patch is working bug I am sure it could be better.\nI am sending it for review, so any comments are welcome!\n\n-- yann\n\n .../core/internal/storage/GitFileRevision.java     |   11 ++\n org.spearce.egit.ui/plugin.properties              |    3 +\n org.spearce.egit.ui/plugin.xml                     |    7 +\n .../spearce/egit/ui/internal/EditableRevision.java |  157\n++++++++++++++++++++\n .../GitCompareFileRevisionEditorInput.java         |   36 +++--\n .../internal/actions/CompareWithIndexAction.java   |  119 +++++++++++++++\n .../src/org/spearce/jgit/lib/GitIndex.java         |   65 ++++++++\n 7 files changed, 384 insertions(+), 14 deletions(-)\n create mode 100644\norg.spearce.egit.ui/src/org/spearce/egit/ui/internal/EditableRevision.java\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..2f23c7d 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@@ -49,6 +49,17 @@ public static GitFileRevision inCommit(final\nRepository db,\n         return new CommitFileRevision(db, commit, path, blobId);\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 58b879f..cb3a5be 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 2f23559..678fd73 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/EditableRevision.java\nb/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/EditableRevision.java\nnew file mode 100644\nindex 0000000..ee064ef\n--- /dev/null\n+++\nb/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/EditableRevision.java\n@@ -0,0 +1,157 @@\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;\n+\n+import java.io.ByteArrayInputStream;\n+import java.io.InputStream;\n+\n+import org.eclipse.compare.IContentChangeListener;\n+import org.eclipse.compare.IContentChangeNotifier;\n+import org.eclipse.compare.IEditableContent;\n+import org.eclipse.compare.ISharedDocumentAdapter;\n+import org.eclipse.compare.ITypedElement;\n+import org.eclipse.compare.internal.ContentChangeNotifier;\n+import org.eclipse.core.runtime.CoreException;\n+import org.eclipse.core.runtime.Platform;\n+import org.eclipse.team.core.history.IFileRevision;\n+import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;\n+import\norg.eclipse.team.internal.ui.synchronize.EditableSharedDocumentAdapter;\n+\n+/**\n+ * @author simon\n+ *\n+ */\n+public class EditableRevision extends FileRevisionTypedElement implements\n+        ITypedElement, IEditableContent, IContentChangeNotifier {\n+\n+    private byte[] modifiedContent;\n+\n+    private ContentChangeNotifier fChangeNotifier;\n+\n+    private EditableSharedDocumentAdapter sharedDocumentAdapter;\n+\n+    /**\n+     * @param fileRevision\n+     */\n+    public EditableRevision(IFileRevision fileRevision) {\n+        super(fileRevision);\n+    }\n+\n+    public boolean isEditable() {\n+        return true;\n+    }\n+\n+    public ITypedElement replace(ITypedElement dest, ITypedElement src) {\n+        return null;\n+    }\n+\n+    @Override\n+    public InputStream getContents() throws CoreException {\n+        if (modifiedContent != null) {\n+            return new ByteArrayInputStream(modifiedContent);\n+        }\n+        return super.getContents();\n+    }\n+\n+    public void setContent(byte[] newContent) {\n+        modifiedContent = newContent;\n+        fireContentChanged();\n+    }\n+\n+    /**\n+     * @return the modified content\n+     */\n+    public byte[] getModifiedContent() {\n+        return modifiedContent;\n+    }\n+\n+    public Object getAdapter(Class adapter) {\n+        if (adapter == ISharedDocumentAdapter.class) {\n+            return getSharedDocumentAdapter();\n+        }\n+        return Platform.getAdapterManager().getAdapter(this, adapter);\n+    }\n+\n+    private synchronized ISharedDocumentAdapter\ngetSharedDocumentAdapter() {\n+        if (sharedDocumentAdapter == null)\n+            sharedDocumentAdapter = new EditableSharedDocumentAdapter(\n+                    new\nEditableSharedDocumentAdapter.ISharedDocumentAdapterListener() {\n+                        public void handleDocumentConnected() {\n+                        }\n+\n+                        public void handleDocumentFlushed() {\n+                        }\n+\n+                        public void handleDocumentDeleted() {\n+                        }\n+\n+                        public void handleDocumentSaved() {\n+                        }\n+\n+                        public void handleDocumentDisconnected() {\n+                        }\n+                    });\n+        return sharedDocumentAdapter;\n+    }\n+\n+    public void addContentChangeListener(IContentChangeListener listener) {\n+        if (fChangeNotifier == null)\n+            fChangeNotifier = new ContentChangeNotifier(this);\n+        fChangeNotifier.addContentChangeListener(listener);\n+    }\n+\n+    public void removeContentChangeListener(IContentChangeListener\nlistener) {\n+        if (fChangeNotifier != null) {\n+            fChangeNotifier.removeContentChangeListener(listener);\n+            if (fChangeNotifier.isEmpty())\n+                fChangeNotifier = null;\n+        }\n+    }\n+\n+    /**\n+     * Notifies all registered <code>IContentChangeListener</code>s of\na content\n+     * change.\n+     */\n+    protected void fireContentChanged() {\n+        if (fChangeNotifier == null || fChangeNotifier.isEmpty()) {\n+            return;\n+        }\n+        fChangeNotifier.fireContentChanged();\n+    }\n+\n+}\ndiff --git\na/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/GitCompareFileRevisionEditorInput.java\nb/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/GitCompareFileRevisionEditorInput.java\nindex 8aa076f..49d4a42 100644\n---\na/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/GitCompareFileRevisionEditorInput.java\n+++\nb/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/GitCompareFileRevisionEditorInput.java\n@@ -11,7 +11,6 @@\n import java.lang.reflect.InvocationTargetException;\n \n import org.eclipse.compare.CompareConfiguration;\n-import org.eclipse.compare.CompareEditorInput;\n import org.eclipse.compare.IEditableContent;\n import org.eclipse.compare.IResourceProvider;\n import org.eclipse.compare.ITypedElement;\n@@ -34,13 +33,14 @@\n import org.eclipse.team.internal.ui.Utils;\n import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;\n import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;\n+import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;\n import org.eclipse.ui.IWorkbenchPage;\n \n /**\n  * The input provider for the compare editor when working on resources\n  * under Git control.\n  */\n-public class GitCompareFileRevisionEditorInput extends CompareEditorInput {\n+public class GitCompareFileRevisionEditorInput extends\nSaveableCompareEditorInput {\n \n     private ITypedElement left;\n     private ITypedElement right;\n@@ -52,7 +52,7 @@\n      * @param page\n      */\n     public GitCompareFileRevisionEditorInput(ITypedElement left,\nITypedElement right, IWorkbenchPage page) {\n-        super(new CompareConfiguration());\n+        super(new CompareConfiguration(), page);\n         this.left = left;\n         this.right = right;\n     }\n@@ -90,9 +90,18 @@ private static void\nensureContentsCached(FileRevisionTypedElement left, FileRevi\n     }\n \n     private boolean isLeftEditable(ICompareInput input) {\n-        Object left = input.getLeft();\n-        if (left instanceof IEditableContent) {\n-            return ((IEditableContent) left).isEditable();\n+        Object tmpLeft = input.getLeft();\n+        return isEditable(tmpLeft);\n+    }\n+\n+    private boolean isRightEditable(ICompareInput input) {\n+        Object tmpRight = input.getRight();\n+        return isEditable(tmpRight);\n+    }\n+\n+    private boolean isEditable(Object object) {\n+        if (object instanceof IEditableContent) {\n+            return ((IEditableContent) object).isEditable();\n         }\n         return false;\n     }\n@@ -326,12 +335,9 @@ private String getContentIdentifier(ITypedElement\nelement){\n         return TeamUIMessages.CompareFileRevisionEditorInput_2;\n     }\n \n-//    /* (non-Javadoc)\n-//     * @see\norg.eclipse.team.ui.synchronize.LocalResourceCompareEditorInput#fireInputChange()\n-//     */\n-//    protected void fireInputChange() {\n-//        ((DiffNode)getCompareResult()).fireChange();\n-//    }\n+    @Override\n+    protected void fireInputChange() {\n+    }\n //\n //    /* (non-Javadoc)\n //     * @see\norg.eclipse.team.ui.synchronize.SaveableCompareEditorInput#contentsCreated()\n@@ -359,10 +365,12 @@ private LocalResourceTypedElement getLocalElement() {\n         return null;\n     }\n \n-    protected Object prepareInput(IProgressMonitor monitor) throws\nInvocationTargetException, InterruptedException {\n+    @Override\n+    protected ICompareInput prepareCompareInput(IProgressMonitor monitor)\n+            throws InvocationTargetException, InterruptedException {\n         ICompareInput input = createCompareInput();\n         getCompareConfiguration().setLeftEditable(isLeftEditable(input));\n-        getCompareConfiguration().setRightEditable(false);\n+        getCompareConfiguration().setRightEditable(isRightEditable(input));\n         ensureContentsCached(getLeftRevision(), getRightRevision(),\nmonitor);\n         initLabels(input);\n         setTitle(NLS.bind(TeamUIMessages.SyncInfoCompareInput_title,\nnew String[] { input.getName() }));\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..3bc24be\n--- /dev/null\n+++\nb/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CompareWithIndexAction.java\n@@ -0,0 +1,119 @@\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 java.io.File;\n+import java.io.IOException;\n+\n+import org.eclipse.compare.CompareUI;\n+import org.eclipse.compare.IContentChangeListener;\n+import org.eclipse.compare.IContentChangeNotifier;\n+import org.eclipse.compare.ITypedElement;\n+import org.eclipse.core.resources.IFile;\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.Utils;\n+import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;\n+import org.spearce.egit.core.internal.storage.GitFileRevision;\n+import org.spearce.egit.core.project.RepositoryMapping;\n+import org.spearce.egit.ui.internal.EditableRevision;\n+import org.spearce.egit.ui.internal.GitCompareFileRevisionEditorInput;\n+import org.spearce.jgit.lib.GitIndex;\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 nextFile =\nGitFileRevision.inIndex(repository, gitPath);\n+\n+        final IFile baseFile = (IFile) resource;\n+        final ITypedElement base =\nSaveableCompareEditorInput.createFileElement(baseFile);\n+\n+        final EditableRevision next = new EditableRevision(nextFile);\n+\n+        IContentChangeListener listener = new IContentChangeListener() {\n+            public void contentChanged(IContentChangeNotifier source) {\n+                final byte[] newContent = next.getModifiedContent();\n+                try {\n+                    final GitIndex index = repository.getIndex();\n+                    final File file = new\nFile(baseFile.getLocation().toString());\n+                    index.add(mapping.getWorkDir(), file, newContent);\n+                } catch (IOException e) {\n+                  \n Utils.handleError(getTargetPart().getSite().getShell(), e,\n+                            \"Error during adding to index\",\n+                            \"Error during adding to index\");\n+                    return;\n+                }\n+            }\n+        };\n+\n+        next.addContentChangeListener(listener);\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+\n+        final IResource resource = selectedResources[0];\n+        if (!(resource instanceof IFile)) {\n+            return false;\n+        }\n+        final RepositoryMapping mapping =\nRepositoryMapping.getMapping(resource.getProject());\n+        return mapping != null;\n+    }\n+\n+}\n\\ No newline at end of file\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java\nb/org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java\nindex 920a9c9..21b495a 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java\n@@ -170,6 +170,30 @@ public Entry add(File wd, File f) throws IOException {\n     }\n \n     /**\n+     * Add the content of a file to the index.\n+     *\n+     * @param wd\n+     *            workdir\n+     * @param f\n+     *            the file\n+     * @param content\n+     *            content of the file\n+     * @return a new or updated index entry for the path represented by f\n+     * @throws IOException\n+     */\n+    public Entry add(File wd, File f, byte[] content) throws IOException {\n+        byte[] key = makeKey(wd, f);\n+        Entry e = entries.get(key);\n+        if (e == null) {\n+            e = new Entry(key, f, 0, content);\n+            entries.put(key, e);\n+        } else {\n+            e.update(f, content);\n+        }\n+        return e;\n+    }\n+\n+    /**\n      * Remove a path from the index.\n      *\n      * @param wd\n@@ -360,6 +384,25 @@ Entry(byte[] key, File f, int stage)\n             flags = (short) ((stage << 12) | name.length); // TODO: fix\nflags\n         }\n \n+        Entry(byte[] key, File f, int stage, byte[] newContent)\n+                throws IOException {\n+            ctime = f.lastModified() * 1000000L;\n+            mtime = ctime; // we use same here\n+            dev = -1;\n+            ino = -1;\n+            if (config_filemode() && File_canExecute(f))\n+                mode = FileMode.EXECUTABLE_FILE.getBits();\n+            else\n+                mode = FileMode.REGULAR_FILE.getBits();\n+            uid = -1;\n+            gid = -1;\n+            size = newContent.length;\n+            ObjectWriter writer = new ObjectWriter(db);\n+            sha1 = writer.writeBlob(newContent);\n+            name = key;\n+            flags = (short) ((stage << 12) | name.length); // TODO: fix\nflags\n+        }\n+\n         Entry(TreeEntry f, int stage) {\n             ctime = -1; // hmm\n             mtime = -1;\n@@ -433,6 +476,28 @@ public boolean update(File f) throws IOException {\n             return modified;\n         }\n \n+        /**\n+         * Update this index entry with stat and SHA-1 information if\nit looks\n+         * like the file has been modified in the workdir.\n+         *\n+         * @param f\n+         *            file in work dir\n+         * @param newContent\n+         *            the new content of the file\n+         * @return true if a change occurred\n+         * @throws IOException\n+         */\n+        public boolean update(File f, byte[] newContent) throws\nIOException {\n+            boolean modified = false;\n+            size = newContent.length;\n+            ObjectWriter writer = new ObjectWriter(db);\n+            ObjectId newsha1 = sha1 = writer.writeBlob(newContent);\n+            if (!newsha1.equals(sha1))\n+                modified = true;\n+            sha1 = newsha1;\n+            return modified;\n+        }\n+\n         void write(ByteBuffer buf) {\n             int startposition = buf.position();\n             buf.putInt((int) (ctime / 1000000000L));\n-- \n1.6.1.2\n"},{"id":"105576","messageId":"551f769b0902200012vdf1bdb0qefa88e43cb16205b@mail.gmail.com","threadId":"17901","inReplyTo":"499D80A2.7030205@gmail.com","subject":"Re: [PATCH JGIT] Add \"compare with index\" action.","fromName":"Yann Simon","fromEmail":"yann.simon.fr@gmail.com","sentAt":"2009-02-20T08:12:34Z","receivedAt":"2009-02-20T08:12:34Z","isPatch":true,"sender":{"key":"yann.simon.fr@gmail.com","avatar":"https://gravatar.com/avatar/2d926895d27ac988c5c8e591887e5a6a4c7036390403c74fce92519119b887a0?d=mp&s=160"},"body":"2009/2/19 Yann Simon <yann.simon.fr@gmail.com>:\n> In the Compare With... menu, the \"compare with index\" action opens\n> a diff editor that compares the workspace version of a file and its\n> index version.\n>\n> The local file can be modified and saved.\n>\n> The staged version can be modified and saved. This updates the index.\n> For this, add methods into GitIndex to allow to specify a content\n> different from the file.\n>\n> Signed-off-by: Yann Simon <yann.simon.fr@gmail.com>\n> ---\n> This patch is working bug I am sure it could be better.\n> I am sending it for review, so any comments are welcome!\n\nThis patch is whitespace corrupted.\nPlease ignore.\n\n-- yann\n"}]}