Skip to content

Add gix::open_with_environment_overrides #2106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion gitoxide-core/src/repository/tag.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use gix::bstr::{BStr, BString, ByteSlice};

use crate::OutputFormat;

#[derive(Eq, PartialEq, PartialOrd, Ord)]
enum VersionPart {
String(BString),
Expand Down Expand Up @@ -41,7 +43,11 @@ impl Version {
}
}

pub fn list(repo: gix::Repository, out: &mut dyn std::io::Write) -> anyhow::Result<()> {
pub fn list(repo: gix::Repository, out: &mut dyn std::io::Write, format: OutputFormat) -> anyhow::Result<()> {
if format != OutputFormat::Human {
anyhow::bail!("JSON output isn't supported");
}

let platform = repo.references()?;

let mut tags: Vec<_> = platform
Expand Down
2 changes: 2 additions & 0 deletions gix/src/discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ impl ThreadSafeRepository {
/// Try to open a git repository directly from the environment.
/// If that fails, discover upwards from `directory` until one is found,
/// while applying discovery options from the environment.
///
/// For more, see [`ThreadSafeRepository::discover_with_environment_overrides_opts()`].
pub fn discover_with_environment_overrides(directory: impl AsRef<Path>) -> Result<Self, Error> {
Self::discover_with_environment_overrides_opts(directory, Default::default(), Default::default())
}
Expand Down
27 changes: 24 additions & 3 deletions gix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//!
//! By default, the [`Repository`] isn't `Sync` and thus can't be used in certain contexts which require the `Sync` trait.
//!
//! To help with this, convert it with [`.into_sync()`][Repository::into_sync()] into a [`ThreadSafeRepository`].
//! To help with this, convert it with [`Repository::into_sync()`] into a [`ThreadSafeRepository`].
//!
//! ### Object-Access Performance
//!
Expand All @@ -41,7 +41,7 @@
//! On miss, the object is looked up and if a pack is hit, there is a small fixed-size cache for delta-base objects.
//!
//! In scenarios where the same objects are accessed multiple times, the object cache can be useful and is to be configured specifically
//! using the [`object_cache_size(…)`][crate::Repository::object_cache_size()] method.
//! using the [`Repository::object_cache_size()`] method.
//!
//! Use the `cache-efficiency-debug` cargo feature to learn how efficient the cache actually is - it's easy to end up with lowered
//! performance if the cache is not hit in 50% of the time.
Expand Down Expand Up @@ -207,7 +207,10 @@ pub mod diff;
#[cfg(feature = "merge")]
pub mod merge;

/// See [`ThreadSafeRepository::discover()`], but returns a [`Repository`] instead.
/// Try to open a git repository in `directory` and search upwards through its parents until one is found,
/// using default trust options which matters in case the found repository isn't owned by the current user.
///
/// For details, see [`ThreadSafeRepository::discover()`].
///
/// # Note
///
Expand All @@ -222,6 +225,24 @@ pub fn discover(directory: impl AsRef<std::path::Path>) -> Result<Repository, di
ThreadSafeRepository::discover(directory).map(Into::into)
}

/// Try to discover a git repository directly from the environment.
///
/// For details, see [`ThreadSafeRepository::discover_with_environment_overrides_opts()`].
#[allow(clippy::result_large_err)]
pub fn discover_with_environment_overrides(
directory: impl AsRef<std::path::Path>,
) -> Result<Repository, discover::Error> {
ThreadSafeRepository::discover_with_environment_overrides(directory).map(Into::into)
}

/// Try to open a git repository directly from the environment.
///
/// See [`ThreadSafeRepository::open_with_environment_overrides()`].
#[allow(clippy::result_large_err)]
pub fn open_with_environment_overrides(directory: impl Into<std::path::PathBuf>) -> Result<Repository, open::Error> {
ThreadSafeRepository::open_with_environment_overrides(directory, Default::default()).map(Into::into)
}

/// See [`ThreadSafeRepository::init()`], but returns a [`Repository`] instead.
#[allow(clippy::result_large_err)]
pub fn init(directory: impl AsRef<std::path::Path>) -> Result<Repository, init::Error> {
Expand Down
4 changes: 3 additions & 1 deletion gix/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ pub struct Reference<'r> {

/// A thread-local handle to interact with a repository from a single thread.
///
/// It is `Send` but **not** `Sync` - for the latter you can convert it `to_sync()`.
/// It is `Send`, but **not** `Sync` - for the latter you can convert it using
/// [`Repository::into_sync()`].
///
/// Note that it clones itself so that it is empty, requiring the user to configure each clone separately, specifically
/// and explicitly. This is to have the fastest-possible default configuration available by default, but allow
/// those who experiment with workloads to get speed boosts of 2x or more.
Expand Down
2 changes: 1 addition & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
None,
move |_progress, out, _err| core::repository::tag::list(repository(Mode::Lenient)?, out),
move |_progress, out, _err| core::repository::tag::list(repository(Mode::Lenient)?, out, format),
),
},
Subcommands::Tree(cmd) => match cmd {
Expand Down
Loading