diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserFilePathNode.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserFilePathNode.java index 704cb4388f6b..141dbb485fe5 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserFilePathNode.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserFilePathNode.java @@ -16,14 +16,15 @@ package com.intellij.openapi.vcs.changes.ui; +import com.intellij.openapi.util.SystemInfoRt; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.ChangesUtil; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.PlatformIcons; - -import java.io.File; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import static com.intellij.util.FontUtil.spaceAndThinSpace; @@ -78,6 +79,7 @@ public class ChangesBrowserFilePathNode extends ChangesBrowserNode { return FileUtil.toSystemDependentName(getUserObject().getPath()); } + @Nullable public static FilePath safeCastToFilePath(Object o) { if (o instanceof FilePath) return (FilePath)o; if (o instanceof Change) { @@ -86,14 +88,15 @@ public class ChangesBrowserFilePathNode extends ChangesBrowserNode { return null; } - public static String getRelativePath(FilePath parent, FilePath child) { - final String systemDependentChild = child.getPath().replace('/', File.separatorChar); - final String systemDependentParent = parent == null ? null : parent.getPath().replace('/', File.separatorChar); - if (systemDependentParent == null || ! systemDependentChild.startsWith(systemDependentParent)) { - return systemDependentChild; - } - final int beginOffset = (systemDependentParent.length() == 1 && '/' == systemDependentParent.charAt(0)) ? 0 : 1; // IDEADEV-35767 - return systemDependentChild.substring(systemDependentParent.length() + beginOffset).replace('/', File.separatorChar); + @NotNull + public static String getRelativePath(@Nullable FilePath parent, @NotNull FilePath child) { + boolean isLocal = !child.isNonLocal(); + boolean caseSensitive = isLocal && SystemInfoRt.isFileSystemCaseSensitive; + String result = parent != null ? FileUtil.getRelativePath(parent.getPath(), child.getPath(), '/', caseSensitive) : null; + + result = result == null ? child.getPath() : result; + + return isLocal ? FileUtil.toSystemDependentName(result) : result; } public int getSortWeight() {