Skip to content

Commit 84b5448

Browse files
committed
support for parsing multiple specs in one invocation (#427)
1 parent df83e23 commit 84b5448

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

Diff for: gitoxide-core/src/repository/revision/parse.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,34 @@ pub(crate) mod function {
1212

1313
pub fn parse(
1414
mut repo: git::Repository,
15-
spec: OsString,
15+
specs: Vec<OsString>,
1616
mut out: impl std::io::Write,
1717
Options { format }: Options,
1818
) -> anyhow::Result<()> {
1919
repo.object_cache_size_if_unset(1024 * 1024);
20-
let spec = git::path::os_str_into_bstr(&spec)?;
21-
let spec = repo.rev_parse(spec)?.detach();
2220

2321
match format {
2422
OutputFormat::Human => {
25-
writeln!(out, "{spec}")?;
23+
for spec in specs {
24+
let spec = git::path::os_str_into_bstr(&spec)?;
25+
let spec = repo.rev_parse(spec)?.detach();
26+
writeln!(out, "{spec}")?;
27+
}
2628
}
2729
#[cfg(feature = "serde1")]
2830
OutputFormat::Json => {
29-
serde_json::to_writer_pretty(&mut out, &spec)?;
31+
serde_json::to_writer_pretty(
32+
&mut out,
33+
&specs
34+
.into_iter()
35+
.map(|spec| {
36+
git::path::os_str_into_bstr(&spec)
37+
.map_err(anyhow::Error::from)
38+
.and_then(|spec| repo.rev_parse(spec).map_err(Into::into))
39+
.map(|spec| spec.detach())
40+
})
41+
.collect::<Result<Vec<_>, _>>()?,
42+
)?;
3043
}
3144
}
3245
Ok(())

Diff for: src/plumbing/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ pub fn main() -> Result<()> {
524524
None,
525525
move |_progress, out, _err| core::repository::revision::explain(spec, out),
526526
),
527-
revision::Subcommands::Parse { spec } => prepare_and_run(
527+
revision::Subcommands::Parse { specs } => prepare_and_run(
528528
"revision-parse",
529529
verbose,
530530
progress,
@@ -533,7 +533,7 @@ pub fn main() -> Result<()> {
533533
move |_progress, out, _err| {
534534
core::repository::revision::parse(
535535
repository()?,
536-
spec,
536+
specs,
537537
out,
538538
core::repository::revision::parse::Options { format },
539539
)

Diff for: src/plumbing/options.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ pub mod revision {
186186
Explain { spec: std::ffi::OsString },
187187
/// Try to resolve the given revspec and print the object names.
188188
#[clap(visible_alias = "query")]
189-
Parse { spec: std::ffi::OsString },
189+
Parse {
190+
#[clap(min_values = 1)]
191+
specs: Vec<std::ffi::OsString>,
192+
},
190193
}
191194
}
192195

0 commit comments

Comments
 (0)