Permalink
Browse files

Show diff when double-clicking on file in commit dialog

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>
  • Loading branch information...
1 parent 9c26a41 commit 23a36457dc6d31491368a495cba6b97c7b730d9b @robinst committed Mar 6, 2009
Showing with 40 additions and 0 deletions.
  1. +40 −0 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();

0 comments on commit 23a3645

Please sign in to comment.