Skip to content

Commit bf63a13

Browse files
committed
percentages for files and lines added (#470)
1 parent 2a3c5b0 commit bf63a13

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

gitoxide-core/src/hours.rs

+27-9
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,12 @@ where
373373
if show_pii {
374374
results_by_hours.sort_by(|a, b| a.hours.partial_cmp(&b.hours).unwrap_or(std::cmp::Ordering::Equal));
375375
for entry in results_by_hours.iter() {
376-
entry.write_to(total_hours, file_stats, line_stats, &mut out)?;
376+
entry.write_to(
377+
total_hours,
378+
file_stats.then(|| total_files),
379+
line_stats.then(|| total_lines),
380+
&mut out,
381+
)?;
377382
writeln!(out)?;
378383
}
379384
}
@@ -543,8 +548,8 @@ impl WorkByPerson {
543548
fn write_to(
544549
&self,
545550
total_hours: f32,
546-
show_files: bool,
547-
show_lines: bool,
551+
total_files: Option<FileStats>,
552+
total_lines: Option<LineStats>,
548553
mut out: impl std::io::Write,
549554
) -> std::io::Result<()> {
550555
writeln!(
@@ -561,18 +566,23 @@ impl WorkByPerson {
561566
self.hours / HOURS_PER_WORKDAY,
562567
(self.hours / total_hours) * 100.0
563568
)?;
564-
if show_files {
569+
if let Some(total) = total_files {
565570
writeln!(
566571
out,
567-
"total files added/removed/modified: {}/{}/{}",
568-
self.files.added, self.files.removed, self.files.modified
572+
"total files added/removed/modified: {}/{}/{} ({:.02}%)",
573+
self.files.added,
574+
self.files.removed,
575+
self.files.modified,
576+
(self.files.sum() / total.sum()) * 100.0
569577
)?;
570578
}
571-
if show_lines {
579+
if let Some(total) = total_lines {
572580
writeln!(
573581
out,
574-
"total lines added/removed: {}/{}",
575-
self.lines.added, self.lines.removed
582+
"total lines added/removed: {}/{} ({:.02}%)",
583+
self.lines.added,
584+
self.lines.removed,
585+
(self.lines.sum() / total.sum()) * 100.0
576586
)?;
577587
}
578588
Ok(())
@@ -622,6 +632,10 @@ impl FileStats {
622632
a.add(other);
623633
a
624634
}
635+
636+
fn sum(&self) -> f32 {
637+
(self.added + self.removed + self.modified) as f32
638+
}
625639
}
626640

627641
impl LineStats {
@@ -636,4 +650,8 @@ impl LineStats {
636650
a.add(other);
637651
a
638652
}
653+
654+
fn sum(&self) -> f32 {
655+
(self.added + self.removed) as f32
656+
}
639657
}

0 commit comments

Comments
 (0)