git/testutil/
build_commit_diff.rs

1use crate::{Commit, CommitDiff, FileStatus};
2
3/// Builder for creating a new commit diff.
4#[derive(Debug)]
5pub struct CommitDiffBuilder {
6	commit_diff: CommitDiff,
7}
8
9impl CommitDiffBuilder {
10	/// Create a new instance.
11	#[inline]
12	#[must_use]
13	pub const fn new(commit: Commit) -> Self {
14		Self {
15			commit_diff: CommitDiff {
16				commit,
17				parent: None,
18				file_statuses: vec![],
19				number_files_changed: 0,
20				number_insertions: 0,
21				number_deletions: 0,
22			},
23		}
24	}
25
26	/// Set the commit.
27	#[inline]
28	#[must_use]
29	#[allow(clippy::missing_const_for_fn)]
30	pub fn commit(mut self, commit: Commit) -> Self {
31		self.commit_diff.commit = commit;
32		self
33	}
34
35	/// Set the parent commit.
36	#[inline]
37	#[must_use]
38	#[allow(clippy::missing_const_for_fn)]
39	pub fn parent(mut self, parent: Commit) -> Self {
40		self.commit_diff.parent = Some(parent);
41		self
42	}
43
44	/// Set the `FileStatus`es.
45	#[inline]
46	#[must_use]
47	pub fn file_statuses(mut self, statuses: Vec<FileStatus>) -> Self {
48		self.commit_diff.file_statuses = statuses;
49		self
50	}
51
52	/// Set the number of files changed.
53	#[inline]
54	#[must_use]
55	pub const fn number_files_changed(mut self, count: usize) -> Self {
56		self.commit_diff.number_files_changed = count;
57		self
58	}
59
60	/// Set the number of line insertions.
61	#[inline]
62	#[must_use]
63	pub const fn number_insertions(mut self, count: usize) -> Self {
64		self.commit_diff.number_insertions = count;
65		self
66	}
67
68	/// Set the number of line deletions.
69	#[inline]
70	#[must_use]
71	pub const fn number_deletions(mut self, count: usize) -> Self {
72		self.commit_diff.number_deletions = count;
73		self
74	}
75
76	/// Return the built `CommitDiff`
77	#[inline]
78	#[must_use]
79	#[allow(clippy::missing_const_for_fn)]
80	pub fn build(self) -> CommitDiff {
81		self.commit_diff
82	}
83}