-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rough but working version of
rev-parse
(#427)
- Loading branch information
Showing
6 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
mod explain; | ||
pub use explain::explain; | ||
|
||
pub mod parse; | ||
pub use parse::function::parse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::OutputFormat; | ||
|
||
pub struct Options { | ||
pub format: OutputFormat, | ||
} | ||
|
||
pub(crate) mod function { | ||
use super::Options; | ||
use crate::OutputFormat; | ||
use git_repository as git; | ||
use std::ffi::OsString; | ||
|
||
pub fn parse( | ||
repo: git::Repository, | ||
spec: OsString, | ||
mut out: impl std::io::Write, | ||
Options { format }: Options, | ||
) -> anyhow::Result<()> { | ||
let spec = git::path::os_str_into_bstr(&spec)?; | ||
let spec = git::RevSpec::from_bstr(spec.as_ref(), &repo)?.detach(); | ||
|
||
match format { | ||
OutputFormat::Human => { | ||
if let Some((kind, from, to)) = spec.range() { | ||
writeln!(&mut out, "{}", from)?; | ||
writeln!( | ||
&mut out, | ||
"{}{}", | ||
matches!(kind, git::revision::spec::Kind::Range) | ||
.then(|| "^") | ||
.unwrap_or_default(), | ||
to | ||
)?; | ||
if matches!(kind, git::revision::spec::Kind::Range) { | ||
writeln!(out, "^TBD: compute and display merge base hash")?; | ||
} | ||
} else if let Some(rev) = spec.single() { | ||
writeln!(&mut out, "{}", rev)?; | ||
} | ||
} | ||
#[cfg(feature = "serde1")] | ||
OutputFormat::Json => { | ||
serde_json::to_writer_pretty(&mut out, &spec)?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters