Skip to content

Commit

Permalink
Simplify return types with aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
spenserblack committed Nov 2, 2023
1 parent 19bb10a commit dc60ab7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/info/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ pub fn traverse_commit_graph(repo: &gix::Repository, options: &CliOptions) -> Re
Ok(git_metrics)
}

type CommitsBySignature = HashMap<Sig, usize>;

fn get_author_channel(
repo: &gix::Repository,
num_threads: usize,
bot_regex_pattern: &Option<MyRegex>,
mailmap: &gix::mailmap::Snapshot,
) -> (
Vec<JoinHandle<Result<HashMap<Sig, usize>>>>,
Vec<JoinHandle<Result<CommitsBySignature>>>,
crossbeam_channel::Sender<ObjectId>,
) {
// we intentionally over-allocate threads a little as the main thread won't be very busy anyway
Expand All @@ -140,7 +142,7 @@ fn get_author_channel(
let bot_regex_pattern = bot_regex_pattern.clone();
let rx = rx.clone();
move || -> anyhow::Result<_> {
let mut number_of_commits_by_signature: HashMap<Sig, usize> = HashMap::new();
let mut number_of_commits_by_signature = CommitsBySignature::new();
// We are sure to see each object only once.
repo.object_cache_size(0);
while let Ok(commit_id) = rx.recv() {
Expand All @@ -160,22 +162,22 @@ fn get_author_channel(
(threads, tx)
}

type CommitsByFilepath = HashMap<BString, usize>;
type ChurnPair = (CommitsByFilepath, usize);

fn get_churn_channel(
repo: &gix::Repository,
has_commit_graph_traversal_ended: &Arc<AtomicBool>,
total_number_of_commits: &Arc<AtomicUsize>,
churn_pool_size_opt: Option<usize>,
) -> Result<(
JoinHandle<Result<(HashMap<BString, usize>, usize)>>,
Sender<ObjectId>,
)> {
) -> Result<(JoinHandle<Result<ChurnPair>>, Sender<ObjectId>)> {
let (tx, rx) = channel::<gix::hash::ObjectId>();
let thread = std::thread::spawn({
let repo = repo.clone();
let has_commit_graph_traversal_ended = has_commit_graph_traversal_ended.clone();
let total_number_of_commits = total_number_of_commits.clone();
move || -> Result<_> {
let mut number_of_commits_by_file_path: HashMap<BString, usize> = HashMap::new();
let mut number_of_commits_by_file_path = CommitsByFilepath::new();
let mut number_of_diffs_computed = 0;
while let Ok(commit_id) = rx.recv() {
let commit = repo.find_object(commit_id)?.into_commit();
Expand Down

0 comments on commit dc60ab7

Please sign in to comment.