#![cfg_attr(
all(doc, feature = "document-features"),
doc = ::document_features::document_features!()
)]
#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg))]
#![cfg_attr(feature = "async-client", allow(unused))]
#![deny(rust_2018_idioms)]
#![forbid(unsafe_code)]
use std::str::FromStr;
use anyhow::bail;
#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
pub enum OutputFormat {
Human,
#[cfg(feature = "serde")]
Json,
}
impl OutputFormat {
pub fn variants() -> &'static [&'static str] {
&[
"human",
#[cfg(feature = "serde")]
"json",
]
}
}
impl FromStr for OutputFormat {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s_lc = s.to_ascii_lowercase();
Ok(match s_lc.as_str() {
"human" => OutputFormat::Human,
#[cfg(feature = "serde")]
"json" => OutputFormat::Json,
_ => return Err(format!("Invalid output format: '{s}'")),
})
}
}
pub mod commitgraph;
#[cfg(feature = "corpus")]
pub mod corpus;
pub mod net;
#[cfg(feature = "estimate-hours")]
pub mod hours;
pub mod index;
pub mod mailmap;
#[cfg(feature = "organize")]
pub mod organize;
pub mod pack;
#[cfg(feature = "query")]
pub mod query;
pub mod repository;
mod discover;
pub use discover::discover;
pub fn trust(paths: &[std::path::PathBuf], mut out: impl std::io::Write) -> anyhow::Result<()> {
let trust_width = "Reduced".len();
for path in paths {
let trust = gix::sec::Trust::from_path_ownership(path)?;
let trust = format!("{trust:?}");
writeln!(out, "{trust:<trust_width$} {}", path.display())?;
}
Ok(())
}
pub fn env(mut out: impl std::io::Write, format: OutputFormat) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("JSON output isn't supported");
}
let width = 15;
writeln!(
out,
"{field:>width$}: {}",
std::path::Path::new(gix::path::env::shell()).display(),
field = "shell",
)?;
writeln!(
out,
"{field:>width$}: {:?}",
gix::path::env::installation_config_prefix(),
field = "config prefix",
)?;
writeln!(
out,
"{field:>width$}: {:?}",
gix::path::env::installation_config(),
field = "config",
)?;
writeln!(
out,
"{field:>width$}: {}",
gix::path::env::exe_invocation().display(),
field = "git exe",
)?;
writeln!(
out,
"{field:>width$}: {:?}",
gix::path::env::system_prefix(),
field = "system prefix",
)?;
writeln!(
out,
"{field:>width$}: {:?}",
gix::path::env::core_dir(),
field = "core dir",
)?;
Ok(())
}
#[cfg(all(feature = "async-client", feature = "blocking-client"))]
compile_error!("Cannot set both 'blocking-client' and 'async-client' features as they are mutually exclusive");
fn is_dir_to_mode(is_dir: bool) -> gix::index::entry::Mode {
if is_dir {
gix::index::entry::Mode::DIR
} else {
gix::index::entry::Mode::FILE
}
}