git/
commit_diff_loader_options.rs

1/// Options for loading a commit with diff
2#[derive(Copy, Clone, Debug)]
3#[allow(clippy::struct_excessive_bools)]
4pub struct CommitDiffLoaderOptions {
5	pub(crate) context_lines: u32,
6	pub(crate) copies: bool,
7	pub(crate) ignore_whitespace: bool,
8	pub(crate) ignore_whitespace_change: bool,
9	pub(crate) ignore_blank_lines: bool,
10	pub(crate) interhunk_context: u32,
11	pub(crate) rename_limit: u32,
12	pub(crate) renames: bool,
13}
14
15impl CommitDiffLoaderOptions {
16	/// Create a new default instance.
17	#[inline]
18	#[must_use]
19	pub const fn new() -> Self {
20		Self {
21			context_lines: 0,
22			copies: false,
23			ignore_whitespace: false,
24			ignore_whitespace_change: false,
25			ignore_blank_lines: false,
26			interhunk_context: 0,
27			rename_limit: 0,
28			renames: false,
29		}
30	}
31
32	/// Set the number of context lines.
33	#[inline]
34	#[must_use]
35	pub const fn context_lines(mut self, context_lines: u32) -> Self {
36		self.context_lines = context_lines;
37		self
38	}
39
40	/// Set the number of interhunk lines.
41	#[inline]
42	#[must_use]
43	pub const fn interhunk_context(mut self, interhunk_context: u32) -> Self {
44		self.interhunk_context = interhunk_context;
45		self
46	}
47
48	/// Set if to detect copies or not.
49	#[inline]
50	#[must_use]
51	pub const fn copies(mut self, copies: bool) -> Self {
52		self.copies = copies;
53		self
54	}
55
56	/// Set if to ignore whitespace.
57	#[inline]
58	#[must_use]
59	pub const fn ignore_whitespace(mut self, ignore_whitespace: bool) -> Self {
60		self.ignore_whitespace = ignore_whitespace;
61		self
62	}
63
64	/// Set if to ignore changes in whitespace.
65	#[inline]
66	#[must_use]
67	pub const fn ignore_whitespace_change(mut self, ignore_whitespace_change: bool) -> Self {
68		self.ignore_whitespace_change = ignore_whitespace_change;
69		self
70	}
71
72	/// Set if to ignore blank lines.
73	#[inline]
74	#[must_use]
75	pub const fn ignore_blank_lines(mut self, ignore_blank_lines: bool) -> Self {
76		self.ignore_blank_lines = ignore_blank_lines;
77		self
78	}
79
80	/// Set if to detect renames, as well as the file rename limit.
81	#[inline]
82	#[must_use]
83	pub const fn renames(mut self, renames: bool, limit: u32) -> Self {
84		self.rename_limit = limit;
85		self.renames = renames;
86		self
87	}
88}
89
90#[cfg(test)]
91mod tests {
92	use super::*;
93
94	#[test]
95	fn context_lines() {
96		assert_eq!(CommitDiffLoaderOptions::new().context_lines(42).context_lines, 42);
97	}
98
99	#[test]
100	fn interhunk_lines() {
101		assert_eq!(
102			CommitDiffLoaderOptions::new().interhunk_context(42).interhunk_context,
103			42
104		);
105	}
106
107	#[test]
108	fn copies() {
109		assert!(CommitDiffLoaderOptions::new().copies(true).copies);
110	}
111
112	#[test]
113	fn ignore_whitespace() {
114		assert!(CommitDiffLoaderOptions::new().ignore_whitespace(true).ignore_whitespace);
115	}
116
117	#[test]
118	fn ignore_whitespace_change() {
119		assert!(
120			CommitDiffLoaderOptions::new()
121				.ignore_whitespace_change(true)
122				.ignore_whitespace_change
123		);
124	}
125
126	#[test]
127	fn ignore_blank_lines() {
128		assert!(
129			CommitDiffLoaderOptions::new()
130				.ignore_blank_lines(true)
131				.ignore_blank_lines
132		);
133	}
134
135	#[test]
136	fn renames() {
137		let load_commit_diff_options = CommitDiffLoaderOptions::new().renames(true, 42);
138		assert!(load_commit_diff_options.renames);
139		assert_eq!(load_commit_diff_options.rename_limit, 42);
140	}
141}