use std::io;
use std::path::Path;
use std::process::Command;
use std::process::Output;
use super::constants::GIT_BINARY;
use super::constants::GIT_NO_OPTIONAL_LOCKS_ARG;
pub(super) fn git_command(repo_root: &Path) -> Command {
let mut cmd = Command::new(GIT_BINARY);
cmd.arg(GIT_NO_OPTIONAL_LOCKS_ARG).current_dir(repo_root);
cmd
}
pub(super) fn git_output_logged<const N: usize>(
repo_root: &Path,
op: &str,
args: [&str; N],
) -> io::Result<Output> {
let started = std::time::Instant::now();
let output = git_command(repo_root).args(args).output();
let status = output
.as_ref()
.ok()
.and_then(|out| out.status.code())
.map_or_else(|| "signal".to_string(), |code| code.to_string());
tracing::info!(
elapsed_ms = tui_pane::perf_log_ms(started.elapsed().as_millis()),
repo_root = %repo_root.display(),
op,
status,
"git_info_get_call"
);
output
}