diff --git a/platform/diff-api/src/com/intellij/diff/DiffRequestFactory.java b/platform/diff-api/src/com/intellij/diff/DiffRequestFactory.java
index 15e6f31bc515..5d05b7e3439d 100644
--- a/platform/diff-api/src/com/intellij/diff/DiffRequestFactory.java
+++ b/platform/diff-api/src/com/intellij/diff/DiffRequestFactory.java
@@ -63,7 +63,7 @@ public abstract class DiffRequestFactory {
public abstract String getContentTitle(@NotNull VirtualFile file);
@NotNull
- public abstract String getTitle(@NotNull VirtualFile file1, @NotNull VirtualFile file2);
+ public abstract String getTitle(@Nullable VirtualFile file1, @Nullable VirtualFile file2);
@NotNull
public abstract String getTitle(@NotNull VirtualFile file);
diff --git a/platform/diff-impl/diff-tests.iml b/platform/diff-impl/diff-tests.iml
index a378b2dfcfd9..7178eefe85a3 100644
--- a/platform/diff-impl/diff-tests.iml
+++ b/platform/diff-impl/diff-tests.iml
@@ -16,5 +16,6 @@
+
\ No newline at end of file
diff --git a/platform/diff-impl/src/com/intellij/diff/DiffRequestFactoryImpl.java b/platform/diff-impl/src/com/intellij/diff/DiffRequestFactoryImpl.java
index dcb5c7284d0c..60b428a6116b 100644
--- a/platform/diff-impl/src/com/intellij/diff/DiffRequestFactoryImpl.java
+++ b/platform/diff-impl/src/com/intellij/diff/DiffRequestFactoryImpl.java
@@ -111,14 +111,16 @@ public class DiffRequestFactoryImpl extends DiffRequestFactory {
@NotNull
@Override
- public String getTitle(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
- return getTitle(VcsUtil.getFilePath(file1), VcsUtil.getFilePath(file2), " vs ");
+ public String getTitle(@Nullable VirtualFile file1, @Nullable VirtualFile file2) {
+ FilePath path1 = file1 != null ? VcsUtil.getFilePath(file1) : null;
+ FilePath path2 = file2 != null ? VcsUtil.getFilePath(file2) : null;
+ return getTitle(path1, path2, " vs ");
}
@NotNull
@Override
public String getTitle(@NotNull VirtualFile file) {
- return getTitle(file, file);
+ return getTitle(file, null);
}
@NotNull
diff --git a/platform/diff-impl/tests/com/intellij/diff/DiffTestCase.kt b/platform/diff-impl/tests/com/intellij/diff/DiffTestCase.kt
index bb501a53faa3..b7f8b320e797 100644
--- a/platform/diff-impl/tests/com/intellij/diff/DiffTestCase.kt
+++ b/platform/diff-impl/tests/com/intellij/diff/DiffTestCase.kt
@@ -23,6 +23,7 @@ import com.intellij.openapi.progress.DumbProgressIndicator
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.util.text.StringUtil
+import com.intellij.openapi.vcs.LocalFilePath
import com.intellij.testFramework.UsefulTestCase
import com.intellij.util.containers.HashMap
import com.intellij.util.text.CharSequenceSubSequence
@@ -152,7 +153,7 @@ abstract class DiffTestCase : TestCase() {
return Math.max(1, document.lineCount)
}
- infix fun Int.until(a: Int): IntRange = this..a - 1
+ fun createFilePath(path: String) = LocalFilePath(path, path.endsWith('/') || path.endsWith('\\'))
//
// AutoTests
diff --git a/platform/diff-impl/tests/com/intellij/diff/util/DiffUtilTest.kt b/platform/diff-impl/tests/com/intellij/diff/util/DiffUtilTest.kt
index 538809266550..365e723690b8 100644
--- a/platform/diff-impl/tests/com/intellij/diff/util/DiffUtilTest.kt
+++ b/platform/diff-impl/tests/com/intellij/diff/util/DiffUtilTest.kt
@@ -30,9 +30,11 @@
*/
package com.intellij.diff.util
+import com.intellij.diff.DiffRequestFactoryImpl
import com.intellij.diff.DiffTestCase
import com.intellij.openapi.diff.DiffBundle
import com.intellij.util.containers.ContainerUtil
+import java.io.File
class DiffUtilTest : DiffTestCase() {
fun `test getSortedIndexes`() {
@@ -78,4 +80,50 @@ class DiffUtilTest : DiffTestCase() {
doTest(2, 1, "There are 2 changes and one conflict left")
doTest(2, 3, "There are 2 changes and 3 conflicts left")
}
+
+ fun `test diff content titles`() {
+ fun doTest(path: String, expected: String) {
+ val filePath = createFilePath(path)
+ val actual1 = DiffRequestFactoryImpl.getContentTitle(filePath)
+ val actual2 = DiffRequestFactoryImpl.getTitle(filePath, null, " <-> ")
+ val actual3 = DiffRequestFactoryImpl.getTitle(null, filePath, " <-> ")
+
+ val expectedNative = expected.replace('/', File.separatorChar)
+ assertEquals(expectedNative, actual1)
+ assertEquals(expectedNative, actual2)
+ assertEquals(expectedNative, actual3)
+ }
+
+ doTest("file.txt", "file.txt")
+ doTest("/path/to/file.txt", "file.txt (/path/to)")
+ doTest("/path/to/dir/", "/path/to/dir")
+ }
+
+ fun `test diff request titles`() {
+ fun doTest(path1: String, path2: String, expected: String) {
+ val filePath1 = createFilePath(path1)
+ val filePath2 = createFilePath(path2)
+ val actual = DiffRequestFactoryImpl.getTitle(filePath1, filePath2, " <-> ")
+ assertEquals(expected.replace('/', File.separatorChar), actual)
+ }
+
+ doTest("file1.txt", "file1.txt", "file1.txt")
+ doTest("/path/to/file1.txt", "/path/to/file1.txt", "file1.txt (/path/to)")
+ doTest("/path/to/dir1/", "/path/to/dir1/", "/path/to/dir1")
+
+ doTest("file1.txt", "file2.txt", "file1.txt <-> file2.txt")
+ doTest("/path/to/file1.txt", "/path/to/file2.txt", "file1.txt <-> file2.txt (/path/to)")
+ doTest("/path/to/dir1/", "/path/to/dir2/", "dir1 <-> dir2 (/path/to)")
+
+ doTest("/path/to/file1.txt", "/path/to_another/file1.txt", "file1.txt (/path/to <-> /path/to_another)")
+ doTest("/path/to/file1.txt", "/path/to_another/file2.txt", "file1.txt <-> file2.txt (/path/to <-> /path/to_another)")
+ doTest("/path/to/dir1/", "/path/to_another/dir2/", "dir1 <-> dir2 (/path/to <-> /path/to_another)")
+
+ doTest("file1.txt", "/path/to/file1.txt", "file1.txt <-> /path/to/file1.txt")
+ doTest("file1.txt", "/path/to/file2.txt", "file1.txt <-> /path/to/file2.txt")
+
+ doTest("/path/to/dir1/", "/path/to/file2.txt", "dir1/ <-> file2.txt (/path/to)")
+ doTest("/path/to/file1.txt", "/path/to/dir2/", "file1.txt <-> dir2/ (/path/to)")
+ doTest("/path/to/dir1/", "/path/to_another/file2.txt", "dir1/ <-> file2.txt (/path/to <-> /path/to_another)")
+ }
}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java
index 0fb2ebbdd349..2c0c909ba7bf 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java
@@ -341,24 +341,9 @@ public class ChangeDiffRequestProducer implements DiffRequestProducer {
public static String getRequestTitle(@NotNull Change change) {
ContentRevision bRev = change.getBeforeRevision();
ContentRevision aRev = change.getAfterRevision();
-
- assert bRev != null || aRev != null;
- if (bRev != null && aRev != null) {
- FilePath bPath = bRev.getFile();
- FilePath aPath = aRev.getFile();
- if (bPath.equals(aPath)) {
- return DiffRequestFactoryImpl.getContentTitle(bPath);
- }
- else {
- return DiffRequestFactoryImpl.getTitle(bPath, aPath, " -> ");
- }
- }
- else if (bRev != null) {
- return DiffRequestFactoryImpl.getContentTitle(bRev.getFile());
- }
- else {
- return DiffRequestFactoryImpl.getContentTitle(aRev.getFile());
- }
+ FilePath bPath = bRev != null ? bRev.getFile() : null;
+ FilePath aPath = aRev != null ? aRev.getFile() : null;
+ return DiffRequestFactoryImpl.getTitle(bPath, aPath, " -> ");
}
@NotNull
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/VcsHistoryUtil.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/VcsHistoryUtil.java
index ba9cab56309d..e5fb8b2f6b09 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/VcsHistoryUtil.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/VcsHistoryUtil.java
@@ -96,13 +96,7 @@ public class VcsHistoryUtil {
FilePath path1 = getRevisionPath(revision1);
FilePath path2 = getRevisionPath(revision2);
- String title;
- if (path1 != null && path2 != null) {
- title = DiffRequestFactoryImpl.getTitle(path1, path2, " -> ");
- }
- else {
- title = DiffRequestFactoryImpl.getContentTitle(path);
- }
+ String title = DiffRequestFactoryImpl.getTitle(path1, path2, " -> ");
DiffContent diffContent1 = createContent(project, content1, revision1, path);
DiffContent diffContent2 = createContent(project, content2, revision2, path);