hglib/commands/
revert.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 files: &'a [&'a str],
10    pub rev: &'a [&'a str],
11    pub all: bool,
12    pub date: &'a str,
13    pub nobackup: bool,
14    pub dryrun: bool,
15    pub include: &'a [&'a str],
16    pub exclude: &'a [&'a str],
17}
18
19impl<'a> Default for Arg<'a> {
20    fn default() -> Self {
21        Self {
22            files: &[],
23            rev: &[],
24            all: false,
25            date: "",
26            nobackup: false,
27            dryrun: false,
28            include: &[],
29            exclude: &[],
30        }
31    }
32}
33
34impl<'a> Arg<'a> {
35    fn run(&self, client: &mut Client) -> Result<(Vec<u8>, i32), HglibError> {
36        runcommand!(
37            client,
38            "revert",
39            self.files,
40            "-r",
41            self.rev,
42            "-a",
43            self.all,
44            "-d",
45            self.date,
46            "--no-backup",
47            self.nobackup,
48            "-n",
49            self.dryrun,
50            "-I",
51            self.include,
52            "-X",
53            self.exclude
54        )
55    }
56}
57
58impl Client {
59    pub fn revert(&mut self, x: Arg) -> Result<bool, HglibError> {
60        HglibError::handle_err(x.run(self))
61    }
62}