#
cargo/sources/git/
mod.rs

    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
    5//! [`oxide`] is the counterpart for gitoxide integration. [`known_hosts`]
    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
    10pub use self::source::GitSource;
    11pub use self::utils::{GitCheckout, GitDatabase, GitRemote, fetch, resolve_ref};
    12mod known_hosts;
    13mod oxide;
    14mod source;
    15mod utils;
    16
    17/// For `-Zgitoxide` integration.
    18pub mod fetch {
    19    use crate::GlobalContext;
    20    use crate::core::features::GitFeatures;
    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            gctx: &GlobalContext,
    39        ) -> gix::remote::fetch::Shallow {
    40            let has_feature = |cb: &dyn Fn(GitFeatures) -> bool| {
    41                gctx.cli_unstable()
    42                    .git
    43                    .map_or(false, |features| cb(features))
    44            };
    45
    46            // maintain shallow-ness and keep downloading single commits, or see if we can do shallow clones
    47            if !repo_is_shallow {
    48                match self {
    49                    RemoteKind::GitDependency if has_feature(&|features| features.shallow_deps) => {
    50                    }
    51                    RemoteKind::Registry if has_feature(&|features| features.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
    60    pub type Error = gix::env::collate::fetch::Error<gix::refspec::parse::Error>;
    61}