git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [EGIT PATCH] Show diff when double-clicking on file in commit dialog
@ 2009-03-08 20:09 Robin Stocker
  2009-03-08 21:59 ` Robin Rosenberg
  0 siblings, 1 reply; 3+ messages in thread
From: Robin Stocker @ 2009-03-08 20:09 UTC (permalink / raw
  To: Shawn O. Pearce, Robin Rosenberg; +Cc: git

It only compares the index version to the working tree version for now.
So if the file was already added to the index, the diff is empty. What
it should show is the diff that will be in the commit.

Signed-off-by: Robin Stocker <robin@nibor.org>
---

Hi,

An essential feature I miss in EGit at the moment (apart from the
synchronize view [1]) is seeing what changes one is about to commit. In
the Subclipse SVN plugin one can double-click a file in the commit
dialog and the diff is shown.

This patch is a first step for adding this to EGit. It only compares the
index version to the working tree version as I couldn't figure out an
easy way to get the HEAD version.

It's more a proof of concept than a final patch. What do you think?

[1] Someone is working on the synchronize view:
    http://github.com/yanns/egit/commits/compare-with-index

-- Robin, a different one :)

 .../egit/ui/internal/dialogs/CommitDialog.java     |   40 ++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
index 8b7fe45..6999e87 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
@@ -18,6 +18,8 @@
 import java.util.Comparator;
 import java.util.Iterator;
 
+import org.eclipse.compare.CompareUI;
+import org.eclipse.compare.ITypedElement;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.jface.dialogs.Dialog;
@@ -52,9 +54,17 @@
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Text;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.core.history.IFileHistory;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.spearce.egit.core.GitProvider;
+import org.spearce.egit.core.internal.storage.GitFileHistoryProvider;
+import org.spearce.egit.core.internal.storage.GitFileRevision;
 import org.spearce.egit.core.project.RepositoryMapping;
 import org.spearce.egit.ui.UIText;
+import org.spearce.egit.ui.internal.GitCompareFileRevisionEditorInput;
 import org.spearce.jgit.lib.Constants;
 import org.spearce.jgit.lib.GitIndex;
 import org.spearce.jgit.lib.PersonIdent;
@@ -262,6 +272,8 @@ public void modifyText(ModifyEvent e) {
 		resourcesTable.setLayoutData(GridDataFactory.fillDefaults().hint(600,
 				200).span(2,1).grab(true, true).create());
 
+		resourcesTable.addSelectionListener(new CommitItemSelectionListener());
+
 		resourcesTable.setHeaderVisible(true);
 		TableColumn statCol = new TableColumn(resourcesTable, SWT.LEFT);
 		statCol.setText(UIText.CommitDialog_Status);
@@ -505,6 +517,34 @@ public void widgetSelected(SelectionEvent e) {
 
 	}
 
+	class CommitItemSelectionListener extends SelectionAdapter {
+
+		public void widgetDefaultSelected(SelectionEvent e) {
+			IStructuredSelection selection = (IStructuredSelection) filesViewer.getSelection();
+
+			CommitItem commitItem = (CommitItem) selection.getFirstElement();
+			if (commitItem == null) {
+				return;
+			}
+
+			IProject project = commitItem.file.getProject();
+			GitProvider provider = (GitProvider) RepositoryProvider.getProvider(project);
+			GitFileHistoryProvider fileHistoryProvider = (GitFileHistoryProvider) provider.getFileHistoryProvider();
+
+			IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(commitItem.file, 0, null);
+
+			IFileRevision baseFile = fileHistory.getFileRevision(GitFileRevision.INDEX);
+			IFileRevision nextFile = fileHistoryProvider.getWorkspaceFileRevision(commitItem.file);
+
+			ITypedElement base = new FileRevisionTypedElement(baseFile);
+			ITypedElement next = new FileRevisionTypedElement(nextFile);
+
+			GitCompareFileRevisionEditorInput input = new GitCompareFileRevisionEditorInput(base, next, null);
+			CompareUI.openCompareDialog(input);
+		}
+
+	}
+
 	@Override
 	protected void okPressed() {
 		commitMessage = commitText.getText();
-- 
1.6.1.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [EGIT PATCH] Show diff when double-clicking on file in commit dialog
  2009-03-08 20:09 [EGIT PATCH] Show diff when double-clicking on file in commit dialog Robin Stocker
@ 2009-03-08 21:59 ` Robin Rosenberg
  2009-03-09  9:48   ` Robin Stocker
  0 siblings, 1 reply; 3+ messages in thread
From: Robin Rosenberg @ 2009-03-08 21:59 UTC (permalink / raw
  To: Robin Stocker; +Cc: Shawn O. Pearce, git

söndag 08 mars 2009 21:09:49 skrev Robin Stocker <robin@nibor.org>:
> It only compares the index version to the working tree version for now.
> So if the file was already added to the index, the diff is empty. What
> it should show is the diff that will be in the commit.
> 
> Signed-off-by: Robin Stocker <robin@nibor.org>
> ---
> 
> Hi,
> 
> An essential feature I miss in EGit at the moment (apart from the
> synchronize view [1]) is seeing what changes one is about to commit. In
> the Subclipse SVN plugin one can double-click a file in the commit
> dialog and the diff is shown.
Hi, Robin. I miss that too!

> This patch is a first step for adding this to EGit. It only compares the
> index version to the working tree version as I couldn't figure out an
> easy way to get the HEAD version.
You can look at how GitDocument does it.

> 
> It's more a proof of concept than a final patch. What do you think?

I've started on an version with the diff integrated into the same dialog, for
some reasons it's not done yet, but we might takes this meanwhile unless
I complete the dialog real quick, as this is really useful, provided we compare
with HEAD.

-- robin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [EGIT PATCH] Show diff when double-clicking on file in commit dialog
  2009-03-08 21:59 ` Robin Rosenberg
@ 2009-03-09  9:48   ` Robin Stocker
  0 siblings, 0 replies; 3+ messages in thread
From: Robin Stocker @ 2009-03-09  9:48 UTC (permalink / raw
  To: Robin Rosenberg; +Cc: Shawn O. Pearce, git

When double-clicking on a file in the commit dialog, a compare dialog is
shown with the changes that are about to be committed. It compares the
HEAD version with the working tree version.

Signed-off-by: Robin Stocker <robin@nibor.org>
---

Robin Rosenberg schrieb:
> söndag 08 mars 2009 21:09:49 skrev Robin Stocker <robin@nibor.org>:
>> An essential feature I miss in EGit at the moment (apart from the
>> synchronize view [1]) is seeing what changes one is about to commit. In
>> the Subclipse SVN plugin one can double-click a file in the commit
>> dialog and the diff is shown.
> Hi, Robin. I miss that too!
> 
>> This patch is a first step for adding this to EGit. It only compares the
>> index version to the working tree version as I couldn't figure out an
>> easy way to get the HEAD version.
> You can look at how GitDocument does it.
> 
>> It's more a proof of concept than a final patch. What do you think?
> 
> I've started on an version with the diff integrated into the same dialog, for
> some reasons it's not done yet, but we might takes this meanwhile unless
> I complete the dialog real quick, as this is really useful, provided we compare
> with HEAD.

That sounds even better! For the meantime, I've updated the patch to
compare with HEAD.

-- Robin

.../egit/ui/internal/dialogs/CommitDialog.java     |   56 ++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
index 8b7fe45..b69a4ba 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
@@ -18,6 +18,8 @@
 import java.util.Comparator;
 import java.util.Iterator;
 
+import org.eclipse.compare.CompareUI;
+import org.eclipse.compare.ITypedElement;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.jface.dialogs.Dialog;
@@ -52,9 +54,17 @@
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Text;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.core.history.IFileHistory;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.spearce.egit.core.GitProvider;
+import org.spearce.egit.core.internal.storage.GitFileHistoryProvider;
 import org.spearce.egit.core.project.RepositoryMapping;
 import org.spearce.egit.ui.UIText;
+import org.spearce.egit.ui.internal.GitCompareFileRevisionEditorInput;
+import org.spearce.jgit.lib.Commit;
 import org.spearce.jgit.lib.Constants;
 import org.spearce.jgit.lib.GitIndex;
 import org.spearce.jgit.lib.PersonIdent;
@@ -262,6 +272,8 @@ public void modifyText(ModifyEvent e) {
 		resourcesTable.setLayoutData(GridDataFactory.fillDefaults().hint(600,
 				200).span(2,1).grab(true, true).create());
 
+		resourcesTable.addSelectionListener(new CommitItemSelectionListener());
+
 		resourcesTable.setHeaderVisible(true);
 		TableColumn statCol = new TableColumn(resourcesTable, SWT.LEFT);
 		statCol.setText(UIText.CommitDialog_Status);
@@ -505,6 +517,50 @@ public void widgetSelected(SelectionEvent e) {
 
 	}
 
+	class CommitItemSelectionListener extends SelectionAdapter {
+
+		public void widgetDefaultSelected(SelectionEvent e) {
+			IStructuredSelection selection = (IStructuredSelection) filesViewer.getSelection();
+
+			CommitItem commitItem = (CommitItem) selection.getFirstElement();
+			if (commitItem == null) {
+				return;
+			}
+
+			IProject project = commitItem.file.getProject();
+			RepositoryMapping mapping = RepositoryMapping.getMapping(project);
+			if (mapping == null) {
+				return;
+			}
+			Repository repository = mapping.getRepository();
+
+			Commit headCommit;
+			try {
+				headCommit = repository.mapCommit(Constants.HEAD);
+			} catch (IOException e1) {
+				headCommit = null;
+			}
+			if (headCommit == null) {
+				return;
+			}
+
+			GitProvider provider = (GitProvider) RepositoryProvider.getProvider(project);
+			GitFileHistoryProvider fileHistoryProvider = (GitFileHistoryProvider) provider.getFileHistoryProvider();
+
+			IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(commitItem.file, 0, null);
+
+			IFileRevision baseFile = fileHistory.getFileRevision(headCommit.getCommitId().name());
+			IFileRevision nextFile = fileHistoryProvider.getWorkspaceFileRevision(commitItem.file);
+
+			ITypedElement base = new FileRevisionTypedElement(baseFile);
+			ITypedElement next = new FileRevisionTypedElement(nextFile);
+
+			GitCompareFileRevisionEditorInput input = new GitCompareFileRevisionEditorInput(base, next, null);
+			CompareUI.openCompareDialog(input);
+		}
+
+	}
+
 	@Override
 	protected void okPressed() {
 		commitMessage = commitText.getText();
-- 
1.6.1.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-03-09  9:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-08 20:09 [EGIT PATCH] Show diff when double-clicking on file in commit dialog Robin Stocker
2009-03-08 21:59 ` Robin Rosenberg
2009-03-09  9:48   ` Robin Stocker

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).