pub struct ThreadSafeRepository {
    pub refs: RefStore,
    pub objects: OwnShared<Store>,
    pub work_tree: Option<PathBuf>,
    pub common_dir: Option<PathBuf>,
    /* private fields */
}
Expand description

An instance with access to everything a git repository entails, best imagined as container implementing Sync + Send for most for system resources required to interact with a git repository which are loaded in once the instance is created.

Use this type to reference it in a threaded context for creation the creation of a thread-local Repositories.

Note that this type purposefully isn’t very useful until it is converted into a thread-local repository with to_thread_local(), it’s merely meant to be able to exist in a Sync context.

Note that it can also cheaply be cloned, and it will retain references to all contained resources.

Fields§

§refs: RefStore

A store for references to point at objects

§objects: OwnShared<Store>

A store for objects that contain data

§work_tree: Option<PathBuf>

The path to the worktree at which to find checked out files

§common_dir: Option<PathBuf>

The path to the common directory if this is a linked worktree repository or it is otherwise set.

Implementations§

source§

impl ThreadSafeRepository

source

pub fn to_thread_local(&self) -> Repository

Add thread-local state to an easy-to-use thread-local repository for the most convenient API.

source§

impl ThreadSafeRepository

source

pub fn path(&self) -> &Path

The path to the .git directory itself, or equivalent if this is a bare repository.

source

pub fn git_dir(&self) -> &Path

Return the path to the repository itself, containing objects, references, configuration, and more.

Synonymous to path().

source

pub fn work_dir(&self) -> Option<&Path>

Return the path to the working directory if this is not a bare repository.

source

pub fn objects_dir(&self) -> &Path

Return the path to the directory containing all objects.

source§

impl ThreadSafeRepository

source

pub fn open(path: impl Into<PathBuf>) -> Result<Self, Error>

Open a git repository at the given path, possibly expanding it to path/.git if path is a work tree dir.

source

pub fn open_opts( path: impl Into<PathBuf>, options: Options ) -> Result<Self, Error>

Open a git repository at the given path, possibly expanding it to path/.git if path is a work tree dir, and use options for fine-grained control.

Note that you should use crate::discover() if security should be adjusted by ownership.

Differences to git2::Repository::open_ext()

Whereas open_ext() is the jack-of-all-trades that can do anything depending on its options, gix will always differentiate between discovering git repositories by searching, and opening a well-known repository by work tree or .git repository.

Note that opening a repository for implementing custom hooks is also handle specifically in open_with_environment_overrides().

source

pub fn open_with_environment_overrides( fallback_directory: impl Into<PathBuf>, trust_map: Mapping<Options> ) -> Result<Self, Error>

Try to open a git repository in fallback_directory (can be worktree or .git directory) only if there is no override from of the gitdir using git environment variables.

Use the trust_map to apply options depending in the trust level for directory or the directory it’s overridden with. The .git directory whether given or computed is used for trust checks.

Note that this will read various GIT_* environment variables to check for overrides, and is probably most useful when implementing custom hooks.

source§

impl ThreadSafeRepository

source

pub fn init( directory: impl AsRef<Path>, kind: Kind, options: Options ) -> Result<Self, Error>

Create a repository with work-tree within directory, creating intermediate directories as needed.

Fails without action if there is already a .git repository inside of directory, but won’t mind if the directory otherwise is non-empty.

source

pub fn init_opts( directory: impl AsRef<Path>, kind: Kind, create_options: Options, open_options: Options ) -> Result<Self, Error>

Similar to init, but allows to determine how exactly to open the newly created repository.

Deviation

Instead of naming the default branch master, we name it main unless configured explicitly using the init.defaultBranch configuration key.

source§

impl ThreadSafeRepository

source

pub fn discover(directory: impl AsRef<Path>) -> Result<Self, Error>

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.

source

pub fn discover_opts( directory: impl AsRef<Path>, options: Options<'_>, trust_map: Mapping<Options> ) -> Result<Self, Error>

Try to open a git repository in directory and search upwards through its parents until one is found, while applying options. Then use the trust_map to determine which of our own repository options to use for instantiations.

Note that trust overrides in the trust_map are not effective here and we will always override it with the determined trust value. This is a precaution as the API user is unable to actually know if the directory that is discovered can indeed be trusted (or else they’d have to implement the discovery themselves and be sure that no attacker ever gets access to a directory structure. The cost of this is a permission check, which seems acceptable).

source

pub fn discover_with_environment_overrides( directory: impl AsRef<Path> ) -> Result<Self, Error>

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.

source

pub fn discover_with_environment_overrides_opts( directory: impl AsRef<Path>, options: Options<'_>, trust_map: Mapping<Options> ) -> Result<Self, Error>

Try to open a git repository directly from the environment, which reads GIT_DIR if it is set. If unset, discover upwards from directory until one is found, while applying options with overrides from the environment which includes:

  • GIT_DISCOVERY_ACROSS_FILESYSTEM
  • GIT_CEILING_DIRECTORIES

Finally, use the trust_map to determine which of our own repository options to use based on the trust level of the effective repository directory.

Trait Implementations§

source§

impl Clone for ThreadSafeRepository

source§

fn clone(&self) -> ThreadSafeRepository

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ThreadSafeRepository

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&ThreadSafeRepository> for Repository

source§

fn from(repo: &ThreadSafeRepository) -> Self

Converts to this type from the input type.
source§

impl From<Repository> for ThreadSafeRepository

source§

fn from(r: Repository) -> Self

Converts to this type from the input type.
source§

impl From<ThreadSafeRepository> for Repository

source§

fn from(repo: ThreadSafeRepository) -> Self

Converts to this type from the input type.
source§

impl PartialEq<ThreadSafeRepository> for ThreadSafeRepository

source§

fn eq(&self, other: &ThreadSafeRepository) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.