Skip to content

Commit

Permalink
no cloning for Sig and Author by using BString directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 30, 2022
1 parent 8df0d19 commit 954de84
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions src/info/author.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use git_repository as git;
use serde::ser::SerializeStruct;
use serde::Serialize;

pub struct Author {
name: String,
email: Option<String>,
name: git::bstr::BString,
email: Option<git::bstr::BString>,
nbr_of_commits: usize,
contribution: usize,
}

impl Author {
pub fn new(
name: String,
email: Option<String>,
name: git::bstr::BString,
email: Option<git::bstr::BString>,
nbr_of_commits: usize,
total_nbr_of_commits: usize,
) -> Self {
Expand Down
26 changes: 7 additions & 19 deletions src/info/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Signature<'_>> 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<git::actor::Signature> 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 }
}
}
Expand Down Expand Up @@ -159,9 +146,10 @@ impl<'a> Repo<'a> {
let authors: Vec<Author> = 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,
)
Expand Down

0 comments on commit 954de84

Please sign in to comment.