1 //! This crate provides the [`Repository`] abstraction which serves as a hub into all the functionality of git.
3 //! It's powerful and won't sacrifice performance while still increasing convenience compared to using the sub-crates
4 //! individually. Sometimes it may hide complexity under the assumption that the performance difference doesn't matter
5 //! for all but the fewest tools out there, which would be using the underlying crates directly or file an issue.
7 //! # The prelude and extensions
9 //! With `use git_repository::prelude::*` you should be ready to go as it pulls in various extension traits to make functionality
10 //! available on objects that may use it.
12 //! The method signatures are still complex and may require various arguments for configuration and cache control.
14 //! Most extensions to existing objects provide an `obj_with_extension.attach(&repo).an_easier_version_of_a_method()` for simpler
17 //! ## ThreadSafe Mode
19 //! By default, the [`Repository`] isn't `Sync` and thus can't be used in certain contexts which require the `Sync` trait.
21 //! To help with this, convert it with [`.into_sync()`][Repository::into_sync()] into a [`ThreadSafeRepository`].
23 //! ## Object-Access Performance
25 //! Accessing objects quickly is the bread-and-butter of working with git, right after accessing references. Hence it's vital
26 //! to understand which cache levels exist and how to leverage them.
28 //! When accessing an object, the first cache that's queried is a memory-capped LRU object cache, mapping their id to data and kind.
29 //! It has to be specifically enabled a [`Repository`].
30 //! On miss, the object is looked up and if a pack is hit, there is a small fixed-size cache for delta-base objects.
32 //! In scenarios where the same objects are accessed multiple times, the object cache can be useful and is to be configured specifically
33 //! using the [`object_cache_size(…)`][crate::Repository::object_cache_size()] method.
35 //! Use the `cache-efficiency-debug` cargo feature to learn how efficient the cache actually is - it's easy to end up with lowered
36 //! performance if the cache is not hit in 50% of the time.
40 //! #### WorkingTree and WorkTree
42 //! When reading the documentation of the canonical gix-worktree program one gets the impression work tree and working tree are used
43 //! interchangeably. We use the term _work tree_ only and try to do so consistently as its shorter and assumed to be the same.
47 //! To make using _sub-crates_ easier these are re-exported into the root of this crate. Here we list how to access nested plumbing
48 //! crates which are otherwise harder to discover:
50 //! **`git_repository::`**
52 //! * [`pack`][odb::pack]
54 //! * [`transport`][protocol::transport]
55 //! * [`packetline`][protocol::transport::packetline]
60 feature
= "document-features",
61 cfg_attr(doc
, doc
= ::document_features
::document_features
!())
63 #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
64 #![deny(missing_docs, rust_2018_idioms, unsafe_code)]
66 // Re-exports to make this a potential one-stop shop crate avoiding people from having to reference various crates themselves.
67 // This also means that their major version changes affect our major version, but that's alright as we directly expose their
68 // APIs/instances anyway.
69 pub use gix_actor
as actor
;
70 pub use gix_attributes
as attrs
;
71 pub use gix_credentials
as credentials
;
72 pub use gix_date
as date
;
73 pub use gix_features
as features
;
74 use gix_features
::threading
::OwnShared
;
75 pub use gix_features
::{parallel, progress::Progress, threading}
;
76 pub use gix_glob
as glob
;
77 pub use gix_hash
as hash
;
79 pub use gix_index
as index
;
80 pub use gix_lock
as lock
;
81 pub use gix_object
as objs
;
82 pub use gix_object
::bstr
;
83 pub use gix_odb
as odb
;
84 pub use gix_prompt
as prompt
;
85 #[cfg(all(feature = "gix-protocol"))]
86 pub use gix_protocol
as protocol
;
87 pub use gix_ref
as refs
;
88 pub use gix_refspec
as refspec
;
89 pub use gix_sec
as sec
;
90 pub use gix_tempfile
as tempfile
;
91 pub use gix_traverse
as traverse
;
92 pub use gix_url
as url
;
95 pub use hash
::{oid, ObjectId}
;
102 pub use gix_features
::parallel
::reduce
::Finalize
;
103 pub use gix_odb
::{Find, FindExt, Header, HeaderExt, Write}
;
105 pub use crate::ext
::*;
111 /// The standard type for a store to handle git references.
112 pub type RefStore
= gix_ref
::file
::Store
;
113 /// A handle for finding objects in an object database, abstracting away caches for thread-local use.
114 pub type OdbHandle
= gix_odb
::Handle
;
115 /// A way to access git configuration
116 pub(crate) type Config
= OwnShared
<gix_config
::File
<'
static>>;
121 Commit
, Head
, Id
, Kind
, Object
, ObjectDetached
, Reference
, Remote
, Repository
, Tag
, ThreadSafeRepository
, Tree
,
137 #[cfg(feature = "progress-tree")]
138 pub use gix_features
::progress
::prodash
::tree
;
139 pub use gix_features
::progress
::*;
147 /// Determine how to do rename tracking.
148 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
150 /// Do not track renames at all, the fastest option.
154 /// Track renames and copies.
156 /// This is the most expensive option.
162 /// See [ThreadSafeRepository::discover()], but returns a [`Repository`] instead.
163 #[allow(clippy::result_large_err)]
164 pub fn discover(directory
: impl AsRef
<std
::path
::Path
>) -> Result
<Repository
, discover
::Error
> {
165 ThreadSafeRepository
::discover(directory
).map(Into
::into
)
168 /// See [ThreadSafeRepository::init()], but returns a [`Repository`] instead.
169 #[allow(clippy::result_large_err)]
170 pub fn init(directory
: impl AsRef
<std
::path
::Path
>) -> Result
<Repository
, init
::Error
> {
171 ThreadSafeRepository
::init(directory
, create
::Kind
::WithWorktree
, create
::Options
::default()).map(Into
::into
)
174 /// See [ThreadSafeRepository::init()], but returns a [`Repository`] instead.
175 #[allow(clippy::result_large_err)]
176 pub fn init_bare(directory
: impl AsRef
<std
::path
::Path
>) -> Result
<Repository
, init
::Error
> {
177 ThreadSafeRepository
::init(directory
, create
::Kind
::Bare
, create
::Options
::default()).map(Into
::into
)
180 /// Create a platform for configuring a bare clone from `url` to the local `path`, using default options for opening it (but
181 /// amended with using configuration from the git installation to ensure all authentication options are honored).
183 /// See [`clone::PrepareFetch::new()] for a function to take full control over all options.
184 #[allow(clippy::result_large_err)]
185 pub fn prepare_clone_bare
<Url
, E
>(
187 path
: impl AsRef
<std
::path
::Path
>,
188 ) -> Result
<clone
::PrepareFetch
, clone
::Error
>
190 Url
: std
::convert
::TryInto
<gix_url
::Url
, Error
= E
>,
191 gix_url
::parse
::Error
: From
<E
>,
193 clone
::PrepareFetch
::new(
197 create
::Options
::default(),
198 open_opts_with_git_binary_config(),
202 /// Create a platform for configuring a clone with main working tree from `url` to the local `path`, using default options for opening it
203 /// (but amended with using configuration from the git installation to ensure all authentication options are honored).
205 /// See [`clone::PrepareFetch::new()] for a function to take full control over all options.
206 #[allow(clippy::result_large_err)]
207 pub fn prepare_clone
<Url
, E
>(url
: Url
, path
: impl AsRef
<std
::path
::Path
>) -> Result
<clone
::PrepareFetch
, clone
::Error
>
209 Url
: std
::convert
::TryInto
<gix_url
::Url
, Error
= E
>,
210 gix_url
::parse
::Error
: From
<E
>,
212 clone
::PrepareFetch
::new(
215 create
::Kind
::WithWorktree
,
216 create
::Options
::default(),
217 open_opts_with_git_binary_config(),
221 fn open_opts_with_git_binary_config() -> open
::Options
{
222 use gix_sec
::trust
::DefaultForLevel
;
223 let mut opts
= open
::Options
::default_for_level(gix_sec
::Trust
::Full
);
224 opts
.permissions
.config
.git_binary
= true;
228 /// See [ThreadSafeRepository::open()], but returns a [`Repository`] instead.
229 #[allow(clippy::result_large_err)]
230 pub fn open(directory
: impl Into
<std
::path
::PathBuf
>) -> Result
<Repository
, open
::Error
> {
231 ThreadSafeRepository
::open(directory
).map(Into
::into
)
234 /// See [ThreadSafeRepository::open_opts()], but returns a [`Repository`] instead.
235 #[allow(clippy::result_large_err)]
236 pub fn open_opts(directory
: impl Into
<std
::path
::PathBuf
>, options
: open
::Options
) -> Result
<Repository
, open
::Error
> {
237 ThreadSafeRepository
::open_opts(directory
, options
).map(Into
::into
)
247 pub type Error
= gix_sec
::permission
::Error
<std
::path
::PathBuf
>;
252 pub mod permissions
{
253 pub use crate::repository
::permissions
::{Config, Environment}
;
255 pub use repository
::permissions
::Permissions
;
280 /// Not to be confused with 'status'.
282 /// Tell what operation is currently in progress.
283 #[derive(Debug, PartialEq, Eq)]
284 pub enum InProgress
{
285 /// A mailbox is being applied.
287 /// A rebase is happening while a mailbox is being applied.
290 /// A git bisect operation has not yet been concluded.
292 /// A cherry pick operation.
294 /// A cherry pick with multiple commits pending.
296 /// A merge operation.
298 /// A rebase operation.
300 /// An interactive rebase operation.
302 /// A revert operation.
304 /// A revert operation with multiple commits pending.