From fde5987fbc695692305e644faa2357421ce40fdf Mon Sep 17 00:00:00 2001 From: Mihail Buryakov Date: Thu, 6 Nov 2025 11:30:51 +0200 Subject: [PATCH] [eel-vcs] IJPL-204860 cleanup after code review (cherry picked from commit c26eadd6840c74789b0dfc435d511c9d669ae950) IJ-CR-180951 GitOrigin-RevId: 7bfd5f1a0d065c3dc0b1dbe0fc8d35d2ea3faf37 --- .../eel/provider/utils/EelOutputChannel.kt | 6 +++--- .../ExternalProcessHandlerService.kt | 5 +++-- .../rt/src/git4idea/gpg/PinentryApp.java | 6 +++--- .../GitHandlerAuthenticationManager.java | 8 ++++---- .../git4idea/commands/GitScriptGenerator.java | 1 + .../commit/signing/GpgAgentConfigurator.kt | 19 +++++++------------ .../commit/signing/PinentryService.kt | 2 +- 7 files changed, 22 insertions(+), 25 deletions(-) diff --git a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/EelOutputChannel.kt b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/EelOutputChannel.kt index bd55c8c0d07f..4e551d0f0d6f 100644 --- a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/EelOutputChannel.kt +++ b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/EelOutputChannel.kt @@ -56,7 +56,7 @@ interface EelOutputChannel { /** * Closes the channel similarly to sendEof, but if the channel is not already closed, can log an error or propagate it to the receiver. */ - fun ensureClosed(error: () -> Throwable? = { null }) + fun ensureClosed(lazyError: () -> Throwable? = { null }) } @ApiStatus.Internal @@ -139,10 +139,10 @@ class EelOutputChannelImpl : EelOutputChannel, EelReceiveChannel { state.update { it.copy(closed = true) } } - override fun ensureClosed(error: () -> Throwable?) { + override fun ensureClosed(lazyError: () -> Throwable?) { state.getAndUpdate { if (!it.closed) { - it.copy(closed = true, closedWithError = error()) + it.copy(closed = true, closedWithError = lazyError()) } else { it diff --git a/platform/external-process-auth-helper/src/externalProcessAuthHelper/ExternalProcessHandlerService.kt b/platform/external-process-auth-helper/src/externalProcessAuthHelper/ExternalProcessHandlerService.kt index 26191072dc18..d1d8195b59f7 100644 --- a/platform/external-process-auth-helper/src/externalProcessAuthHelper/ExternalProcessHandlerService.kt +++ b/platform/external-process-auth-helper/src/externalProcessAuthHelper/ExternalProcessHandlerService.kt @@ -138,8 +138,9 @@ abstract class ExternalProcessHandlerService( override fun getExecutablePath(): Path = process.executableName.asNioPath() override fun close() { - stderr.close() - stdout.close() + stderr.use { + stdout.close() + } } } diff --git a/plugins/git4idea/rt/src/git4idea/gpg/PinentryApp.java b/plugins/git4idea/rt/src/git4idea/gpg/PinentryApp.java index aa7561c852be..431c8b16db30 100644 --- a/plugins/git4idea/rt/src/git4idea/gpg/PinentryApp.java +++ b/plugins/git4idea/rt/src/git4idea/gpg/PinentryApp.java @@ -31,7 +31,7 @@ public final class PinentryApp implements ExternalApp, ExternalCli { } public static final String PREFIX = "IJ_PINENTRY="; - public static final String ENTRYPOINT_PREFIX = "IJ_PINENTRY_ENTRYPOINT="; + public static final String EEL_ENTRYPOINT_PREFIX = "IJ_PINENTRY_ENTRYPOINT="; public int entryPointInternal(ExternalAppEntry entry) throws IOException, URISyntaxException { boolean shouldLog = isLogEnabled(entry.getArgs()); @@ -70,8 +70,8 @@ public final class PinentryApp implements ExternalApp, ExternalCli { if (pinentryUserData == null) { parsedPinentryData = Collections.emptyList(); } - else if (pinentryUserData.startsWith(ENTRYPOINT_PREFIX)) { - String withoutPrefix = pinentryUserData.replace(ENTRYPOINT_PREFIX, ""); + else if (pinentryUserData.startsWith(EEL_ENTRYPOINT_PREFIX)) { + String withoutPrefix = pinentryUserData.replace(EEL_ENTRYPOINT_PREFIX, ""); parsedPinentryData = Arrays.asList(withoutPrefix.split(":")).subList(1, 4); } else { diff --git a/plugins/git4idea/src/git4idea/commands/GitHandlerAuthenticationManager.java b/plugins/git4idea/src/git4idea/commands/GitHandlerAuthenticationManager.java index 186348d36e17..d31467299909 100644 --- a/plugins/git4idea/src/git4idea/commands/GitHandlerAuthenticationManager.java +++ b/plugins/git4idea/src/git4idea/commands/GitHandlerAuthenticationManager.java @@ -209,8 +209,8 @@ public final class GitHandlerAuthenticationManager implements AutoCloseable { if (GitGpgConfigUtilsKt.isGpgSignEnabledCached(repo)) { PinentryService.PinentryData pinentryData; - if (gitExecutable instanceof GitExecutable.Eel) { - pinentryData = PinentryService.getInstance(myProject).startSession(((GitExecutable.Eel)gitExecutable).getEel()); + if (gitExecutable instanceof GitExecutable.Eel gitExecutableEel) { + pinentryData = PinentryService.getInstance(myProject).startSession(gitExecutableEel.getEel()); } else { pinentryData = PinentryService.getInstance(myProject).startSession(null); @@ -226,8 +226,8 @@ public final class GitHandlerAuthenticationManager implements AutoCloseable { @NotNull ExternalProcessHandlerService service) throws IOException { GitExecutable executable = myHandler.getExecutable(); String scriptPath; - if (executable instanceof GitExecutable.Eel) { - EelApi eelApi = ((GitExecutable.Eel)executable).getEel(); + if (executable instanceof GitExecutable.Eel gitExecutableEel) { + EelApi eelApi = gitExecutableEel.getEel(); Path scriptFile = service.getCallbackScriptPath(eelApi, shouldUseBatchScript(executable), myDisposable); scriptPath = executable.convertFilePath(scriptFile); } diff --git a/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java b/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java index 2e975e6e25bd..79fbc35a997f 100644 --- a/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java +++ b/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java @@ -17,6 +17,7 @@ import java.nio.file.Path; import java.util.List; public class GitScriptGenerator extends ScriptGeneratorImpl { + @Nullable private final WSLDistribution myWSLDistribution; diff --git a/plugins/git4idea/src/git4idea/commit/signing/GpgAgentConfigurator.kt b/plugins/git4idea/src/git4idea/commit/signing/GpgAgentConfigurator.kt index 4c2a57106660..fc8cea8f1db9 100644 --- a/plugins/git4idea/src/git4idea/commit/signing/GpgAgentConfigurator.kt +++ b/plugins/git4idea/src/git4idea/commit/signing/GpgAgentConfigurator.kt @@ -54,6 +54,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext +import org.intellij.lang.annotations.Language import org.jetbrains.annotations.VisibleForTesting import java.io.IOException import java.nio.file.InvalidPathException @@ -224,8 +225,8 @@ internal class GpgAgentConfigurator(private val project: Project, private val cs } } - private suspend fun generatePinentryLauncher(executable: GitExecutable, gpgAgentPaths: GpgAgentPaths, pinentryFallback: String?) { - LOG.info("Creating pinentry launcher with fallback: ${pinentryFallback ?: "-"}") + private suspend fun generatePinentryLauncher(executable: GitExecutable, gpgAgentPaths: GpgAgentPaths, pinentryFallback: String) { + LOG.info("Creating pinentry launcher with fallback: ${pinentryFallback}") PinentryShellScriptLauncherGenerator(executable).generate(project, gpgAgentPaths, pinentryFallback) } @@ -344,7 +345,7 @@ private class GpgAgentCommandExecutorImpl( internal class PinentryShellScriptLauncherGenerator(val executable: GitExecutable) { - suspend fun generate(project: Project, gpgAgentPaths: GpgAgentPaths, fallbackPinentryPath: String?) = withContext(Dispatchers.IO) { + suspend fun generate(project: Project, gpgAgentPaths: GpgAgentPaths, fallbackPinentryPath: String) = withContext(Dispatchers.IO) { val path = gpgAgentPaths.gpgPinentryAppLauncher try { path.createParentDirectories().writeText(getScriptTemplate(fallbackPinentryPath)) @@ -370,14 +371,8 @@ internal class PinentryShellScriptLauncherGenerator(val executable: GitExecutabl return GitScriptGenerator(executable).addParameters(*getCommandLineParameters()).commandLine(PinentryApp::class.java, false) } - private fun getScriptTemplate(fallbackPinentryPath: String?): String { - // language="Shell Script" - val fallbackLine = if (fallbackPinentryPath != null) { - """exec ${CommandLineUtil.posixQuote(fallbackPinentryPath)} "$@"""" - } else { - """echo ERR pinentry program is not set""" - } - // language="Shell Script" + @Language("ShellScript") + private fun getScriptTemplate(fallbackPinentryPath: String): String { return run { """|#!/bin/sh |if [ -n "${'$'}$PINENTRY_USER_DATA_ENV" ]; then @@ -394,7 +389,7 @@ internal class PinentryShellScriptLauncherGenerator(val executable: GitExecutabl | ;; | esac |fi - |$fallbackLine + |exec ${CommandLineUtil.posixQuote(fallbackPinentryPath)} "$@" """.trimMargin() } } diff --git a/plugins/git4idea/src/git4idea/commit/signing/PinentryService.kt b/plugins/git4idea/src/git4idea/commit/signing/PinentryService.kt index 92e812adf855..8daaf6aef7ec 100644 --- a/plugins/git4idea/src/git4idea/commit/signing/PinentryService.kt +++ b/plugins/git4idea/src/git4idea/commit/signing/PinentryService.kt @@ -197,7 +197,7 @@ internal class PinentryService(private val cs: CoroutineScope) { companion object { const val PREFIX = PinentryApp.PREFIX - const val ENTRYPOINT_PREFIX = PinentryApp.ENTRYPOINT_PREFIX + const val ENTRYPOINT_PREFIX = PinentryApp.EEL_ENTRYPOINT_PREFIX } }