From a2cc34426a205c3f199be5ca91a430ecff4ccba3 Mon Sep 17 00:00:00 2001 From: Mihail Buryakov Date: Fri, 30 May 2025 01:24:53 +0300 Subject: [PATCH] [eel-vcs] replace io.File with nio.Path GitOrigin-RevId: 061301240260bb2a70a0784ba485dd6a918403c9 --- .../src/git4idea/commands/GitHandler.java | 2 +- .../git4idea/commands/GitScriptGenerator.java | 3 +- .../src/git4idea/config/GitExecutable.kt | 34 ++++++++++--------- .../git4idea/rebase/GitRebaseEditorService.kt | 6 ++-- .../git4idea/repo/GitCommitTemplateTracker.kt | 7 ++-- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/GitHandler.java b/plugins/git4idea/src/git4idea/commands/GitHandler.java index f309a6d3ea0e..dfbbed852e19 100644 --- a/plugins/git4idea/src/git4idea/commands/GitHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitHandler.java @@ -252,7 +252,7 @@ public abstract class GitHandler { } public void addAbsoluteFile(@NotNull File file) { - myCommandLine.addParameter(myExecutable.convertFilePath(file)); + myCommandLine.addParameter(myExecutable.convertFilePath(file.toPath())); } /** diff --git a/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java b/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java index d7d0f872fccd..bdd265161b43 100644 --- a/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java +++ b/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java @@ -12,6 +12,7 @@ import git4idea.http.GitAskPassAppHandler; import org.jetbrains.annotations.NotNull; import java.io.File; +import java.nio.file.Path; import java.util.List; public class GitScriptGenerator extends ScriptGeneratorImpl { @@ -24,7 +25,7 @@ public class GitScriptGenerator extends ScriptGeneratorImpl { @Override protected @NotNull String getJavaExecutablePath() { if (myExecutable instanceof GitExecutable.Wsl) { - File javaExecutable = new File(String.format("%s\\bin\\java.exe", System.getProperty("java.home"))); + Path javaExecutable = Path.of(String.format("%s\\bin\\java.exe", System.getProperty("java.home"))); return myExecutable.convertFilePath(javaExecutable); } return super.getJavaExecutablePath(); diff --git a/plugins/git4idea/src/git4idea/config/GitExecutable.kt b/plugins/git4idea/src/git4idea/config/GitExecutable.kt index c4e6eb81ec5b..a4390920eab0 100644 --- a/plugins/git4idea/src/git4idea/config/GitExecutable.kt +++ b/plugins/git4idea/src/git4idea/config/GitExecutable.kt @@ -29,6 +29,8 @@ import java.io.File import java.nio.file.Files import java.nio.file.Path import kotlin.Throws +import kotlin.io.path.Path +import kotlin.io.path.absolutePathString sealed class GitExecutable { private companion object { @@ -71,12 +73,12 @@ sealed class GitExecutable { /** * Convert an absolute file path into a form that can be passed into executable arguments. */ - abstract fun convertFilePath(file: File): String + abstract fun convertFilePath(file: Path): String /** * Convert a file path, returned by git, to be used by IDE. */ - abstract fun convertFilePathBack(path: String, workingDir: File): File + abstract fun convertFilePathBack(path: String, workingDir: Path): Path @Throws(ExecutionException::class) abstract fun patchCommandLine(handler: GitHandler, commandLine: GeneralCommandLine, executableContext: GitExecutableContext) @@ -93,13 +95,13 @@ sealed class GitExecutable { override val isLocal: Boolean = true override fun toString(): String = exePath - override fun convertFilePath(file: File): String = file.absolutePath + override fun convertFilePath(file: Path): String = file.absolutePathString() - override fun convertFilePathBack(path: String, workingDir: File): File { + override fun convertFilePathBack(path: String, workingDir: Path): Path { if (SystemInfo.isWindows && path.startsWith(CYGDRIVE_PREFIX)) { val prefixSize = CYGDRIVE_PREFIX.length val localPath = path.substring(prefixSize, prefixSize + 1) + ":" + path.substring(prefixSize + 1) - return File(localPath) + return Path(localPath) } return workingDir.resolve(path) } @@ -164,8 +166,8 @@ sealed class GitExecutable { override val id: @NonNls String = eel.descriptor.toString() override val isLocal: Boolean = eel.descriptor === LocalEelDescriptor - override fun convertFilePath(file: File): String { - return if (isLocal) delegate.convertFilePath(file) else file.toPath().asEelPath().toString() + override fun convertFilePath(file: Path): String { + return if (isLocal) delegate.convertFilePath(file) else file.asEelPath().toString() } override fun getModificationTime(): Long { @@ -176,8 +178,8 @@ sealed class GitExecutable { ) } - override fun convertFilePathBack(path: String, workingDir: File): File { - return if (isLocal) delegate.convertFilePathBack(path, workingDir) else workingDir.toPath().resolve(path).toFile() + override fun convertFilePathBack(path: String, workingDir: Path): Path { + return if (isLocal) delegate.convertFilePathBack(path, workingDir) else workingDir.resolve(path) } override fun patchCommandLine(handler: GitHandler, commandLine: GeneralCommandLine, executableContext: GitExecutableContext) { @@ -205,17 +207,17 @@ sealed class GitExecutable { return 0 } - override fun convertFilePath(file: File): String { - val path = file.absolutePath + override fun convertFilePath(file: Path): String { + val path = file.absolutePathString() // 'C:\Users\file.txt' -> '/mnt/c/Users/file.txt' - val wslPath = distribution.getWslPath(file.toPath().toAbsolutePath()) + val wslPath = distribution.getWslPath(file.toAbsolutePath()) return wslPath ?: path } - override fun convertFilePathBack(path: String, workingDir: File): File = + override fun convertFilePathBack(path: String, workingDir: Path): Path = // '/mnt/c/Users/file.txt' -> 'C:\Users\file.txt' - File(distribution.getWindowsPath(path)) + Path(distribution.getWindowsPath(path)) override fun patchCommandLine(handler: GitHandler, commandLine: GeneralCommandLine, executableContext: GitExecutableContext) { if (executableContext.isWithNoTty) { @@ -302,8 +304,8 @@ sealed class GitExecutable { return 0 } - override fun convertFilePath(file: File): String = file.absolutePath - override fun convertFilePathBack(path: String, workingDir: File): File = File(path) + override fun convertFilePath(file: Path): String = file.absolutePathString() + override fun convertFilePathBack(path: String, workingDir: Path): Path = Path(path) override fun patchCommandLine(handler: GitHandler, commandLine: GeneralCommandLine, executableContext: GitExecutableContext) { throw ExecutionException(errorMessage) diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditorService.kt b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditorService.kt index fde44b866b0d..a8fc0b4c5f67 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditorService.kt +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditorService.kt @@ -9,8 +9,8 @@ import com.intellij.openapi.components.service import git4idea.config.GitExecutable import git4idea.editor.GitRebaseEditorApp import git4idea.editor.GitRebaseEditorAppHandler -import java.io.File import java.util.* +import kotlin.io.path.Path @Service(Service.Level.APP) internal class GitRebaseEditorService : ExternalProcessHandlerService( @@ -37,8 +37,8 @@ internal class GitRebaseEditorService : ExternalProcessHandlerService() @@ -190,9 +193,9 @@ internal class GitCommitTemplateTracker( private fun resolvePathAsAbsolute(repository: GitRepository, gitCommitTemplatePath: String): String? { val executable = GitExecutableManager.getInstance().getExecutable(repository.project) - val localPath = executable.convertFilePathBack(gitCommitTemplatePath, File(repository.root.path)) + val localPath = executable.convertFilePathBack(gitCommitTemplatePath, Path(repository.root.path)) if (localPath.exists()) { - return localPath.path + return localPath.pathString } return null