History

Merge pull request #2106 from cruessler/add-open-with-environment-overrides

Add `gix::open_with_environment_overrides`

Sebastian Thiel committed 1 year ago

Commit c1491162 parents a4b0d2c fb2766b5 files · +37 −6Browse files

Unified · Split

5 files
  1. gitoxide-core/src/repository/tag.rs +7 −1
  2. gix/src/discover.rs +2 −0
  3. gix/src/lib.rs +24 −3
  4. gix/src/types.rs +3 −1
  5. src/plumbing/main.rs +1 −1
gitoxide-core/src/repository/tag.rs+7−1
@@ -1,5 +1,7 @@
1use gix::bstr::{BStr, BString, ByteSlice};1use gix::bstr::{BStr, BString, ByteSlice};
2 2
3use crate::OutputFormat;
4
3#[derive(Eq, PartialEq, PartialOrd, Ord)]5#[derive(Eq, PartialEq, PartialOrd, Ord)]
4enum VersionPart {6enum VersionPart {
5 String(BString),7 String(BString),
@@ -41,7 +43,11 @@ impl Version { · 35 unmodified lines
41 }43 }
42}44}
43 45
44pub fn list(repo: gix::Repository, out: &mut dyn std::io::Write) -> anyhow::Result<()> {46pub fn list(repo: gix::Repository, out: &mut dyn std::io::Write, format: OutputFormat) -> anyhow::Result<()> {
47 if format != OutputFormat::Human {
48 anyhow::bail!("JSON output isn't supported");
49 }
50
45 let platform = repo.references()?;51 let platform = repo.references()?;
46 52
47 let mut tags: Vec<_> = platform53 let mut tags: Vec<_> = platform
gix/src/discover.rs+2−0
@@ -49,6 +49,8 @@ impl ThreadSafeRepository { · 48 unmodified lines
49 /// Try to open a git repository directly from the environment.49 /// Try to open a git repository directly from the environment.
50 /// If that fails, discover upwards from `directory` until one is found,50 /// If that fails, discover upwards from `directory` until one is found,
51 /// while applying discovery options from the environment.51 /// while applying discovery options from the environment.
52 ///
53 /// For more, see [`ThreadSafeRepository::discover_with_environment_overrides_opts()`].
52 pub fn discover_with_environment_overrides(directory: impl AsRef<Path>) -> Result<Self, Error> {54 pub fn discover_with_environment_overrides(directory: impl AsRef<Path>) -> Result<Self, Error> {
53 Self::discover_with_environment_overrides_opts(directory, Default::default(), Default::default())55 Self::discover_with_environment_overrides_opts(directory, Default::default(), Default::default())
54 }56 }
gix/src/lib.rs+24−3
@@ -29,7 +29,7 @@ · 28 unmodified lines
29//!29//!
30//! By default, the [`Repository`] isn't `Sync` and thus can't be used in certain contexts which require the `Sync` trait.30//! By default, the [`Repository`] isn't `Sync` and thus can't be used in certain contexts which require the `Sync` trait.
31//!31//!
32//! To help with this, convert it with [`.into_sync()`][Repository::into_sync()] into a [`ThreadSafeRepository`].32//! To help with this, convert it with [`Repository::into_sync()`] into a [`ThreadSafeRepository`].
33//!33//!
34//! ### Object-Access Performance34//! ### Object-Access Performance
35//!35//!
@@ -41,7 +41,7 @@ · 5 unmodified lines
41//! On miss, the object is looked up and if a pack is hit, there is a small fixed-size cache for delta-base objects.41//! On miss, the object is looked up and if a pack is hit, there is a small fixed-size cache for delta-base objects.
42//!42//!
43//! In scenarios where the same objects are accessed multiple times, the object cache can be useful and is to be configured specifically43//! In scenarios where the same objects are accessed multiple times, the object cache can be useful and is to be configured specifically
44//! using the [`object_cache_size(…)`][crate::Repository::object_cache_size()] method.44//! using the [`Repository::object_cache_size()`] method.
45//!45//!
46//! Use the `cache-efficiency-debug` cargo feature to learn how efficient the cache actually is - it's easy to end up with lowered46//! Use the `cache-efficiency-debug` cargo feature to learn how efficient the cache actually is - it's easy to end up with lowered
47//! performance if the cache is not hit in 50% of the time.47//! performance if the cache is not hit in 50% of the time.
@@ -207,7 +207,10 @@ pub mod diff; · 159 unmodified lines
207#[cfg(feature = "merge")]207#[cfg(feature = "merge")]
208pub mod merge;208pub mod merge;
209 209
210/// See [`ThreadSafeRepository::discover()`], but returns a [`Repository`] instead.210/// Try to open a git repository in `directory` and search upwards through its parents until one is found,
211/// using default trust options which matters in case the found repository isn't owned by the current user.
212///
213/// For details, see [`ThreadSafeRepository::discover()`].
211///214///
212/// # Note215/// # Note
213///216///
@@ -222,6 +225,24 @@ pub fn discover(directory: impl AsRef<std::path::Path>) -> Result<Repository, di · 8 unmodified lines
222 ThreadSafeRepository::discover(directory).map(Into::into)225 ThreadSafeRepository::discover(directory).map(Into::into)
223}226}
224 227
228/// Try to discover a git repository directly from the environment.
229///
230/// For details, see [`ThreadSafeRepository::discover_with_environment_overrides_opts()`].
231#[allow(clippy::result_large_err)]
232pub fn discover_with_environment_overrides(
233 directory: impl AsRef<std::path::Path>,
234) -> Result<Repository, discover::Error> {
235 ThreadSafeRepository::discover_with_environment_overrides(directory).map(Into::into)
236}
237
238/// Try to open a git repository directly from the environment.
239///
240/// See [`ThreadSafeRepository::open_with_environment_overrides()`].
241#[allow(clippy::result_large_err)]
242pub fn open_with_environment_overrides(directory: impl Into<std::path::PathBuf>) -> Result<Repository, open::Error> {
243 ThreadSafeRepository::open_with_environment_overrides(directory, Default::default()).map(Into::into)
244}
245
225/// See [`ThreadSafeRepository::init()`], but returns a [`Repository`] instead.246/// See [`ThreadSafeRepository::init()`], but returns a [`Repository`] instead.
226#[allow(clippy::result_large_err)]247#[allow(clippy::result_large_err)]
227pub fn init(directory: impl AsRef<std::path::Path>) -> Result<Repository, init::Error> {248pub fn init(directory: impl AsRef<std::path::Path>) -> Result<Repository, init::Error> {
gix/src/types.rs+3−1
@@ -145,7 +145,9 @@ pub struct Reference<'r> { · 144 unmodified lines
145 145
146/// A thread-local handle to interact with a repository from a single thread.146/// A thread-local handle to interact with a repository from a single thread.
147///147///
148/// It is `Send` but **not** `Sync` - for the latter you can convert it `to_sync()`.148/// It is `Send`, but **not** `Sync` - for the latter you can convert it using
149/// [`Repository::into_sync()`].
150///
149/// Note that it clones itself so that it is empty, requiring the user to configure each clone separately, specifically151/// Note that it clones itself so that it is empty, requiring the user to configure each clone separately, specifically
150/// and explicitly. This is to have the fastest-possible default configuration available by default, but allow152/// and explicitly. This is to have the fastest-possible default configuration available by default, but allow
151/// those who experiment with workloads to get speed boosts of 2x or more.153/// those who experiment with workloads to get speed boosts of 2x or more.
src/plumbing/main.rs+1−1
@@ -1312,7 +1312,7 @@ pub fn main() -> Result<()> { · 1311 unmodified lines
1312 progress,1312 progress,
1313 progress_keep_open,1313 progress_keep_open,
1314 None,1314 None,
1315 move |_progress, out, _err| core::repository::tag::list(repository(Mode::Lenient)?, out),1315 move |_progress, out, _err| core::repository::tag::list(repository(Mode::Lenient)?, out, format),
1316 ),1316 ),
1317 },1317 },
1318 Subcommands::Tree(cmd) => match cmd {1318 Subcommands::Tree(cmd) => match cmd {