From dbd7838aba2f54b28d4d5601f994e70cc2ddab2d Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Sun, 4 Aug 2019 07:59:49 +0200 Subject: Always check for merge commit when opening file diff The 2-way file diff is invoked from 3 different places in the code, but only one of them checked whether the diff was a merge commit. Move that check into the file diff method itself to have all 3 invocations checked. It might be possible that the other 2 invocations cannot be called for merge commits due to other external logic, but let's be fault tolerant here by always forbidding this. Change-Id: Ieaacc0c0ddf0bdbc273891cd557ab55ff5560133 Signed-off-by: Michael Keppler --- .../src/org/eclipse/egit/ui/internal/commit/DiffViewer.java | 12 +++++++++++- .../egit/ui/internal/history/CommitFileDiffViewer.java | 11 +---------- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'org.eclipse.egit.ui/src/org/eclipse') diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java index 53adaff7ec..fce1d12926 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffViewer.java @@ -51,6 +51,7 @@ import org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion; import org.eclipse.egit.ui.internal.dialogs.HyperlinkSourceViewer; import org.eclipse.egit.ui.internal.history.FileDiff; import org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.jface.resource.FontRegistry; @@ -797,10 +798,19 @@ public class DiffViewer extends HyperlinkSourceViewer { * the {@link FileDiff} to show */ public static void showTwoWayFileDiff(FileDiff d) { + ObjectId[] blobs = d.getBlobs(); + if (blobs.length > 2) { + MessageDialog.openInformation( + PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getShell(), + UIText.CommitFileDiffViewer_CanNotOpenCompareEditorTitle, + UIText.CommitFileDiffViewer_MergeCommitMultiAncestorMessage); + return; + } + String np = d.getNewPath(); String op = d.getOldPath(); RevCommit c = d.getCommit(); - ObjectId[] blobs = d.getBlobs(); // extract commits final RevCommit oldCommit; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java index 793304f40d..7b5f8dfc06 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java @@ -60,7 +60,6 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; import org.eclipse.jface.viewers.IOpenListener; @@ -614,15 +613,7 @@ public class CommitFileDiffViewer extends TableViewer { } void showTwoWayFileDiff(final FileDiff d) { - if (d.getBlobs().length <= 2) { - DiffViewer.showTwoWayFileDiff(d); - } else { - MessageDialog.openInformation( - PlatformUI.getWorkbench().getActiveWorkbenchWindow() - .getShell(), - UIText.CommitFileDiffViewer_CanNotOpenCompareEditorTitle, - UIText.CommitFileDiffViewer_MergeCommitMultiAncestorMessage); - } + DiffViewer.showTwoWayFileDiff(d); } void showWorkingDirectoryFileDiff(final FileDiff d) { -- cgit v1.2.3