[eel-vcs] IJPL-204860 cleanup after code review

(cherry picked from commit c26eadd6840c74789b0dfc435d511c9d669ae950)

IJ-CR-180951

GitOrigin-RevId: 7bfd5f1a0d065c3dc0b1dbe0fc8d35d2ea3faf37
This commit is contained in:
Mihail Buryakov
2025-11-12 14:13:10 +00:00
committed by intellij-monorepo-bot
parent f93f5c52d3
commit fde5987fbc
7 changed files with 22 additions and 25 deletions
@@ -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
@@ -138,8 +138,9 @@ abstract class ExternalProcessHandlerService<T : ExternalAppHandler>(
override fun getExecutablePath(): Path = process.executableName.asNioPath()
override fun close() {
stderr.close()
stdout.close()
stderr.use {
stdout.close()
}
}
}
@@ -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 {
@@ -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);
}
@@ -17,6 +17,7 @@ import java.nio.file.Path;
import java.util.List;
public class GitScriptGenerator extends ScriptGeneratorImpl {
@Nullable
private final WSLDistribution myWSLDistribution;
@@ -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()
}
}
@@ -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
}
}