Add runtime diagnostic logging for level setup, native Git calls, inspection, validation, and UI command flow
This commit is contained in:
@@ -54,11 +54,27 @@ internal class GitProcessRunner(
|
||||
arguments: List<String>,
|
||||
environment: Map<String, String> = emptyMap(),
|
||||
): ProcessExecutionResult {
|
||||
if (context != null) {
|
||||
gitExecDirectory(binary)
|
||||
return NativeGitBridge.runGitMain(binary, workingDir, arguments, gitEnvironment(binary, workingDir, environment))
|
||||
val startedAt = System.nanoTime()
|
||||
val execStartedAt = System.nanoTime()
|
||||
val gitExecPath = gitExecDirectory(binary)
|
||||
val execDirectoryMs = elapsedMillisSince(execStartedAt)
|
||||
val fullEnvironment = gitEnvironment(binary, workingDir, environment, gitExecPath)
|
||||
AppLog.d(
|
||||
"GitProcess",
|
||||
"runGit start cwd=${workingDir.absolutePath} argv=${formatGitArgv(arguments)} " +
|
||||
"extraEnvKeys=${environment.keys.sorted()} execDirectoryMs=$execDirectoryMs",
|
||||
)
|
||||
val result = if (context != null) {
|
||||
NativeGitBridge.runGitMain(binary, workingDir, arguments, fullEnvironment)
|
||||
} else {
|
||||
runProcess(binary, workingDir, arguments, fullEnvironment)
|
||||
}
|
||||
return runProcess(binary, workingDir, arguments, environment)
|
||||
AppLog.d(
|
||||
"GitProcess",
|
||||
"runGit finish exit=${result.exitCode} durationMs=${elapsedMillisSince(startedAt)} " +
|
||||
"output=${formatOutputPreview(result.outputLines)}",
|
||||
)
|
||||
return result
|
||||
}
|
||||
|
||||
fun runShellProcess(binary: File, workingDir: File, arguments: List<String>): ProcessExecutionResult {
|
||||
@@ -84,15 +100,14 @@ internal class GitProcessRunner(
|
||||
binary: File,
|
||||
workingDir: File,
|
||||
arguments: List<String>,
|
||||
extraEnvironment: Map<String, String> = emptyMap(),
|
||||
environment: Map<String, String>,
|
||||
): ProcessExecutionResult {
|
||||
return try {
|
||||
val gitExecPath = gitExecDirectory(binary)
|
||||
val process = ProcessBuilder(listOf(binary.absolutePath) + arguments)
|
||||
.directory(workingDir)
|
||||
.redirectErrorStream(true)
|
||||
.apply {
|
||||
environment().putAll(gitEnvironment(binary, workingDir, extraEnvironment, gitExecPath))
|
||||
environment().putAll(environment)
|
||||
}
|
||||
.start()
|
||||
|
||||
@@ -192,6 +207,25 @@ internal class GitProcessRunner(
|
||||
}
|
||||
alias.setExecutable(true, false)
|
||||
}
|
||||
|
||||
private fun formatGitArgv(arguments: List<String>): String =
|
||||
(listOf("git") + arguments).joinToString(" ") { argument ->
|
||||
if (argument.any { it.isWhitespace() || it == '"' || it == '\'' }) {
|
||||
"'" + argument.replace("'", "'\\''") + "'"
|
||||
} else {
|
||||
argument
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatOutputPreview(lines: List<String>): String {
|
||||
if (lines.isEmpty()) return "[]"
|
||||
val preview = lines
|
||||
.take(8)
|
||||
.joinToString(" | ")
|
||||
.take(1_000)
|
||||
val suffix = if (lines.size > 8) " ... (${lines.size} lines)" else " (${lines.size} lines)"
|
||||
return "[$preview]$suffix"
|
||||
}
|
||||
}
|
||||
|
||||
internal data class ProcessExecutionResult(
|
||||
|
||||
Reference in New Issue
Block a user