hglib/commands/
export.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 crate::client::{Client, HglibError, Runner};
6use crate::{runcommand, MkArg};
7
8pub struct Arg<'a> {
9    pub revs: &'a [&'a str],
10    pub output: &'a str,
11    pub switchparent: bool,
12    pub text: bool,
13    pub git: bool,
14    pub nodates: bool,
15}
16
17impl<'a> Default for Arg<'a> {
18    fn default() -> Self {
19        Self {
20            revs: &[],
21            output: "",
22            switchparent: false,
23            text: false,
24            git: false,
25            nodates: false,
26        }
27    }
28}
29
30impl<'a> Arg<'a> {
31    fn run(&self, client: &mut Client) -> Result<(Vec<u8>, i32), HglibError> {
32        runcommand!(
33            client,
34            "export",
35            self.revs,
36            "-o",
37            self.output,
38            "--switch-parent",
39            self.switchparent,
40            "-a",
41            self.text,
42            "-g",
43            self.git,
44            "--nodates",
45            self.nodates
46        )
47    }
48}
49
50impl Client {
51    pub fn export(&mut self, x: Arg) -> Result<Option<Vec<u8>>, HglibError> {
52        Ok(if x.output.is_empty() {
53            let (data, _) = x.run(self)?;
54            Some(data)
55        } else {
56            None
57        })
58    }
59}