Skip to contentSkip to conversation

Add "compare with index" action.

PATCH In review Yann Simon 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore

Yann Simon

author
#0 lore raw

PATCH 1/1 Add "compare with index" action.

In the Compare With... menu, the "compare with 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.

---
This send correct the whitespaces corruption.

-- yann

 .../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   |  119 +++++++++++++++
 .../src/org/spearce/jgit/lib/GitIndex.java         |   65 ++++++++
 7 files changed, 384 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
index 21ba19e..2f23c7d 100644
@@ -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
index 58b879f..cb3a5be 100644
@@ -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=Compare with index version
+CompareWithIndexAction_tooltip=Compare with 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
index 2f23559..678fd73 100644
@@ -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="&amp;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
index 8aa076f..49d4a42 100644
@@ -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 +119 -0

120 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
#1 lore raw

fredag 20 februari 2009 09:20:29 skrev Yann Simon <[email protected]>:

Quoted 3 lines

In the Compare With... menu, the "compare with index" action opens a diff editor that compares the workspace version of a file and its index version.

The appearance in the menu is a bit odd. "Compare with" is already in the menu context as that is the name of the menu that hold the Compare with index. So the menu name should be really be just "Git Index".

Quoted 5 lines

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.

One would expect this feature to work at any level of the project, not just files. That won't be a showstopper though.

-- robin

author
#2 lore raw

2009/2/22 Robin Rosenberg <[email protected]>:

Quoted 8 lines

fredag 20 februari 2009 09:20:29 skrev Yann Simon <[email protected]>:

Quoted 3 lines

In the Compare With... menu, the "compare with index" action opens a diff editor that compares the workspace version of a file and its index version.

The appearance in the menu is a bit odd. "Compare with" is already in the menu context as that is the name of the menu that hold the Compare with index. So the menu name should be really be just "Git Index".

Yes, you're right.
I can change the labels to:
CompareWithIndexAction_label=Git Index CompareWithIndexAction_tooltip=Compare with Git's index version

Quoted 8 lines
Quoted 5 lines

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.

One would expect this feature to work at any level of the project, not just files. That won't be a showstopper though.

Yes of course. In that case, we would need to display a tree of modifications. That could be done in a second step.

-- yann