summaryrefslogtreecommitdiffstats
path: root/src/git/testutil/build_commit_diff.rs
blob: 1c97815078dfef1c952e15fbe778039dd16f532b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::git::{Commit, CommitDiff, FileStatus};

/// Builder for creating a new commit diff.
#[derive(Debug)]
pub(crate) struct CommitDiffBuilder {
	commit_diff: CommitDiff,
}

impl CommitDiffBuilder {
	/// Create a new instance.
	#[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,
			},
		}
	}

	/// Set the commit.
	#[must_use]
	#[allow(clippy::missing_const_for_fn)]
	pub(crate) fn commit(mut self, commit: Commit) -> Self {
		self.commit_diff.commit = commit;
		self
	}

	/// Set the parent commit.
	#[must_use]
	#[allow(clippy::missing_const_for_fn)]
	pub(crate) fn parent(mut self, parent: Commit) -> Self {
		self.commit_diff.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
	}

	/// 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
	}

	/// 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
	}

	/// 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
	}

	/// Return the built `CommitDiff`
	#[must_use]
	#[allow(clippy::missing_const_for_fn)]
	pub(crate) fn build(self) -> CommitDiff {
		self.commit_diff
	}
}