Skip to content

Commit

Permalink
Skip common git flags in command trace log (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 authored Feb 6, 2025
1 parent 586186b commit 4092a12
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ 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 +287,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 4092a12

Please sign in to comment.