Thanks to visit codestin.com
Credit goes to docs.rs

Skip to main content

gix/
types.rs

1use std::{cell::RefCell, path::PathBuf};
2
3use gix_hash::ObjectId;
4
5use crate::{head, remote};
6
7/// A worktree checkout containing the files of the repository in consumable form.
8#[derive(Debug, Clone)]
9pub struct Worktree<'repo> {
10    pub(crate) parent: &'repo Repository,
11    /// The root path of the checkout.
12    pub(crate) path: &'repo std::path::Path,
13}
14
15/// The head reference, as created from looking at `.git/HEAD`, able to represent all of its possible states.
16///
17/// Note that like [`Reference`], this type's data is snapshot of persisted state on disk.
18#[derive(Clone)]
19pub struct Head<'repo> {
20    /// One of various possible states for the HEAD reference
21    pub kind: head::Kind,
22    /// The owning repository.
23    pub repo: &'repo Repository,
24}
25
26/// An [`ObjectId`] with access to a repository.
27#[derive(Clone, Copy)]
28pub struct Id<'r> {
29    /// The actual object id
30    pub(crate) inner: ObjectId,
31    /// The owning repository.
32    pub repo: &'r Repository,
33}
34
35/// A decoded object with a reference to its owning repository.
36#[derive(Clone)]
37pub struct Object<'repo> {
38    /// The id of the object
39    pub id: ObjectId,
40    /// The kind of the object
41    pub kind: gix_object::Kind,
42    /// The fully decoded object data
43    pub data: Vec<u8>,
44    /// The owning repository.
45    pub repo: &'repo Repository,
46}
47
48impl Drop for Object<'_> {
49    fn drop(&mut self) {
50        self.repo.reuse_buffer(&mut self.data);
51    }
52}
53
54/// A blob along with access to its owning repository.
55#[derive(Clone)]
56pub struct Blob<'repo> {
57    /// The id of the tree
58    pub id: ObjectId,
59    /// The blob's data.
60    pub data: Vec<u8>,
61    /// The owning repository.
62    pub repo: &'repo Repository,
63}
64
65impl Drop for Blob<'_> {
66    fn drop(&mut self) {
67        self.repo.reuse_buffer(&mut self.data);
68    }
69}
70
71/// A decoded tree object with access to its owning repository.
72#[derive(Clone)]
73pub struct Tree<'repo> {
74    /// Thek[ id of the tree
75    pub id: ObjectId,
76    /// The fully decoded tree data
77    pub data: Vec<u8>,
78    /// The owning repository.
79    pub repo: &'repo Repository,
80}
81
82impl Drop for Tree<'_> {
83    fn drop(&mut self) {
84        self.repo.reuse_buffer(&mut self.data);
85    }
86}
87
88/// A decoded tag object with access to its owning repository.
89#[derive(Clone)]
90pub struct Tag<'repo> {
91    /// The id of the tree
92    pub id: ObjectId,
93    /// The fully decoded tag data
94    pub data: Vec<u8>,
95    /// The owning repository.
96    pub repo: &'repo Repository,
97}
98
99impl Drop for Tag<'_> {
100    fn drop(&mut self) {
101        self.repo.reuse_buffer(&mut self.data);
102    }
103}
104
105/// A decoded commit object with access to its owning repository.
106#[derive(Clone)]
107pub struct Commit<'repo> {
108    /// The id of the commit
109    pub id: ObjectId,
110    /// The fully decoded commit data
111    pub data: Vec<u8>,
112    /// The owning repository.
113    pub repo: &'repo Repository,
114}
115
116impl Drop for Commit<'_> {
117    fn drop(&mut self) {
118        self.repo.reuse_buffer(&mut self.data);
119    }
120}
121
122/// A detached, self-contained object, without access to its source repository.
123///
124/// Use it if an `ObjectRef` should be sent over thread boundaries or stored in collections.
125#[derive(Clone)]
126pub struct ObjectDetached {
127    /// The id of the object
128    pub id: ObjectId,
129    /// The kind of the object
130    pub kind: gix_object::Kind,
131    /// The fully decoded object data
132    pub data: Vec<u8>,
133}
134
135/// A reference that points to an object or reference, with access to its source repository.
136///
137/// Note that these are snapshots and won't recognize if they are stale.
138#[derive(Clone)]
139pub struct Reference<'r> {
140    /// The actual reference data
141    pub inner: gix_ref::Reference,
142    /// The owning repository.
143    pub repo: &'r Repository,
144}
145
146/// A thread-local handle to interact with a repository from a single thread.
147///
148/// It is `Send`, but **not** `Sync` - for the latter you can convert it using
149/// [`Repository::into_sync()`].
150///
151/// Note that it clones itself so that it is empty, requiring the user to configure each clone separately, specifically
152/// and explicitly. This is to have the fastest-possible default configuration available by default, but allow
153/// those who experiment with workloads to get speed boosts of 2x or more.
154///
155/// ### `Send` only with `parallel` feature
156///
157/// When built with `default-features = false`, this type is **not** `Send`.
158/// The minimal feature set to activate `Send` is `features = ["parallel"]`.
159pub struct Repository {
160    /// A ref store with shared ownership (or the equivalent of it).
161    pub refs: crate::RefStore,
162    /// A way to access objects.
163    pub objects: crate::OdbHandle,
164
165    pub(crate) work_tree: Option<PathBuf>,
166    /// The path to the resolved common directory if this is a linked worktree repository or it is otherwise set.
167    pub(crate) common_dir: Option<PathBuf>,
168    /// A free-list of reusable object backing buffers
169    pub(crate) bufs: Option<RefCell<Vec<Vec<u8>>>>,
170    /// A pre-assembled selection of often-accessed configuration values for quick access.
171    pub(crate) config: crate::config::Cache,
172    /// the options obtained when instantiating this repository.
173    ///
174    /// Particularly useful when following linked worktrees and instantiating new equally configured worktree repositories.
175    pub(crate) options: crate::open::Options,
176    #[cfg(feature = "index")]
177    pub(crate) index: crate::worktree::IndexStorage,
178    #[cfg(feature = "attributes")]
179    pub(crate) modules: crate::submodule::ModulesFileStorage,
180    pub(crate) shallow_commits: crate::shallow::CommitsStorage,
181}
182
183/// An instance with access to everything a git repository entails, best imagined as container implementing `Sync + Send` for _most_
184/// for system resources required to interact with a `git` repository which are loaded in once the instance is created.
185///
186/// Use this type to reference it in a threaded context for creation the creation of a thread-local [`Repositories`][Repository].
187///
188/// Note that this type purposefully isn't very useful until it is converted into a thread-local repository with `to_thread_local()`,
189/// it's merely meant to be able to exist in a `Sync` context.
190///
191/// Note that it can also cheaply be cloned, and it will retain references to all contained resources.
192///
193/// ### `Send` only with `parallel` feature
194///
195/// When built with `default-features = false`, this type is **not** `Send`.
196/// The minimal feature set to activate `Send` is `features = ["parallel"]`.
197#[derive(Clone)]
198pub struct ThreadSafeRepository {
199    /// A store for references to point at objects
200    pub refs: crate::RefStore,
201    /// A store for objects that contain data
202    pub objects: gix_features::threading::OwnShared<gix_odb::Store>,
203    /// The path to the worktree at which to find checked out files
204    pub work_tree: Option<PathBuf>,
205    /// The path to the common directory if this is a linked worktree repository or it is otherwise set.
206    pub common_dir: Option<PathBuf>,
207    pub(crate) config: crate::config::Cache,
208    /// options obtained when instantiating this repository for use when following linked worktrees.
209    pub(crate) linked_worktree_options: crate::open::Options,
210    /// The index of this instances worktree.
211    #[cfg(feature = "index")]
212    pub(crate) index: crate::worktree::IndexStorage,
213    #[cfg(feature = "attributes")]
214    pub(crate) modules: crate::submodule::ModulesFileStorage,
215    pub(crate) shallow_commits: crate::shallow::CommitsStorage,
216}
217
218/// A remote which represents a way to interact with hosts for remote clones of the parent repository.
219#[derive(Debug, Clone, PartialEq)]
220pub struct Remote<'repo> {
221    /// The remotes symbolic name, only present if persisted in git configuration files.
222    pub(crate) name: Option<remote::Name<'static>>,
223    /// The url of the host to talk to, after application of replacements. If it is unset, the `push_url` must be set.
224    /// and fetches aren't possible.
225    pub(crate) url: Option<gix_url::Url>,
226    /// The rewritten `url`, if it was rewritten.
227    pub(crate) url_alias: Option<gix_url::Url>,
228    /// The url to use for pushing specifically.
229    pub(crate) push_url: Option<gix_url::Url>,
230    /// The rewritten `push_url`, if it was rewritten.
231    pub(crate) push_url_alias: Option<gix_url::Url>,
232    /// Refspecs for use when fetching.
233    pub(crate) fetch_specs: Vec<gix_refspec::RefSpec>,
234    /// Refspecs for use when pushing.
235    pub(crate) push_specs: Vec<gix_refspec::RefSpec>,
236    /// Tell us what to do with tags when fetched.
237    pub(crate) fetch_tags: remote::fetch::Tags,
238    // /// Delete local tracking branches that don't exist on the remote anymore.
239    // pub(crate) prune: bool,
240    // /// Delete tags that don't exist on the remote anymore, equivalent to pruning the refspec `refs/tags/*:refs/tags/*`.
241    // pub(crate) prune_tags: bool,
242    /// The owning repository.
243    pub repo: &'repo Repository,
244}
245
246/// A utility to make matching against pathspecs simple.
247///
248/// Note that to perform pathspec matching, attribute access might need to be provided. For that, we use our own
249/// and argue that the implementation is only going to incur costs for it when a pathspec matches *and* has attributes.
250/// Should this potential duplication of effort to maintain attribute state be unacceptable, the user may fall back
251/// to the underlying plumbing.
252#[derive(Clone)]
253#[cfg(feature = "attributes")]
254pub struct Pathspec<'repo> {
255    /// The owning repository.
256    pub repo: &'repo Repository,
257    /// The cache to power attribute access. It's only initialized if we have a pattern with attributes.
258    pub(crate) stack: Option<gix_worktree::Stack>,
259    /// The prepared search to use for checking matches.
260    pub(crate) search: gix_pathspec::Search,
261}
262
263/// Like [`Pathspec`], but without a Repository reference and with minimal API.
264#[derive(Clone)]
265#[cfg(feature = "attributes")]
266pub struct PathspecDetached {
267    /// The cache to power attribute access. It's only initialized if we have a pattern with attributes.
268    pub stack: Option<gix_worktree::Stack>,
269    /// The prepared search to use for checking matches.
270    pub search: gix_pathspec::Search,
271    /// A thread-safe version of an ODB.
272    pub odb: crate::OdbHandleArc,
273}
274
275/// A stand-in for the submodule of a particular name.
276#[derive(Clone)]
277#[cfg(feature = "attributes")]
278pub struct Submodule<'repo> {
279    pub(crate) state: std::rc::Rc<crate::submodule::SharedState<'repo>>,
280    pub(crate) name: crate::bstr::BString,
281}
282
283/// A utility to access `.gitattributes` and `.gitignore` information efficiently.
284#[cfg(any(feature = "attributes", feature = "excludes"))]
285pub struct AttributeStack<'repo> {
286    /// The owning repository.
287    pub repo: &'repo Repository,
288    pub(crate) inner: gix_worktree::Stack,
289}