From fa1287f2e218a0959700cb858b41465f315db9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Fri, 22 Aug 2025 14:21:28 +0200 Subject: [PATCH 1/2] feat: Add `gix::discover_with_environment_overrides()` --- gix/src/discover.rs | 4 +++- gix/src/lib.rs | 27 ++++++++++++++++++++++++--- gix/src/types.rs | 4 +++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/gix/src/discover.rs b/gix/src/discover.rs index 32fbe2e044c..e4b6c7a0061 100644 --- a/gix/src/discover.rs +++ b/gix/src/discover.rs @@ -3,7 +3,7 @@ use std::path::Path; pub use gix_discover::*; -use crate::{bstr::BString, ThreadSafeRepository}; +use crate::{bstr::BString, Repository, ThreadSafeRepository}; /// The error returned by [`crate::discover()`]. #[derive(Debug, thiserror::Error)] @@ -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) -> Result { Self::discover_with_environment_overrides_opts(directory, Default::default(), Default::default()) } diff --git a/gix/src/lib.rs b/gix/src/lib.rs index 6c8d06f91dd..93292b9a92b 100644 --- a/gix/src/lib.rs +++ b/gix/src/lib.rs @@ -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 //! @@ -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. @@ -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 /// @@ -222,6 +225,24 @@ pub fn discover(directory: impl AsRef) -> Result, +) -> Result { + 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) -> Result { + 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) -> Result { diff --git a/gix/src/types.rs b/gix/src/types.rs index 4ada3d5c72d..3019863fa60 100644 --- a/gix/src/types.rs +++ b/gix/src/types.rs @@ -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. From fb2766bd006ba1a276dfd5554cf0cdc3b7043ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Mon, 18 Aug 2025 11:26:30 +0200 Subject: [PATCH 2/2] Fail `gix tag list` when JSON is requested --- gitoxide-core/src/repository/tag.rs | 8 +++++++- gix/src/discover.rs | 2 +- src/plumbing/main.rs | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gitoxide-core/src/repository/tag.rs b/gitoxide-core/src/repository/tag.rs index 24f1572f1ef..5c41d05f1bf 100644 --- a/gitoxide-core/src/repository/tag.rs +++ b/gitoxide-core/src/repository/tag.rs @@ -1,5 +1,7 @@ use gix::bstr::{BStr, BString, ByteSlice}; +use crate::OutputFormat; + #[derive(Eq, PartialEq, PartialOrd, Ord)] enum VersionPart { String(BString), @@ -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 diff --git a/gix/src/discover.rs b/gix/src/discover.rs index e4b6c7a0061..07684d8ac78 100644 --- a/gix/src/discover.rs +++ b/gix/src/discover.rs @@ -3,7 +3,7 @@ use std::path::Path; pub use gix_discover::*; -use crate::{bstr::BString, Repository, ThreadSafeRepository}; +use crate::{bstr::BString, ThreadSafeRepository}; /// The error returned by [`crate::discover()`]. #[derive(Debug, thiserror::Error)] diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 12f2e5e7733..24148035056 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -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 {