Skip to content

Commit def80df

Browse files
committed
feat: ein tool estimate-hours now supports mailmaps (#366)
1 parent b53da03 commit def80df

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

git-repository/src/repository/snapshots.rs

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ impl crate::Repository {
1818
}
1919
}
2020

21+
// TODO: tests
22+
/// Similar to [`load_mailmap_into()`][crate::Repository::load_mailmap_into()], but ignores all errors and returns at worst
23+
/// an empty mailmap, e.g. if there is no mailmap or if there were errors loading them.
24+
///
25+
/// This represents typical usage within git, which also works with what's there without considering a populated mailmap
26+
/// a reason to abort an operation, considering it optional.
27+
#[cfg(feature = "git-mailmap")]
28+
pub fn load_mailmap(&self) -> git_mailmap::Snapshot {
29+
let mut out = git_mailmap::Snapshot::default();
30+
self.load_mailmap_into(&mut out).ok();
31+
out
32+
}
33+
2134
// TODO: tests
2235
/// Try to merge mailmaps from the following locations into `target`:
2336
///

gitoxide-core/src/hours.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::{
99
};
1010

1111
use anyhow::{anyhow, bail};
12+
use git_repository as git;
1213
use git_repository::{actor, bstr::BString, interrupt, objs, prelude::*, progress, refs::file::ReferenceExt, Progress};
1314
use itertools::Itertools;
1415
use rayon::prelude::*;
@@ -44,7 +45,7 @@ where
4445
W: io::Write,
4546
P: Progress,
4647
{
47-
let repo = git_repository::discover(working_dir)?;
48+
let repo = git::discover(working_dir)?;
4849
let handle = repo.clone().apply_environment();
4950
let commit_id = repo
5051
.refs
@@ -79,6 +80,7 @@ where
7980
commits
8081
};
8182

83+
let mailmap = repo.load_mailmap();
8284
let start = Instant::now();
8385
#[allow(clippy::redundant_closure)]
8486
let mut all_commits: Vec<actor::Signature> = all_commits
@@ -87,7 +89,7 @@ where
8789
objs::CommitRefIter::from_bytes(&commit_data)
8890
.signatures()
8991
.next()
90-
.map(|author| actor::Signature::from(author))
92+
.map(|author| mailmap.resolve(&author))
9193
})
9294
.try_fold(
9395
|| Vec::new(),

gitoxide-core/src/repository/mailmap.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::OutputFormat;
22
use git_repository as git;
3-
use git_repository::bstr::ByteSlice;
3+
#[cfg(feature = "serde1")]
44
use git_repository::mailmap::Entry;
55
use std::io;
66
use std::path::PathBuf;
@@ -17,6 +17,7 @@ struct JsonEntry {
1717
#[cfg(feature = "serde1")]
1818
impl<'a> From<Entry<'a>> for JsonEntry {
1919
fn from(v: Entry<'a>) -> Self {
20+
use git_repository::bstr::ByteSlice;
2021
JsonEntry {
2122
new_name: v.new_name().map(|s| s.to_str_lossy().into_owned()),
2223
new_email: v.new_email().map(|s| s.to_str_lossy().into_owned()),
@@ -29,7 +30,7 @@ impl<'a> From<Entry<'a>> for JsonEntry {
2930
pub fn entries(
3031
repository: PathBuf,
3132
format: OutputFormat,
32-
out: impl io::Write,
33+
#[cfg_attr(not(feature = "serde1"), allow(unused_variables))] out: impl io::Write,
3334
mut err: impl io::Write,
3435
) -> anyhow::Result<()> {
3536
if format == OutputFormat::Human {

0 commit comments

Comments
 (0)