]>
Commit | Line | Data |
---|---|---|
fe692bf9 FG |
1 | //! Home of the [`GitSource`]. |
2 | //! | |
3 | //! Apparently, the most important type in this module is [`GitSource`]. | |
4 | //! [`utils`] provides libgit2 utilities like fetch and checkout, whereas | |
781aab86 | 5 | //! [`oxide`] is the counterpart for gitoxide integration. [`known_hosts`] |
fe692bf9 FG |
6 | //! is the mitigation of [CVE-2022-46176]. |
7 | //! | |
8 | //! [CVE-2022-46176]: https://blog.rust-lang.org/2023/01/10/cve-2022-46176.html | |
9 | ||
0a29b90c FG |
10 | pub use self::source::GitSource; |
11 | pub use self::utils::{fetch, GitCheckout, GitDatabase, GitRemote}; | |
12 | mod known_hosts; | |
13 | mod oxide; | |
14 | mod source; | |
15 | mod utils; | |
16 | ||
fe692bf9 | 17 | /// For `-Zgitoxide` integration. |
0a29b90c | 18 | pub mod fetch { |
49aad941 FG |
19 | use crate::core::features::GitoxideFeatures; |
20 | use crate::Config; | |
21 | ||
22 | /// The kind remote repository to fetch. | |
23 | #[derive(Debug, Copy, Clone)] | |
24 | pub enum RemoteKind { | |
25 | /// A repository belongs to a git dependency. | |
26 | GitDependency, | |
27 | /// A repository belongs to a Cargo registry. | |
28 | Registry, | |
29 | } | |
30 | ||
31 | impl RemoteKind { | |
32 | /// Obtain the kind of history we would want for a fetch from our remote knowing if the target repo is already shallow | |
33 | /// via `repo_is_shallow` along with gitoxide-specific feature configuration via `config`. | |
34 | /// `rev_and_ref` is additional information that affects whether or not we may be shallow. | |
35 | pub(crate) fn to_shallow_setting( | |
36 | &self, | |
37 | repo_is_shallow: bool, | |
38 | config: &Config, | |
39 | ) -> gix::remote::fetch::Shallow { | |
40 | let has_feature = |cb: &dyn Fn(GitoxideFeatures) -> bool| { | |
41 | config | |
42 | .cli_unstable() | |
43 | .gitoxide | |
44 | .map_or(false, |features| cb(features)) | |
45 | }; | |
46 | ||
47 | // maintain shallow-ness and keep downloading single commits, or see if we can do shallow clones | |
48 | if !repo_is_shallow { | |
49 | match self { | |
50 | RemoteKind::GitDependency if has_feature(&|git| git.shallow_deps) => {} | |
51 | RemoteKind::Registry if has_feature(&|git| git.shallow_index) => {} | |
52 | _ => return gix::remote::fetch::Shallow::NoChange, | |
53 | } | |
54 | }; | |
55 | ||
56 | gix::remote::fetch::Shallow::DepthAtRemote(1.try_into().expect("non-zero")) | |
57 | } | |
58 | } | |
59 | ||
0a29b90c FG |
60 | pub type Error = gix::env::collate::fetch::Error<gix::refspec::parse::Error>; |
61 | } |