1#[must_use]
3pub fn new() -> RevList<'static> {
4 RevList::new()
5}
6
7#[derive(Debug)]
11pub struct RevList<'a> {
12 base: crate::RepoBase<'a>,
13 topo_order: bool,
14 reverse: bool,
15 max_count: Option<usize>,
16 commits: Vec<&'a str>,
17}
18
19crate::impl_repo_base!(RevList);
20
21impl<'a> RevList<'a> {
22 #[must_use]
23 fn new() -> Self {
24 Self {
25 base: crate::RepoBase::default(),
26 topo_order: false,
27 reverse: false,
28 max_count: None,
29 commits: Vec::new(),
30 }
31 }
32
33 crate::flag_methods! {
34 pub fn topo_order / topo_order_if, topo_order, "Conditionally show commits in topological order."
38 }
39
40 crate::flag_methods! {
41 pub fn reverse / reverse_if, reverse, "Conditionally output commits in reverse order."
45 }
46
47 #[must_use]
51 pub fn max_count(mut self, count: usize) -> Self {
52 self.max_count = Some(count);
53 self
54 }
55
56 #[must_use]
58 pub fn commit(mut self, commit: &'a str) -> Self {
59 self.commits.push(commit);
60 self
61 }
62}
63
64impl Default for RevList<'_> {
65 fn default() -> Self {
66 Self::new()
67 }
68}
69
70impl crate::Build for RevList<'_> {
71 fn build(self) -> Result<cmd_proc::Command, crate::EnvError> {
72 Ok(self
73 .base
74 .command()?
75 .argument("rev-list")
76 .optional_flag(self.topo_order, "--topo-order")
77 .optional_flag(self.reverse, "--reverse")
78 .optional_option("--max-count", self.max_count.map(|c| c.to_string()))
79 .arguments(self.commits))
80 }
81}
82
83#[cfg(feature = "test-utils")]
84impl RevList<'_> {
85 pub fn test_eq(&self, other: &cmd_proc::Command) {
87 let command = crate::Build::build(Self {
88 base: self.base,
89 topo_order: self.topo_order,
90 reverse: self.reverse,
91 max_count: self.max_count,
92 commits: self.commits.clone(),
93 })
94 .unwrap();
95 command.test_eq(other);
96 }
97}