diff options
author | Tim Oram <dev@mitmaro.ca> | 2024-02-15 19:33:42 -0330 |
---|---|---|
committer | Tim Oram <dev@mitmaro.ca> | 2024-02-15 20:27:06 -0330 |
commit | 94bd5bdf98138a5930ad72b2f97a9b9fe53ae7f5 (patch) | |
tree | 1e8f6b54e8fd04d32bff3781f2cfb2f83b5c0aed | |
parent | 2b508d278f946bcd9a245501401ca4918a13f61f (diff) |
Remove pub access in commit_diff
-rw-r--r-- | src/git/commit.rs | 2 | ||||
-rw-r--r-- | src/git/commit_diff.rs | 31 | ||||
-rw-r--r-- | src/git/commit_diff_loader.rs | 10 | ||||
-rw-r--r-- | src/test_helpers/builders/commit_diff.rs | 42 |
4 files changed, 58 insertions, 27 deletions
diff --git a/src/git/commit.rs b/src/git/commit.rs index fccce68..6a04ac2 100644 --- a/src/git/commit.rs +++ b/src/git/commit.rs @@ -24,6 +24,7 @@ impl Commit { /// Get the reference to the commit #[must_use] + #[allow(dead_code)] pub(crate) const fn reference(&self) -> &Option<Reference> { &self.reference } @@ -36,6 +37,7 @@ impl Commit { /// Get the author of the commit. #[must_use] + #[allow(dead_code)] pub(crate) const fn authored_date(&self) -> &Option<DateTime<Local>> { &self.authored_date } diff --git a/src/git/commit_diff.rs b/src/git/commit_diff.rs index 46d0d8c..ad4619b 100644 --- a/src/git/commit_diff.rs +++ b/src/git/commit_diff.rs @@ -3,15 +3,33 @@ use crate::git::{Commit, FileStatus}; /// Represents a commit with a diff #[derive(Debug)] pub(crate) struct CommitDiff { - pub(crate) commit: Commit, - pub(crate) parent: Option<Commit>, - pub(crate) file_statuses: Vec<FileStatus>, - pub(crate) number_files_changed: usize, - pub(crate) number_insertions: usize, - pub(crate) number_deletions: usize, + commit: Commit, + parent: Option<Commit>, + file_statuses: Vec<FileStatus>, + number_files_changed: usize, + number_insertions: usize, + number_deletions: usize, } impl CommitDiff { + pub(crate) fn new( + commit: Commit, + parent: Option<Commit>, + file_statuses: Vec<FileStatus>, + number_files_changed: usize, + number_insertions: usize, + number_deletions: usize, + ) -> Self { + CommitDiff { + commit, + parent, + file_statuses, + number_files_changed, + number_insertions, + number_deletions, + } + } + /// The commit of the diff #[must_use] pub(crate) const fn commit(&self) -> &Commit { @@ -20,6 +38,7 @@ impl CommitDiff { /// The parent commit for the diff #[must_use] + #[allow(dead_code)] pub(crate) const fn parent(&self) -> &Option<Commit> { &self.parent } diff --git a/src/git/commit_diff_loader.rs b/src/git/commit_diff_loader.rs index 3b3621b..566a7fd 100644 --- a/src/git/commit_diff_loader.rs +++ b/src/git/commit_diff_loader.rs @@ -145,14 +145,14 @@ impl<'options> CommitDiffLoader<'options> { let fsb = file_stats_builder.into_inner(); - Ok(CommitDiff { - commit: Commit::from(commit), - parent: parent.map(Commit::from), - file_statuses: fsb.build(), + Ok(CommitDiff::new( + Commit::from(commit), + parent.map(Commit::from), + fsb.build(), number_files_changed, number_insertions, number_deletions, - }) + )) } } diff --git a/src/test_helpers/builders/commit_diff.rs b/src/test_helpers/builders/commit_diff.rs index 1c97815..55b286e 100644 --- a/src/test_helpers/builders/commit_diff.rs +++ b/src/test_helpers/builders/commit_diff.rs @@ -3,7 +3,12 @@ use crate::git::{Commit, CommitDiff, FileStatus}; /// Builder for creating a new commit diff. #[derive(Debug)] pub(crate) struct CommitDiffBuilder { - commit_diff: CommitDiff, + commit: Commit, + parent: Option<Commit>, + file_statuses: Vec<FileStatus>, + number_files_changed: usize, + number_insertions: usize, + number_deletions: usize, } impl CommitDiffBuilder { @@ -11,14 +16,12 @@ impl CommitDiffBuilder { #[must_use] pub(crate) const fn new(commit: Commit) -> Self { Self { - commit_diff: CommitDiff { - commit, - parent: None, - file_statuses: vec![], - number_files_changed: 0, - number_insertions: 0, - number_deletions: 0, - }, + commit, + parent: None, + file_statuses: vec![], + number_files_changed: 0, + number_insertions: 0, + number_deletions: 0, } } @@ -26,7 +29,7 @@ impl CommitDiffBuilder { #[must_use] #[allow(clippy::missing_const_for_fn)] pub(crate) fn commit(mut self, commit: Commit) -> Self { - self.commit_diff.commit = commit; + self.commit = commit; self } @@ -34,35 +37,35 @@ impl CommitDiffBuilder { #[must_use] #[allow(clippy::missing_const_for_fn)] pub(crate) fn parent(mut self, parent: Commit) -> Self { - self.commit_diff.parent = Some(parent); + self.parent = Some(parent); self } /// Set the `FileStatus`es. #[must_use] pub(crate) fn file_statuses(mut self, statuses: Vec<FileStatus>) -> Self { - self.commit_diff.file_statuses = statuses; + self.file_statuses = statuses; self } /// Set the number of files changed. #[must_use] pub(crate) const fn number_files_changed(mut self, count: usize) -> Self { - self.commit_diff.number_files_changed = count; + self.number_files_changed = count; self } /// Set the number of line insertions. #[must_use] pub(crate) const fn number_insertions(mut self, count: usize) -> Self { - self.commit_diff.number_insertions = count; + self.number_insertions = count; self } /// Set the number of line deletions. #[must_use] pub(crate) const fn number_deletions(mut self, count: usize) -> Self { - self.commit_diff.number_deletions = count; + self.number_deletions = count; self } @@ -70,6 +73,13 @@ impl CommitDiffBuilder { #[must_use] #[allow(clippy::missing_const_for_fn)] pub(crate) fn build(self) -> CommitDiff { - self.commit_diff + CommitDiff::new( + self.commit, + self.parent, + self.file_statuses, + self.number_files_changed, + self.number_insertions, + self.number_deletions, + ) } } |