diff --git a/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/PathDescription.java b/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/PathDescription.java index c448a839ac66..8bf1c52e42c7 100644 --- a/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/PathDescription.java +++ b/platform/vcs-api/vcs-api-core/src/com/intellij/openapi/diff/impl/patch/PathDescription.java @@ -1,25 +1,14 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.diff.impl.patch; import org.jetbrains.annotations.NotNull; +import java.nio.file.Path; + public interface PathDescription { - @NotNull - String getPath(); + @NotNull Path getPath(); + boolean isDirectory(); + long lastModified(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/IdeaTextPatchBuilder.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/IdeaTextPatchBuilder.java index dd3dd1be67a2..8f13531b4735 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/IdeaTextPatchBuilder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/IdeaTextPatchBuilder.java @@ -98,10 +98,12 @@ public final class IdeaTextPatchBuilder { @Nullable private static AirContentRevision convertRevision(@Nullable ContentRevision cr, @Nullable String actualTextContent) { - if (cr == null) return null; - final FilePath fp = cr.getFile(); - final StaticPathDescription description = new StaticPathDescription(fp.isDirectory(), fp.getIOFile().lastModified(), fp.getPath()); + if (cr == null) { + return null; + } + FilePath filePath = cr.getFile(); + StaticPathDescription description = new StaticPathDescription(filePath.isDirectory(), filePath.getIOFile().toPath()); if (actualTextContent != null) { return new PartialTextAirContentRevision(actualTextContent, cr, description, null); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/StaticPathDescription.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/StaticPathDescription.java index 9794fd5b8fab..723b4c179fa6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/StaticPathDescription.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/StaticPathDescription.java @@ -3,20 +3,32 @@ package com.intellij.openapi.diff.impl.patch; import org.jetbrains.annotations.NotNull; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + final class StaticPathDescription implements PathDescription { - private final String myPath; + private final Path myPath; private final boolean myIsDirectory; private final long myLastModified; - StaticPathDescription(boolean isDirectory, long lastModified, String path) { + StaticPathDescription(boolean isDirectory, @NotNull Path path) { myIsDirectory = isDirectory; + + long lastModified; + try { + lastModified = Files.getLastModifiedTime(path).toMillis(); + } + catch (IOException e) { + lastModified = 0; + } myLastModified = lastModified; + myPath = path; } @Override - @NotNull - public String getPath() { + public @NotNull Path getPath() { return myPath; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java index c6f0f92ef298..398be95291c2 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java @@ -7,8 +7,6 @@ import com.intellij.diff.comparison.DiffTooBigException; import com.intellij.diff.comparison.iterables.FairDiffIterable; import com.intellij.diff.util.Range; import com.intellij.openapi.progress.DumbProgressIndicator; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.LineTokenizer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FileStatus; @@ -19,6 +17,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.File; import java.nio.file.Path; import java.text.MessageFormat; import java.util.ArrayList; @@ -331,14 +330,6 @@ public final class TextPatchBuilder { return hunk; } - public static @NotNull String getRelativePath(@NotNull String basePath, @NotNull String secondPath) { - String baseModified = FileUtil.toSystemIndependentName(basePath); - String secondModified = FileUtil.toSystemIndependentName(secondPath); - - String relPath = FileUtil.getRelativePath(baseModified, secondModified, '/', SystemInfo.isFileSystemCaseSensitive); - return relPath == null ? secondModified : relPath; - } - @NotNull private TextFilePatch buildPatchHeading(@NotNull AirContentRevision beforeRevision, @NotNull AirContentRevision afterRevision) { @@ -350,10 +341,10 @@ public final class TextPatchBuilder { private void setPatchHeading(@NotNull FilePatch result, @NotNull AirContentRevision beforeRevision, @NotNull AirContentRevision afterRevision) { - result.setBeforeName(getRelativePath(myBasePath.toString(), beforeRevision.getPath().getPath())); + result.setBeforeName(myBasePath.relativize(beforeRevision.getPath().getPath()).toString().replace(File.separatorChar, '/')); result.setBeforeVersionId(getRevisionName(beforeRevision)); - result.setAfterName(getRelativePath(myBasePath.toString(), afterRevision.getPath().getPath())); + result.setAfterName(myBasePath.relativize(afterRevision.getPath().getPath()).toString().replace(File.separatorChar, '/')); result.setAfterVersionId(getRevisionName(afterRevision)); }