1use std::path::Path;
2
3#[must_use]
5pub fn new() -> RevList<'static> {
6 RevList::new()
7}
8
9#[derive(Debug)]
13pub struct RevList<'a> {
14 repo_path: Option<&'a Path>,
15 topo_order: bool,
16 reverse: bool,
17 max_count: Option<usize>,
18 commits: Vec<&'a str>,
19}
20
21crate::impl_repo_path!(RevList);
22
23impl<'a> RevList<'a> {
24 #[must_use]
25 fn new() -> Self {
26 Self {
27 repo_path: None,
28 topo_order: false,
29 reverse: false,
30 max_count: None,
31 commits: Vec::new(),
32 }
33 }
34
35 crate::flag_methods! {
36 pub fn topo_order / topo_order_if, topo_order, "Conditionally show commits in topological order."
40 }
41
42 crate::flag_methods! {
43 pub fn reverse / reverse_if, reverse, "Conditionally output commits in reverse order."
47 }
48
49 #[must_use]
53 pub fn max_count(mut self, count: usize) -> Self {
54 self.max_count = Some(count);
55 self
56 }
57
58 #[must_use]
60 pub fn commit(mut self, commit: &'a str) -> Self {
61 self.commits.push(commit);
62 self
63 }
64}
65
66impl Default for RevList<'_> {
67 fn default() -> Self {
68 Self::new()
69 }
70}
71
72impl crate::Build for RevList<'_> {
73 fn build(self) -> cmd_proc::Command {
74 crate::base_command(self.repo_path)
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 repo_path: self.repo_path,
89 topo_order: self.topo_order,
90 reverse: self.reverse,
91 max_count: self.max_count,
92 commits: self.commits.clone(),
93 });
94 command.test_eq(other);
95 }
96}