From 954de842f1f91dff19898158ba593a1a39f3e3a5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 30 Mar 2022 09:25:22 +0800 Subject: [PATCH] no cloning for `Sig` and `Author` by using BString directly --- Cargo.lock | 62 ++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- src/info/author.rs | 9 ++++--- src/info/repo.rs | 26 ++++++------------- 4 files changed, 75 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 316005e60..e4ee75db4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,6 +176,7 @@ dependencies = [ "lazy_static", "memchr", "regex-automata", + "serde", ] [[package]] @@ -691,6 +692,7 @@ dependencies = [ "itoa 1.0.1", "nom", "quick-error", + "serde", ] [[package]] @@ -756,6 +758,7 @@ version = "0.9.2" dependencies = [ "hex", "quick-error", + "serde", ] [[package]] @@ -772,6 +775,7 @@ dependencies = [ "git-object", "memmap2 0.5.3", "quick-error", + "serde", "smallvec", ] @@ -791,6 +795,7 @@ dependencies = [ "bstr", "git-actor", "quick-error", + "serde", ] [[package]] @@ -807,6 +812,7 @@ dependencies = [ "itoa 1.0.1", "nom", "quick-error", + "serde", "smallvec", ] @@ -821,6 +827,7 @@ dependencies = [ "git-pack", "git-quote", "parking_lot 0.12.0", + "serde", "tempfile", "thiserror", ] @@ -842,11 +849,36 @@ dependencies = [ "hash_hasher", "memmap2 0.5.3", "parking_lot 0.12.0", + "serde", "smallvec", "thiserror", "uluru", ] +[[package]] +name = "git-packetline" +version = "0.12.3" +dependencies = [ + "bstr", + "hex", + "quick-error", +] + +[[package]] +name = "git-protocol" +version = "0.14.0" +dependencies = [ + "bstr", + "btoi", + "git-features", + "git-hash", + "git-transport", + "maybe-async", + "nom", + "quick-error", + "serde", +] + [[package]] name = "git-quote" version = "0.1.0" @@ -870,6 +902,7 @@ dependencies = [ "memmap2 0.5.3", "nom", "quick-error", + "serde", ] [[package]] @@ -889,8 +922,10 @@ dependencies = [ "git-object", "git-odb", "git-pack", + "git-protocol", "git-ref", "git-tempfile", + "git-transport", "git-traverse", "git-url", "git-validate", @@ -913,6 +948,19 @@ dependencies = [ "tempfile", ] +[[package]] +name = "git-transport" +version = "0.15.0" +dependencies = [ + "bstr", + "git-features", + "git-packetline", + "git-url", + "quick-error", + "serde", + "thiserror", +] + [[package]] name = "git-traverse" version = "0.12.0" @@ -1302,6 +1350,17 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +[[package]] +name = "maybe-async" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6007f9dad048e0a224f27ca599d669fca8cfa0dac804725aab542b2eb032bce6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "memchr" version = "2.4.1" @@ -2035,6 +2094,9 @@ name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +dependencies = [ + "serde", +] [[package]] name = "spin" diff --git a/Cargo.toml b/Cargo.toml index f90785bd4..530a9d88d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ bytecount = "0.6.2" clap = {version = "3.1.6", features = ["cargo", "wrap_help"]} color_quant = "1.1.0" git2 = {version = "0.14.2", default-features = false} -git-repository = { version = "0.15.0", git = "https://github.com/Byron/gitoxide", branch = "for-onefetch", features = ["max-performance", "unstable"] } +git-repository = { version = "0.15.0", git = "https://github.com/Byron/gitoxide", branch = "for-onefetch", features = ["max-performance", "unstable", "serde1"] } image = "0.24.1" owo-colors = "3.3.0" regex = "1.5.5" diff --git a/src/info/author.rs b/src/info/author.rs index 50d12f1f7..3cfa7b5f6 100644 --- a/src/info/author.rs +++ b/src/info/author.rs @@ -1,17 +1,18 @@ +use git_repository as git; use serde::ser::SerializeStruct; use serde::Serialize; pub struct Author { - name: String, - email: Option, + name: git::bstr::BString, + email: Option, nbr_of_commits: usize, contribution: usize, } impl Author { pub fn new( - name: String, - email: Option, + name: git::bstr::BString, + email: Option, nbr_of_commits: usize, total_nbr_of_commits: usize, ) -> Self { diff --git a/src/info/repo.rs b/src/info/repo.rs index 66a5acf95..652549ee1 100644 --- a/src/info/repo.rs +++ b/src/info/repo.rs @@ -2,9 +2,7 @@ use crate::info::author::Author; use crate::info::head_refs::HeadRefs; use anyhow::{Context, Result}; use byte_unit::Byte; -use git2::{ - BranchType, Repository, RepositoryOpenFlags, Signature, Status, StatusOptions, StatusShow, -}; +use git2::{BranchType, Repository, RepositoryOpenFlags, Status, StatusOptions, StatusShow}; use git_repository as git; use git_repository::bstr::ByteSlice; use regex::Regex; @@ -26,23 +24,12 @@ pub struct Repo<'a> { #[derive(Hash, PartialEq, Eq)] pub struct Sig { - name: String, - email: String, -} - -// TODO: make Sig use BString, to avoid allocations/utf8 checks -impl From> for Sig { - fn from(sig: Signature) -> Self { - let name = String::from_utf8_lossy(sig.name_bytes()).into_owned(); - let email = String::from_utf8_lossy(sig.email_bytes()).into_owned(); - Self { name, email } - } + name: git::bstr::BString, + email: git::bstr::BString, } impl From for Sig { - fn from(sig: git::actor::Signature) -> Self { - let name = sig.name.to_string(); - let email = sig.email.to_string(); + fn from(git::actor::Signature { name, email, .. }: git::actor::Signature) -> Self { Self { name, email } } } @@ -159,9 +146,10 @@ impl<'a> Repo<'a> { let authors: Vec = authors_by_number_of_commits .into_iter() .map(|(author, author_nbr_of_commits)| { + let email = author.email; Author::new( - author.name.clone(), - show_email.then(|| author.email), + author.name, + show_email.then(|| email), author_nbr_of_commits, total_nbr_of_commits, )