diff --git a/gitoxide-core/src/repository/revision/parse.rs b/gitoxide-core/src/repository/revision/parse.rs index ec66c1c626..bd0d89e91f 100644 --- a/gitoxide-core/src/repository/revision/parse.rs +++ b/gitoxide-core/src/repository/revision/parse.rs @@ -12,21 +12,34 @@ pub(crate) mod function { pub fn parse( mut repo: git::Repository, - spec: OsString, + specs: Vec, mut out: impl std::io::Write, Options { format }: Options, ) -> anyhow::Result<()> { repo.object_cache_size_if_unset(1024 * 1024); - let spec = git::path::os_str_into_bstr(&spec)?; - let spec = repo.rev_parse(spec)?.detach(); match format { OutputFormat::Human => { - writeln!(out, "{spec}")?; + for spec in specs { + let spec = git::path::os_str_into_bstr(&spec)?; + let spec = repo.rev_parse(spec)?.detach(); + writeln!(out, "{spec}")?; + } } #[cfg(feature = "serde1")] OutputFormat::Json => { - serde_json::to_writer_pretty(&mut out, &spec)?; + serde_json::to_writer_pretty( + &mut out, + &specs + .into_iter() + .map(|spec| { + git::path::os_str_into_bstr(&spec) + .map_err(anyhow::Error::from) + .and_then(|spec| repo.rev_parse(spec).map_err(Into::into)) + .map(|spec| spec.detach()) + }) + .collect::, _>>()?, + )?; } } Ok(()) diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index cacd7cf0e6..3c42b2b642 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -524,7 +524,7 @@ pub fn main() -> Result<()> { None, move |_progress, out, _err| core::repository::revision::explain(spec, out), ), - revision::Subcommands::Parse { spec } => prepare_and_run( + revision::Subcommands::Parse { specs } => prepare_and_run( "revision-parse", verbose, progress, @@ -533,7 +533,7 @@ pub fn main() -> Result<()> { move |_progress, out, _err| { core::repository::revision::parse( repository()?, - spec, + specs, out, core::repository::revision::parse::Options { format }, ) diff --git a/src/plumbing/options.rs b/src/plumbing/options.rs index 5e78e731bb..a7b8ce7714 100644 --- a/src/plumbing/options.rs +++ b/src/plumbing/options.rs @@ -186,7 +186,10 @@ pub mod revision { Explain { spec: std::ffi::OsString }, /// Try to resolve the given revspec and print the object names. #[clap(visible_alias = "query")] - Parse { spec: std::ffi::OsString }, + Parse { + #[clap(min_values = 1)] + specs: Vec, + }, } }