diff --git a/Cargo.toml b/Cargo.toml index 6143696..b55a52d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "glc" version = "0.1.0" +description = "Find the latest commit for each entry in a git tree" authors = ["tjh "] license = "MIT" edition = "2024" diff --git a/src/cli.rs b/src/cli.rs index 3bf62f6..66f099c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -6,6 +6,7 @@ pub fn parse() -> Arguments { } #[derive(Parser)] +#[command(about, author, version)] pub struct Arguments { /// Commit, tag, or branch to start scanning from. #[arg(long, value_name = "from-revspec", default_value = "HEAD")] @@ -15,13 +16,13 @@ pub struct Arguments { #[arg(long, value_name = "to-revspec")] pub to: Option, - /// Convert timestamps to UTC. + /// Preserve timezone in timestamp output. #[arg{long}] - pub utc: bool, + pub preserve_tz: bool, /// Path to the git repository. - #[arg(value_hint = ValueHint::DirPath, default_value = ".")] - pub repository_path: PathBuf, + #[arg(long, short = 'R', value_hint = ValueHint::DirPath, default_value = ".")] + pub repository: PathBuf, pub subtree: Option, } diff --git a/src/main.rs b/src/main.rs index f1c2c2a..a31da37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ mod cli; fn main() -> anyhow::Result<()> { let arguments = cli::parse(); - let repository = gix::open(arguments.repository_path)?; + let repository = gix::open(arguments.repository)?; let mut current_commit = repository.resolve_revspec(&arguments.from)?; let mut current_tree = current_commit @@ -54,9 +54,10 @@ fn main() -> anyhow::Result<()> { let output = |filename: &BStr, commit: &Commit| -> anyhow::Result<()> { let id = commit.id; - let ts = format_ts(&commit.time()?, arguments.utc)?; + let ts = format_ts(&commit.time()?, arguments.preserve_tz)?; let message = commit.message()?.summary(); - println!("{filename: anyhow::Result<()> { current_commit = parent_commit; } + if !interested.is_empty() { + for entry in interested.drain() { + println!("{:?}", entry.as_bstr()); + } + } + Ok(()) } @@ -216,7 +223,7 @@ impl<'a> Change<'a> { } } -fn format_ts(time: &Time, utc: bool) -> anyhow::Result { +fn format_ts(time: &Time, preserve_tz: bool) -> anyhow::Result { use time::OffsetDateTime; use time::UtcOffset; use time::format_description::well_known::Rfc3339; @@ -224,9 +231,9 @@ fn format_ts(time: &Time, utc: bool) -> anyhow::Result { let odt = OffsetDateTime::from_unix_timestamp(time.seconds)? .to_offset(UtcOffset::from_whole_seconds(time.offset)?); - let formatted = match utc { - true => odt.to_utc().format(&Rfc3339)?, - false => odt.format(&Rfc3339)?, + let formatted = match preserve_tz { + true => odt.format(&Rfc3339)?, + false => odt.to_utc().format(&Rfc3339)?, }; Ok(formatted)