{"thread":{"id":"18216","subject":"[EGIT PATCH] Show diff when double-clicking on file in commit dialog","startedAt":"2009-03-08T20:09:49Z","lastAt":"2009-03-09T09:48:13Z","messageCount":3,"participants":["Robin Stocker","Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"107397","messageId":"49B4260D.6070501@nibor.org","threadId":"18216","inReplyTo":null,"subject":"[EGIT PATCH] Show diff when double-clicking on file in commit dialog","fromName":"Robin Stocker","fromEmail":"robin@nibor.org","sentAt":"2009-03-08T20:09:49Z","receivedAt":"2009-03-08T20:09:49Z","isPatch":true,"sender":{"key":"robin@nibor.org","avatar":"https://gravatar.com/avatar/c14673277e79914545e24f8ca819310592d6cb15b0f7832e176523b955de2c5d?d=mp&s=160"},"body":"It only compares the index version to the working tree version for now.\nSo if the file was already added to the index, the diff is empty. What\nit should show is the diff that will be in the commit.\n\nSigned-off-by: Robin Stocker <robin@nibor.org>\n---\n\nHi,\n\nAn essential feature I miss in EGit at the moment (apart from the\nsynchronize view [1]) is seeing what changes one is about to commit. In\nthe Subclipse SVN plugin one can double-click a file in the commit\ndialog and the diff is shown.\n\nThis patch is a first step for adding this to EGit. It only compares the\nindex version to the working tree version as I couldn't figure out an\neasy way to get the HEAD version.\n\nIt's more a proof of concept than a final patch. What do you think?\n\n[1] Someone is working on the synchronize view:\n    http://github.com/yanns/egit/commits/compare-with-index\n\n-- Robin, a different one :)\n\n .../egit/ui/internal/dialogs/CommitDialog.java     |   40 ++++++++++++++++++++\n 1 files changed, 40 insertions(+), 0 deletions(-)\n\ndiff --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\nindex 8b7fe45..6999e87 100644\n--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java\n+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java\n@@ -18,6 +18,8 @@\n import java.util.Comparator;\n import java.util.Iterator;\n \n+import org.eclipse.compare.CompareUI;\n+import org.eclipse.compare.ITypedElement;\n import org.eclipse.core.resources.IFile;\n import org.eclipse.core.resources.IProject;\n import org.eclipse.jface.dialogs.Dialog;\n@@ -52,9 +54,17 @@\n import org.eclipse.swt.widgets.Table;\n import org.eclipse.swt.widgets.TableColumn;\n import org.eclipse.swt.widgets.Text;\n+import org.eclipse.team.core.RepositoryProvider;\n+import org.eclipse.team.core.history.IFileHistory;\n+import org.eclipse.team.core.history.IFileRevision;\n+import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;\n import org.eclipse.ui.model.WorkbenchLabelProvider;\n+import org.spearce.egit.core.GitProvider;\n+import org.spearce.egit.core.internal.storage.GitFileHistoryProvider;\n+import org.spearce.egit.core.internal.storage.GitFileRevision;\n import org.spearce.egit.core.project.RepositoryMapping;\n import org.spearce.egit.ui.UIText;\n+import org.spearce.egit.ui.internal.GitCompareFileRevisionEditorInput;\n import org.spearce.jgit.lib.Constants;\n import org.spearce.jgit.lib.GitIndex;\n import org.spearce.jgit.lib.PersonIdent;\n@@ -262,6 +272,8 @@ public void modifyText(ModifyEvent e) {\n \t\tresourcesTable.setLayoutData(GridDataFactory.fillDefaults().hint(600,\n \t\t\t\t200).span(2,1).grab(true, true).create());\n \n+\t\tresourcesTable.addSelectionListener(new CommitItemSelectionListener());\n+\n \t\tresourcesTable.setHeaderVisible(true);\n \t\tTableColumn statCol = new TableColumn(resourcesTable, SWT.LEFT);\n \t\tstatCol.setText(UIText.CommitDialog_Status);\n@@ -505,6 +517,34 @@ public void widgetSelected(SelectionEvent e) {\n \n \t}\n \n+\tclass CommitItemSelectionListener extends SelectionAdapter {\n+\n+\t\tpublic void widgetDefaultSelected(SelectionEvent e) {\n+\t\t\tIStructuredSelection selection = (IStructuredSelection) filesViewer.getSelection();\n+\n+\t\t\tCommitItem commitItem = (CommitItem) selection.getFirstElement();\n+\t\t\tif (commitItem == null) {\n+\t\t\t\treturn;\n+\t\t\t}\n+\n+\t\t\tIProject project = commitItem.file.getProject();\n+\t\t\tGitProvider provider = (GitProvider) RepositoryProvider.getProvider(project);\n+\t\t\tGitFileHistoryProvider fileHistoryProvider = (GitFileHistoryProvider) provider.getFileHistoryProvider();\n+\n+\t\t\tIFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(commitItem.file, 0, null);\n+\n+\t\t\tIFileRevision baseFile = fileHistory.getFileRevision(GitFileRevision.INDEX);\n+\t\t\tIFileRevision nextFile = fileHistoryProvider.getWorkspaceFileRevision(commitItem.file);\n+\n+\t\t\tITypedElement base = new FileRevisionTypedElement(baseFile);\n+\t\t\tITypedElement next = new FileRevisionTypedElement(nextFile);\n+\n+\t\t\tGitCompareFileRevisionEditorInput input = new GitCompareFileRevisionEditorInput(base, next, null);\n+\t\t\tCompareUI.openCompareDialog(input);\n+\t\t}\n+\n+\t}\n+\n \t@Override\n \tprotected void okPressed() {\n \t\tcommitMessage = commitText.getText();\n-- \n1.6.1.2\n"},{"id":"107412","messageId":"200903082259.35886.robin.rosenberg.lists@dewire.com","threadId":"18216","inReplyTo":"49B4260D.6070501@nibor.org","subject":"Re: [EGIT PATCH] Show diff when double-clicking on file in commit dialog","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2009-03-08T21:59:35Z","receivedAt":"2009-03-08T21:59:35Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"söndag 08 mars 2009 21:09:49 skrev Robin Stocker <robin@nibor.org>:\n> It only compares the index version to the working tree version for now.\n> So if the file was already added to the index, the diff is empty. What\n> it should show is the diff that will be in the commit.\n> \n> Signed-off-by: Robin Stocker <robin@nibor.org>\n> ---\n> \n> Hi,\n> \n> An essential feature I miss in EGit at the moment (apart from the\n> synchronize view [1]) is seeing what changes one is about to commit. In\n> the Subclipse SVN plugin one can double-click a file in the commit\n> dialog and the diff is shown.\nHi, Robin. I miss that too!\n\n> This patch is a first step for adding this to EGit. It only compares the\n> index version to the working tree version as I couldn't figure out an\n> easy way to get the HEAD version.\nYou can look at how GitDocument does it.\n\n> \n> It's more a proof of concept than a final patch. What do you think?\n\nI've started on an version with the diff integrated into the same dialog, for\nsome reasons it's not done yet, but we might takes this meanwhile unless\nI complete the dialog real quick, as this is really useful, provided we compare\nwith HEAD.\n\n-- robin\n"},{"id":"107443","messageId":"49B4E5DD.8060302@nibor.org","threadId":"18216","inReplyTo":"200903082259.35886.robin.rosenberg.lists@dewire.com","subject":"Re: [EGIT PATCH] Show diff when double-clicking on file in commit dialog","fromName":"Robin Stocker","fromEmail":"robin@nibor.org","sentAt":"2009-03-09T09:48:13Z","receivedAt":"2009-03-09T09:48:13Z","isPatch":true,"sender":{"key":"robin@nibor.org","avatar":"https://gravatar.com/avatar/c14673277e79914545e24f8ca819310592d6cb15b0f7832e176523b955de2c5d?d=mp&s=160"},"body":"When double-clicking on a file in the commit dialog, a compare dialog is\nshown with the changes that are about to be committed. It compares the\nHEAD version with the working tree version.\n\nSigned-off-by: Robin Stocker <robin@nibor.org>\n---\n\nRobin Rosenberg schrieb:\n> söndag 08 mars 2009 21:09:49 skrev Robin Stocker <robin@nibor.org>:\n>> An essential feature I miss in EGit at the moment (apart from the\n>> synchronize view [1]) is seeing what changes one is about to commit. In\n>> the Subclipse SVN plugin one can double-click a file in the commit\n>> dialog and the diff is shown.\n> Hi, Robin. I miss that too!\n> \n>> This patch is a first step for adding this to EGit. It only compares the\n>> index version to the working tree version as I couldn't figure out an\n>> easy way to get the HEAD version.\n> You can look at how GitDocument does it.\n> \n>> It's more a proof of concept than a final patch. What do you think?\n> \n> I've started on an version with the diff integrated into the same dialog, for\n> some reasons it's not done yet, but we might takes this meanwhile unless\n> I complete the dialog real quick, as this is really useful, provided we compare\n> with HEAD.\n\nThat sounds even better! For the meantime, I've updated the patch to\ncompare with HEAD.\n\n-- Robin\n\n.../egit/ui/internal/dialogs/CommitDialog.java     |   56 ++++++++++++++++++++\n 1 files changed, 56 insertions(+), 0 deletions(-)\n\ndiff --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\nindex 8b7fe45..b69a4ba 100644\n--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java\n+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java\n@@ -18,6 +18,8 @@\n import java.util.Comparator;\n import java.util.Iterator;\n \n+import org.eclipse.compare.CompareUI;\n+import org.eclipse.compare.ITypedElement;\n import org.eclipse.core.resources.IFile;\n import org.eclipse.core.resources.IProject;\n import org.eclipse.jface.dialogs.Dialog;\n@@ -52,9 +54,17 @@\n import org.eclipse.swt.widgets.Table;\n import org.eclipse.swt.widgets.TableColumn;\n import org.eclipse.swt.widgets.Text;\n+import org.eclipse.team.core.RepositoryProvider;\n+import org.eclipse.team.core.history.IFileHistory;\n+import org.eclipse.team.core.history.IFileRevision;\n+import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;\n import org.eclipse.ui.model.WorkbenchLabelProvider;\n+import org.spearce.egit.core.GitProvider;\n+import org.spearce.egit.core.internal.storage.GitFileHistoryProvider;\n import org.spearce.egit.core.project.RepositoryMapping;\n import org.spearce.egit.ui.UIText;\n+import org.spearce.egit.ui.internal.GitCompareFileRevisionEditorInput;\n+import org.spearce.jgit.lib.Commit;\n import org.spearce.jgit.lib.Constants;\n import org.spearce.jgit.lib.GitIndex;\n import org.spearce.jgit.lib.PersonIdent;\n@@ -262,6 +272,8 @@ public void modifyText(ModifyEvent e) {\n \t\tresourcesTable.setLayoutData(GridDataFactory.fillDefaults().hint(600,\n \t\t\t\t200).span(2,1).grab(true, true).create());\n \n+\t\tresourcesTable.addSelectionListener(new CommitItemSelectionListener());\n+\n \t\tresourcesTable.setHeaderVisible(true);\n \t\tTableColumn statCol = new TableColumn(resourcesTable, SWT.LEFT);\n \t\tstatCol.setText(UIText.CommitDialog_Status);\n@@ -505,6 +517,50 @@ public void widgetSelected(SelectionEvent e) {\n \n \t}\n \n+\tclass CommitItemSelectionListener extends SelectionAdapter {\n+\n+\t\tpublic void widgetDefaultSelected(SelectionEvent e) {\n+\t\t\tIStructuredSelection selection = (IStructuredSelection) filesViewer.getSelection();\n+\n+\t\t\tCommitItem commitItem = (CommitItem) selection.getFirstElement();\n+\t\t\tif (commitItem == null) {\n+\t\t\t\treturn;\n+\t\t\t}\n+\n+\t\t\tIProject project = commitItem.file.getProject();\n+\t\t\tRepositoryMapping mapping = RepositoryMapping.getMapping(project);\n+\t\t\tif (mapping == null) {\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t\tRepository repository = mapping.getRepository();\n+\n+\t\t\tCommit headCommit;\n+\t\t\ttry {\n+\t\t\t\theadCommit = repository.mapCommit(Constants.HEAD);\n+\t\t\t} catch (IOException e1) {\n+\t\t\t\theadCommit = null;\n+\t\t\t}\n+\t\t\tif (headCommit == null) {\n+\t\t\t\treturn;\n+\t\t\t}\n+\n+\t\t\tGitProvider provider = (GitProvider) RepositoryProvider.getProvider(project);\n+\t\t\tGitFileHistoryProvider fileHistoryProvider = (GitFileHistoryProvider) provider.getFileHistoryProvider();\n+\n+\t\t\tIFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(commitItem.file, 0, null);\n+\n+\t\t\tIFileRevision baseFile = fileHistory.getFileRevision(headCommit.getCommitId().name());\n+\t\t\tIFileRevision nextFile = fileHistoryProvider.getWorkspaceFileRevision(commitItem.file);\n+\n+\t\t\tITypedElement base = new FileRevisionTypedElement(baseFile);\n+\t\t\tITypedElement next = new FileRevisionTypedElement(nextFile);\n+\n+\t\t\tGitCompareFileRevisionEditorInput input = new GitCompareFileRevisionEditorInput(base, next, null);\n+\t\t\tCompareUI.openCompareDialog(input);\n+\t\t}\n+\n+\t}\n+\n \t@Override\n \tprotected void okPressed() {\n \t\tcommitMessage = commitText.getText();\n-- \n1.6.1.2\n"}]}