hglib/commands/
log.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 revrange: &'a [&'a str],
11    pub files: &'a [&'a str],
12    pub follow: bool,
13    pub followfirst: bool,
14    pub date: &'a str,
15    pub copies: bool,
16    pub keyword: &'a [&'a str],
17    pub removed: bool,
18    pub onlymerges: bool,
19    pub user: &'a [&'a str],
20    pub branch: &'a [&'a str],
21    pub prune: &'a [&'a str],
22    pub hidden: bool,
23    pub limit: Option<u32>,
24    pub nomerges: bool,
25    pub include: &'a [&'a str],
26    pub exclude: &'a [&'a str],
27}
28
29impl<'a> Default for Arg<'a> {
30    fn default() -> Self {
31        Self {
32            revrange: &[],
33            files: &[],
34            follow: false,
35            followfirst: false,
36            date: "",
37            copies: false,
38            keyword: &[],
39            removed: false,
40            onlymerges: false,
41            user: &[],
42            branch: &[],
43            prune: &[],
44            hidden: false,
45            limit: None,
46            nomerges: false,
47            include: &[],
48            exclude: &[],
49        }
50    }
51}
52
53impl<'a> Arg<'a> {
54    fn run(&self, client: &mut Client) -> Result<(Vec<u8>, i32), HglibError> {
55        runcommand!(
56            client,
57            "log",
58            self.files,
59            "--template",
60            common::CHANGESETS_TEMPLATE,
61            "-r",
62            self.revrange,
63            "-f",
64            self.follow,
65            "--follow-first",
66            self.followfirst,
67            "-d",
68            self.date,
69            "-C",
70            self.copies,
71            "-k",
72            self.keyword,
73            "--removed",
74            self.removed,
75            "-m",
76            self.onlymerges,
77            "-u",
78            self.user,
79            "-b",
80            self.branch,
81            "-P",
82            self.prune,
83            "--hidden",
84            self.hidden,
85            "-l",
86            self.limit,
87            "-M",
88            self.nomerges,
89            "-I",
90            self.include,
91            "-X",
92            self.exclude
93        )
94    }
95}
96
97impl Client {
98    pub fn log<'a>(&mut self, x: Arg<'a>) -> Result<Vec<common::Revision>, HglibError> {
99        let (data, _) = x.run(self)?;
100        common::parserevs(data)
101    }
102}