From 5de57ee32d9e150da0748fd7c967e5d11f8d02a8 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Wed, 12 Apr 2017 23:06:28 +0300 Subject: [PATCH] [diff] DiffRequestFactory.getTitle accepts nulls --- .../intellij/diff/DiffRequestFactoryImpl.java | 10 +++++++- .../src/git4idea/log/GitLogDiffHandler.java | 23 ++++--------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/diff/DiffRequestFactoryImpl.java b/platform/diff-impl/src/com/intellij/diff/DiffRequestFactoryImpl.java index 98dc253fb707..dcb5c7284d0c 100644 --- a/platform/diff-impl/src/com/intellij/diff/DiffRequestFactoryImpl.java +++ b/platform/diff-impl/src/com/intellij/diff/DiffRequestFactoryImpl.java @@ -45,6 +45,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import static com.intellij.util.ObjectUtils.chooseNotNull; + public class DiffRequestFactoryImpl extends DiffRequestFactory { private final DiffContentFactoryEx myContentFactory = DiffContentFactoryEx.getInstanceEx(); @@ -127,7 +129,13 @@ public class DiffRequestFactoryImpl extends DiffRequestFactory { } @NotNull - public static String getTitle(@NotNull FilePath path1, @NotNull FilePath path2, @NotNull String separator) { + public static String getTitle(@Nullable FilePath path1, @Nullable FilePath path2, @NotNull String separator) { + assert path1 != null || path2 != null; + + if (path1 == null || path2 == null) { + return getContentTitle(chooseNotNull(path1, path2)); + } + if ((path1.isDirectory() || path2.isDirectory()) && path1.getPath().equals(path2.getPath())) { return path1.getPresentableUrl(); } diff --git a/plugins/git4idea/src/git4idea/log/GitLogDiffHandler.java b/plugins/git4idea/src/git4idea/log/GitLogDiffHandler.java index 42c1cb59ec89..bcb8854a1f8d 100644 --- a/plugins/git4idea/src/git4idea/log/GitLogDiffHandler.java +++ b/plugins/git4idea/src/git4idea/log/GitLogDiffHandler.java @@ -17,7 +17,6 @@ package git4idea.log; import com.intellij.diff.DiffContentFactoryEx; import com.intellij.diff.DiffManager; -import com.intellij.diff.DiffRequestFactoryImpl; import com.intellij.diff.contents.DiffContent; import com.intellij.diff.contents.EmptyContent; import com.intellij.diff.requests.DiffRequest; @@ -51,10 +50,9 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.Collections; -import java.util.Objects; +import static com.intellij.diff.DiffRequestFactoryImpl.getTitle; import static com.intellij.util.ObjectUtils.chooseNotNull; -import static com.intellij.util.ObjectUtils.notNull; public class GitLogDiffHandler implements VcsLogDiffHandler { private static final Logger LOG = Logger.getInstance(GitLogDiffHandler.class); @@ -84,7 +82,7 @@ public class GitLogDiffHandler implements VcsLogDiffHandler { DiffContent leftDiffContent = createDiffContent(root, leftPath, leftHash); DiffContent rightDiffContent = createDiffContent(root, rightPath, rightHash); - return new SimpleDiffRequest(getTitle(leftPath, rightPath), + return new SimpleDiffRequest(getTitle(leftPath, rightPath, " -> "), leftDiffContent, rightDiffContent, leftHash.asString(), rightHash.asString()); } @@ -110,7 +108,7 @@ public class GitLogDiffHandler implements VcsLogDiffHandler { LOG.assertTrue(file != null); DiffContent rightDiffContent = myDiffContentFactory.create(myProject, file); - return new SimpleDiffRequest(getTitle(revisionPath, localPath), + return new SimpleDiffRequest(getTitle(revisionPath, localPath, " -> "), leftDiffContent, rightDiffContent, revisionHash.asString(), "(Local)"); } @@ -131,7 +129,7 @@ public class GitLogDiffHandler implements VcsLogDiffHandler { " and " + (rightRevision == null ? "current revision" : rightRevision.asString()) + " in " + - getTitle(directoryPath, directoryPath); + getTitle(directoryPath, directoryPath, " -> "); VcsDiffUtil.showChangesDialog(myProject, dialogTitle, ContainerUtil.newArrayList(diff)); }, "Calculating Diff for " + directoryPath.getName()); } @@ -202,17 +200,4 @@ public class GitLogDiffHandler implements VcsLogDiffHandler { return diffContent; } - - @NotNull - private static String getTitle(@Nullable FilePath leftPath, @Nullable FilePath rightPath) { - LOG.assertTrue(leftPath != null || rightPath != null); - - if (Objects.equals(rightPath, leftPath)) { - return DiffRequestFactoryImpl.getContentTitle(notNull(leftPath)); - } - if (leftPath == null || rightPath == null) { - return DiffRequestFactoryImpl.getContentTitle(chooseNotNull(leftPath, rightPath)); - } - return DiffRequestFactoryImpl.getTitle(leftPath, rightPath, " -> "); - } }