Skip to content

Commit 954de84

Browse files
committed
no cloning for Sig and Author by using BString directly
1 parent 8df0d19 commit 954de84

File tree

4 files changed

+75
-24
lines changed

4 files changed

+75
-24
lines changed

Diff for: Cargo.lock

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bytecount = "0.6.2"
3333
clap = {version = "3.1.6", features = ["cargo", "wrap_help"]}
3434
color_quant = "1.1.0"
3535
git2 = {version = "0.14.2", default-features = false}
36-
git-repository = { version = "0.15.0", git = "https://github.com/Byron/gitoxide", branch = "for-onefetch", features = ["max-performance", "unstable"] }
36+
git-repository = { version = "0.15.0", git = "https://github.com/Byron/gitoxide", branch = "for-onefetch", features = ["max-performance", "unstable", "serde1"] }
3737
image = "0.24.1"
3838
owo-colors = "3.3.0"
3939
regex = "1.5.5"

Diff for: src/info/author.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
use git_repository as git;
12
use serde::ser::SerializeStruct;
23
use serde::Serialize;
34

45
pub struct Author {
5-
name: String,
6-
email: Option<String>,
6+
name: git::bstr::BString,
7+
email: Option<git::bstr::BString>,
78
nbr_of_commits: usize,
89
contribution: usize,
910
}
1011

1112
impl Author {
1213
pub fn new(
13-
name: String,
14-
email: Option<String>,
14+
name: git::bstr::BString,
15+
email: Option<git::bstr::BString>,
1516
nbr_of_commits: usize,
1617
total_nbr_of_commits: usize,
1718
) -> Self {

Diff for: src/info/repo.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use crate::info::author::Author;
22
use crate::info::head_refs::HeadRefs;
33
use anyhow::{Context, Result};
44
use byte_unit::Byte;
5-
use git2::{
6-
BranchType, Repository, RepositoryOpenFlags, Signature, Status, StatusOptions, StatusShow,
7-
};
5+
use git2::{BranchType, Repository, RepositoryOpenFlags, Status, StatusOptions, StatusShow};
86
use git_repository as git;
97
use git_repository::bstr::ByteSlice;
108
use regex::Regex;
@@ -26,23 +24,12 @@ pub struct Repo<'a> {
2624

2725
#[derive(Hash, PartialEq, Eq)]
2826
pub struct Sig {
29-
name: String,
30-
email: String,
31-
}
32-
33-
// TODO: make Sig use BString, to avoid allocations/utf8 checks
34-
impl From<Signature<'_>> for Sig {
35-
fn from(sig: Signature) -> Self {
36-
let name = String::from_utf8_lossy(sig.name_bytes()).into_owned();
37-
let email = String::from_utf8_lossy(sig.email_bytes()).into_owned();
38-
Self { name, email }
39-
}
27+
name: git::bstr::BString,
28+
email: git::bstr::BString,
4029
}
4130

4231
impl From<git::actor::Signature> for Sig {
43-
fn from(sig: git::actor::Signature) -> Self {
44-
let name = sig.name.to_string();
45-
let email = sig.email.to_string();
32+
fn from(git::actor::Signature { name, email, .. }: git::actor::Signature) -> Self {
4633
Self { name, email }
4734
}
4835
}
@@ -159,9 +146,10 @@ impl<'a> Repo<'a> {
159146
let authors: Vec<Author> = authors_by_number_of_commits
160147
.into_iter()
161148
.map(|(author, author_nbr_of_commits)| {
149+
let email = author.email;
162150
Author::new(
163-
author.name.clone(),
164-
show_email.then(|| author.email),
151+
author.name,
152+
show_email.then(|| email),
165153
author_nbr_of_commits,
166154
total_nbr_of_commits,
167155
)

0 commit comments

Comments
 (0)