Add "compare with Git Index" action.
PATCH 1/1 Add "compare with Git Index" action.
In the Compare With... menu, the "Git Index" action opens a diff editor that compares the workspace version of a file and its index version.
The local file can be modified and saved.
The staged version can be modified and saved. This updates the index. For this, add methods into GitIndex to allow to specify a content different from the file.
---
Changed comapred to previous version:
- fix saving the index version.
.../core/internal/storage/GitFileRevision.java | 11 ++ org.spearce.egit.ui/plugin.properties | 3 + org.spearce.egit.ui/plugin.xml | 7 + .../spearce/egit/ui/internal/EditableRevision.java | 157 ++++++++++++++++++++ .../GitCompareFileRevisionEditorInput.java | 36 +++-- .../internal/actions/CompareWithIndexAction.java | 120 +++++++++++++++ .../src/org/spearce/jgit/lib/GitIndex.java | 65 ++++++++ 7 files changed, 385 insertions(+), 14 deletions(-) create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/EditableRevision.java create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CompareWithIndexAction.java
org.spearce.egit.core/src/org/spearce/egit/core/internal/storage/GitFileRevision.java +11 -0
@@ -49,6 +49,17 @@ public static GitFileRevision inCommit(final Repository db, return new CommitFileRevision(db, commit, path, blobId); } + /** + * @param db + * the repository which contains the index to use. + * @param path + * path of the resource in the index + * @return revision implementation for the given path in the index + */ + public static GitFileRevision inIndex(final Repository db, final String path) { + return new IndexFileRevision(db, path); + } + private final String path; GitFileRevision(final String fileName) {
org.spearce.egit.ui/plugin.properties +3 -0
@@ -31,6 +31,9 @@ Decorator_description=Shows Git specific information on resources in projects un CompareWithRevisionAction_label=Compare With Git Revision CompareWithRevisionAction_tooltip=Compare With a Git Revision +CompareWithIndexAction_label=Git Index +CompareWithIndexAction_tooltip=Compare with Git's index version + ShowResourceInHistoryAction_label=Show in Resource History ShowResourceInHistoryAction_tooltip=Show selected files in the resource history view.
org.spearce.egit.ui/plugin.xml +7 -0
@@ -108,6 +108,13 @@ label="%CommitAction_label" menubarPath="team.main/group1" tooltip="%CommitAction_tooltip"/> + <action + class="org.spearce.egit.ui.internal.actions.CompareWithIndexAction" + id="org.spearce.egit.ui.internal.actions.CompareWithIndexAction" + label="%CompareWithIndexAction_label" + menubarPath="compareWithMenu/gitCompareWithGroup" + tooltip="&CompareWithIndexAction_tooltip"> + </action> </objectContribution> <objectContribution id="org.spearce.egit.ui.resetto"
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/EditableRevision.java new file +157 -0
157 lines not on this page · raw message
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/GitCompareFileRevisionEditorInput.java +22 -14
@@ -11,7 +11,6 @@ import java.lang.reflect.InvocationTargetException; import org.eclipse.compare.CompareConfiguration; -import org.eclipse.compare.CompareEditorInput; import org.eclipse.compare.IEditableContent; import org.eclipse.compare.IResourceProvider; import org.eclipse.compare.ITypedElement;
@@ -34,13 +33,14 @@ import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.internal.ui.history.FileRevisionTypedElement; import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement; +import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput; import org.eclipse.ui.IWorkbenchPage; /** * The input provider for the compare editor when working on resources * under Git control. */ -public class GitCompareFileRevisionEditorInput extends CompareEditorInput { +public class GitCompareFileRevisionEditorInput extends SaveableCompareEditorInput { private ITypedElement left; private ITypedElement right;
@@ -52,7 +52,7 @@ * @param page */ public GitCompareFileRevisionEditorInput(ITypedElement left, ITypedElement right, IWorkbenchPage page) { - super(new CompareConfiguration()); + super(new CompareConfiguration(), page); this.left = left; this.right = right; }
@@ -90,9 +90,18 @@ private static void ensureContentsCached(FileRevisionTypedElement left, FileRevi } private boolean isLeftEditable(ICompareInput input) { - Object left = input.getLeft(); - if (left instanceof IEditableContent) { - return ((IEditableContent) left).isEditable(); + Object tmpLeft = input.getLeft(); + return isEditable(tmpLeft); + } + + private boolean isRightEditable(ICompareInput input) { + Object tmpRight = input.getRight(); + return isEditable(tmpRight); + } + + private boolean isEditable(Object object) { + if (object instanceof IEditableContent) { + return ((IEditableContent) object).isEditable(); } return false; }
@@ -326,12 +335,9 @@ private String getContentIdentifier(ITypedElement element){ return TeamUIMessages.CompareFileRevisionEditorInput_2; } -// /* (non-Javadoc) -// * @see org.eclipse.team.ui.synchronize.LocalResourceCompareEditorInput#fireInputChange() -// */ -// protected void fireInputChange() { -// ((DiffNode)getCompareResult()).fireChange(); -// } + @Override + protected void fireInputChange() { + } // // /* (non-Javadoc) // * @see org.eclipse.team.ui.synchronize.SaveableCompareEditorInput#contentsCreated()
@@ -359,10 +365,12 @@ private LocalResourceTypedElement getLocalElement() { return null; } - protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + @Override + protected ICompareInput prepareCompareInput(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { ICompareInput input = createCompareInput(); getCompareConfiguration().setLeftEditable(isLeftEditable(input)); - getCompareConfiguration().setRightEditable(false); + getCompareConfiguration().setRightEditable(isRightEditable(input)); ensureContentsCached(getLeftRevision(), getRightRevision(), monitor); initLabels(input); setTitle(NLS.bind(TeamUIMessages.SyncInfoCompareInput_title, new String[] { input.getName() }));
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CompareWithIndexAction.java new file +120 -0
121 lines not on this page · raw message
org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java +65 -0
83 lines not on this page · raw message
Signature · 1 line
1.6.1.2
tisdag 10 mars 2009 11:03:08 skrev Yann Simon <[email protected]>:
Quoted 6 lines
In the Compare With... menu, the "Git Index" action opens a diff editor that compares the workspace version of a file and its index version.
The local file can be modified and saved.
Quoted 8 lines
The staged version can be modified and saved. This updates the index. For this, add methods into GitIndex to allow to specify a content different from the file.
Signed-off-by Yann Simon <[email protected]>---
Changed comapred to previous version:
- fix saving the index version.
Saving works, but the diff regions aren't updated on save. When there is a diff this would give us the partial staging similar to git gui, if only (not your fault) the commit dialog would allow us to make a distinction between changes in the workdir and the index.
-- robin
2009/3/11 Robin Rosenberg <[email protected]>:
Quoted 1 line
Saving works, but the diff regions aren't updated on save.
Sorry, I do not understand. Can you explain me more?
Quoted 4 lines
When there is a diff
this would give us the partial staging similar to git gui, if only (not your fault) the commit dialog would allow us to make a distinction between changes in the workdir and the index.
Yes, I know that this patch is not very usefull for the moment. I was more looking for a review as an inclusion.
And you found one bug. Thank you for that!
--
yann
fredag 13 mars 2009 11:28:48 skrev Yann Simon <[email protected]>:
Quoted 4 lines
2009/3/11 Robin Rosenberg <[email protected]>:
Quoted 1 line
Saving works, but the diff regions aren't updated on save.
Sorry, I do not understand. Can you explain me more?
The compare ui marks the hunks when you bring it up. I think it should update on save to the same view you would see when it is first brought up.
Quoted 8 lines
Quoted 4 lines
When there is a diff
this would give us the partial staging similar to git gui, if only (not your fault) the commit dialog would allow us to make a distinction between changes in the workdir and the index.Yes, I know that this patch is not very usefull for the moment. I was more looking for a review as an inclusion.
And you found one bug. Thank you for that!
Well it is, sort of though it's not *the* solution.
-- robin