| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#; |
| 2 | |
| 3 | pub fn retrieve_git_versionrust-analyzer cargo git-delta 0.19.2 utils/git/retrieve_git_version().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, usize)> { |
| 4 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(git_path) = grep_clirust-analyzer cargo grep-cli 0.1.12 crate/::resolve_binaryrust-analyzer cargo grep-cli 0.1.12 decompress/resolve_binary().("git") { |
| 5 | let cmd = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(git_path).argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("--version").outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 6 | parse_git_versionrust-analyzer cargo git-delta 0.19.2 utils/git/parse_git_version().(&cmd.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.) |
| 7 | } else { |
| 8 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | fn parse_git_versionrust-analyzer cargo git-delta 0.19.2 utils/git/parse_git_version().(output: &[u8]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, usize)> { |
| 13 | let mut parts = output.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]strip_prefix().(b"git version ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split().(|&b| b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'.'); |
| 14 | let major = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Split<'a, T, P>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 15 | let minor = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Split<'a, T, P>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 16 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((major, minor)) |
| 17 | } |
| 18 | |
| 19 | #[cfg(test)] |
| 20 | mod testsrust-analyzer cargo git-delta 0.19.2 utils/git/tests/ { |
| 21 | use superrust-analyzer cargo git-delta 0.19.2 utils/git/::parse_git_versionrust-analyzer cargo git-delta 0.19.2 utils/git/parse_git_version().; |
| 22 | use rstestrust-analyzer cargo rstest 0.21.0 crate/::rstestrust-analyzer cargo rstest_macros 0.21.0 rstest:; |
| 23 | |
| 24 | #[rstestrust-analyzer cargo rstest_macros 0.21.0 rstest:] |
| 25 | #[case(b"git version 2.46.0", Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((2, 46)))] |
| 26 | #[case(b"git version 2.39.3 (Apple Git-146)", Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((2, 39)))] |
| 27 | #[case(b"", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)] |
| 28 | fn test_parse_git_versionrust-analyzer cargo git-delta 0.19.2 utils/git/tests/test_parse_git_version().(#[case] input: &[u8], #[case] expected: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, usize)>) { |
| 29 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_git_versionrust-analyzer cargo git-delta 0.19.2 utils/git/parse_git_version().(input), expected); |
| 30 | } |
| 31 | } |