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
use crate::{Reference, ReferenceKind};

/// Builder for creating a new reference.
#[derive(Debug)]
pub struct ReferenceBuilder {
	reference: Reference,
}

impl ReferenceBuilder {
	/// Create a new instance of the builder with the provided hash. The new instance will default
	/// to a branch kind and a name of "main".
	#[inline]
	#[must_use]
	pub fn new(hash: &str) -> Self {
		Self {
			reference: Reference {
				hash: String::from(hash),
				name: String::from("refs/heads/main"),
				shorthand: String::from("main"),
				kind: ReferenceKind::Branch,
			},
		}
	}

	/// Set the hash.
	#[inline]
	pub fn hash(&mut self, hash: &str) -> &mut Self {
		self.reference.hash = String::from(hash);
		self
	}

	/// Set the name.
	#[inline]
	pub fn name(&mut self, name: &str) -> &mut Self {
		self.reference.name = String::from(name);
		self
	}

	/// Set the shortname.
	#[inline]
	pub fn shorthand(&mut self, shorthand: &str) -> &mut Self {
		self.reference.shorthand = String::from(shorthand);
		self
	}

	/// Set the kind.
	#[inline]
	pub fn kind(&mut self, kind: ReferenceKind) -> &mut Self {
		self.reference.kind = kind;
		self
	}

	/// Build the `Reference`.
	#[inline]
	#[must_use]
	#[allow(clippy::missing_const_for_fn)]
	pub fn build(self) -> Reference {
		self.reference
	}
}