[eel-vcs] replace io.File with nio.Path

GitOrigin-RevId: 061301240260bb2a70a0784ba485dd6a918403c9
This commit is contained in:
Mihail Buryakov
2025-05-30 01:24:53 +03:00
committed by intellij-monorepo-bot
parent e469d2cfa6
commit a2cc34426a
5 changed files with 29 additions and 23 deletions

View File

@@ -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()));
}
/**

View File

@@ -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();

View File

@@ -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)

View File

@@ -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<GitRebaseEditorAppHandler>(
@@ -37,8 +37,8 @@ internal class GitRebaseEditorService : ExternalProcessHandlerService<GitRebaseE
private class RebaseEditorAppHandler(private val editorHandler: GitRebaseEditorHandler,
private val executable: GitExecutable) : GitRebaseEditorAppHandler {
override fun editCommits(path: String, workingDir: String): Int {
val file = executable.convertFilePathBack(path, File(workingDir))
return editorHandler.editCommits(file)
val file = executable.convertFilePathBack(path, Path(workingDir))
return editorHandler.editCommits(file.toFile())
}
}
}

View File

@@ -34,6 +34,9 @@ import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.read
import kotlin.concurrent.write
import kotlin.coroutines.coroutineContext
import kotlin.io.path.Path
import kotlin.io.path.exists
import kotlin.io.path.pathString
private val LOG = logger<GitCommitTemplateTracker>()
@@ -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