Skip to content

Commit

Permalink
Skip common git flags in command trace log
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Feb 6, 2025
1 parent 586186b commit 6d0d258
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use miette::Diagnostic;
use owo_colors::OwoColorize;
/// Adapt [axoprocess] to use [`tokio::process::Process`] instead of [`std::process::Command`].
use std::{
ffi::OsStr,
path::Path,
process::{CommandArgs, CommandEnvs, ExitStatus, Stdio},
};

use miette::Diagnostic;
use owo_colors::OwoColorize;
use thiserror::Error;
use tracing::trace;

use crate::git::GIT;

pub type Result<T> = std::result::Result<T, Error>;

/// An error from executing a Command
Expand Down Expand Up @@ -285,23 +286,36 @@ impl Cmd {
}
}

fn should_omit_arg(cmd: &OsStr, arg: &OsStr, val: Option<&&OsStr>) -> bool {
if GIT.as_ref().is_ok_and(|git| cmd == git) && arg == "-c" {
return val.is_some_and(|flag| {
let flag = flag.as_encoded_bytes();
flag.starts_with(b"core.useBuiltinFSMonitor") || flag.starts_with(b"protocol.version")
});
};
false
}

/// Simplified Command Debug output, with args truncated if they're too long.
impl std::fmt::Display for Cmd {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(cwd) = self.get_current_dir() {
write!(f, "cd {} && ", cwd.to_string_lossy())?;
}
let program = self.get_program();
let mut args = self.get_args();
if let Some(arg) = args.next() {
write!(f, "{} ", program.to_string_lossy().cyan())?;
if arg != program {
write!(f, "{}", arg.to_string_lossy().dimmed())?;
}
let mut args = self.get_args().peekable();

write!(f, "{}", program.to_string_lossy().cyan())?;
if args.peek().is_some_and(|arg| *arg == program) {
args.next(); // Skip the program if it's repeated
}

let mut len = 0;
for arg in args {
while let Some(arg) = args.next() {
if should_omit_arg(program, arg, args.peek()) {
args.next();
continue;
}
write!(f, " {}", arg.to_string_lossy().dimmed())?;
len += arg.len() + 1;
if len > 100 {
Expand Down

0 comments on commit 6d0d258

Please sign in to comment.