Skip to content

Commit

Permalink
Merge branch 'main' into fix-odb-race
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 21, 2022
2 parents 53b5086 + b833a4d commit 30712dc
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 309 deletions.
1 change: 1 addition & 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 @@ -37,7 +37,7 @@ pretty-cli = [ "gitoxide-core/serde1", "prodash/progress-tree", "prodash/progres

## The `--verbose` flag will be powered by an interactive progress mechanism that doubles as log as well as interactive progress
## that appears after a short duration.
prodash-render-line-crossterm = ["prodash-render-line", "prodash/render-line-crossterm", "atty", "crosstermion"]
prodash-render-line-crossterm = ["prodash-render-line", "prodash/render-line-crossterm", "prodash/signal-hook", "atty", "crosstermion"]

#! ### Convenience Features
#! These combine common choices of the above features to represent typical builds
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@ is usable to some extend.
* [x] Generate and verify large commit graphs
* [ ] Generate huge pack from a lot of loose objects

### Cargo features

Many crates use feature flags to allow tuning the compiled result based on your needs. Have a [look at the guide][cargo-features] for more information.

[cargo-features]: https://github.com/Byron/gitoxide/blob/main/cargo-features.md#git-config

### Stability and MSRV

Our [stability guide] helps to judge how much churn can be expected when depending on crates in this workspace.
Expand Down
5 changes: 5 additions & 0 deletions git-object/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ impl EntryMode {
*self != EntryMode::Tree
}

/// Return true if the entry is any kind of blob.
pub fn is_blob(&self) -> bool {
matches!(self, EntryMode::Blob | EntryMode::BlobExecutable)
}

/// Represent the mode as descriptive string.
pub fn as_str(&self) -> &'static str {
use EntryMode::*;
Expand Down
92 changes: 92 additions & 0 deletions gitoxide-core/src/hours/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use crate::hours::FileStats;
use crate::hours::LineStats;
use crate::hours::WorkByEmail;
use crate::hours::WorkByPerson;
use git::bstr::BStr;
use git_repository as git;
use itertools::Itertools;
use std::collections::hash_map::Entry;
use std::collections::HashMap;

const MINUTES_PER_HOUR: f32 = 60.0;
pub const HOURS_PER_WORKDAY: f32 = 8.0;

pub fn estimate_hours(
commits: &[(u32, git::actor::SignatureRef<'static>)],
stats: &[(u32, FileStats, LineStats)],
) -> WorkByEmail {
assert!(!commits.is_empty());
const MAX_COMMIT_DIFFERENCE_IN_MINUTES: f32 = 2.0 * MINUTES_PER_HOUR;
const FIRST_COMMIT_ADDITION_IN_MINUTES: f32 = 2.0 * MINUTES_PER_HOUR;

let hours_for_commits = commits.iter().map(|t| &t.1).rev().tuple_windows().fold(
0_f32,
|hours, (cur, next): (&git::actor::SignatureRef<'_>, &git::actor::SignatureRef<'_>)| {
let change_in_minutes = (next
.time
.seconds_since_unix_epoch
.saturating_sub(cur.time.seconds_since_unix_epoch)) as f32
/ MINUTES_PER_HOUR;
if change_in_minutes < MAX_COMMIT_DIFFERENCE_IN_MINUTES {
hours + change_in_minutes as f32 / MINUTES_PER_HOUR
} else {
hours + (FIRST_COMMIT_ADDITION_IN_MINUTES / MINUTES_PER_HOUR)
}
},
);

let author = &commits[0].1;
let (files, lines) = (!stats.is_empty())
.then(|| {
commits
.iter()
.map(|t| &t.0)
.fold((FileStats::default(), LineStats::default()), |mut acc, id| match stats
.binary_search_by(|t| t.0.cmp(id))
{
Ok(idx) => {
let t = &stats[idx];
acc.0.add(&t.1);
acc.1.add(&t.2);
acc
}
Err(_) => acc,
})
})
.unwrap_or_default();
WorkByEmail {
name: author.name,
email: author.email,
hours: FIRST_COMMIT_ADDITION_IN_MINUTES / 60.0 + hours_for_commits,
num_commits: commits.len() as u32,
files,
lines,
}
}

pub fn deduplicate_identities(persons: &[WorkByEmail]) -> Vec<WorkByPerson> {
let mut email_to_index = HashMap::<&'static BStr, usize>::with_capacity(persons.len());
let mut name_to_index = HashMap::<&'static BStr, usize>::with_capacity(persons.len());
let mut out = Vec::<WorkByPerson>::with_capacity(persons.len());
for person_by_email in persons {
match email_to_index.entry(person_by_email.email) {
Entry::Occupied(email_entry) => {
out[*email_entry.get()].merge(person_by_email);
name_to_index.insert(&person_by_email.name, *email_entry.get());
}
Entry::Vacant(email_entry) => match name_to_index.entry(&person_by_email.name) {
Entry::Occupied(name_entry) => {
out[*name_entry.get()].merge(person_by_email);
email_entry.insert(*name_entry.get());
}
Entry::Vacant(name_entry) => {
let idx = out.len();
name_entry.insert(idx);
email_entry.insert(idx);
out.push(person_by_email.into());
}
},
}
}
out
}
Loading

0 comments on commit 30712dc

Please sign in to comment.