hglib/commands/
heads.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this file,
3// You can obtain one at http://mozilla.org/MPL/2.0/.
4
5use super::common;
6use crate::client::{Client, HglibError, Runner};
7use crate::{runcommand, MkArg};
8
9pub struct Arg<'a> {
10    pub rev: &'a [&'a str],
11    pub startrev: &'a [&'a str],
12    pub topological: bool,
13    pub closed: bool,
14}
15
16impl<'a> Default for Arg<'a> {
17    fn default() -> Self {
18        Self {
19            rev: &[],
20            startrev: &[],
21            topological: false,
22            closed: false,
23        }
24    }
25}
26
27impl<'a> Arg<'a> {
28    fn run(&self, client: &mut Client) -> Result<(Vec<u8>, i32), HglibError> {
29        runcommand!(
30            client,
31            "heads",
32            self.rev,
33            "-r",
34            self.startrev,
35            "-t",
36            self.topological,
37            "-c",
38            self.closed,
39            "--template",
40            common::CHANGESETS_TEMPLATE
41        )
42    }
43}
44
45impl Client {
46    pub fn heads(&mut self, x: Arg) -> Result<Vec<common::Revision>, HglibError> {
47        match x.run(self) {
48            Ok((data, _)) => common::parserevs(data),
49            Err(err) => {
50                if err.code == 1 {
51                    Ok(Vec::new())
52                } else {
53                    Err(err)
54                }
55            }
56        }
57    }
58}