gix/
attribute_stack.rs

1use std::ops::{Deref, DerefMut};
2
3use gix_fs::stack::ToNormalPathComponents;
4
5use crate::{types::AttributeStack, Repository};
6
7/// Lifecycle
8impl<'repo> AttributeStack<'repo> {
9    /// Create a new instance from a `repo` and the underlying pre-configured `stack`.
10    ///
11    /// Note that this type is typically created by [`Repository::attributes()`] or [`Repository::attributes_only()`].
12    pub fn new(stack: gix_worktree::Stack, repo: &'repo Repository) -> Self {
13        AttributeStack { repo, inner: stack }
14    }
15
16    /// Detach the repository and return the underlying plumbing datatype.
17    pub fn detach(self) -> gix_worktree::Stack {
18        self.inner
19    }
20}
21
22impl Deref for AttributeStack<'_> {
23    type Target = gix_worktree::Stack;
24
25    fn deref(&self) -> &Self::Target {
26        &self.inner
27    }
28}
29
30impl DerefMut for AttributeStack<'_> {
31    fn deref_mut(&mut self) -> &mut Self::Target {
32        &mut self.inner
33    }
34}
35
36/// Platform retrieval
37impl AttributeStack<'_> {
38    /// Append the `relative` path to the root directory of the cache and load all attribute or ignore files on the way as needed.
39    /// Use `mode` to specify what kind of item lives at `relative` - directories may match against rules specifically.
40    /// If `mode` is `None`, the item at `relative` is assumed to be a file.
41    ///
42    /// The returned platform may be used to access the actual attribute or ignore information.
43    #[doc(alias = "is_path_ignored", alias = "git2")]
44    pub fn at_path(
45        &mut self,
46        relative: impl AsRef<std::path::Path>,
47        mode: Option<gix_index::entry::Mode>,
48    ) -> std::io::Result<gix_worktree::stack::Platform<'_>> {
49        self.inner.at_path(relative.as_ref(), mode, &self.repo.objects)
50    }
51
52    /// Obtain a platform for attribute or ignore lookups from a repo-`relative` path, typically obtained from an index entry.
53    /// `mode` should reflect whether it's a directory or not, or left at `None` if unknown.
54    ///
55    /// If `relative` ends with `/` and `mode` is `None`, it is automatically assumed to be a directory.
56    pub fn at_entry(
57        &mut self,
58        relative: impl ToNormalPathComponents,
59        mode: Option<gix_index::entry::Mode>,
60    ) -> std::io::Result<gix_worktree::stack::Platform<'_>> {
61        self.inner.at_path(relative, mode, &self.repo.objects)
62    }
63}