Mercurial > hg
annotate rust/rhg/src/commands/debugrhgsparse.rs @ 49914:58074252db3c
rust: run `cargo clippy`
These automatic fixes are good to have because they make the code
more idiomatic and less surprising.
The transform from `sort` -> `sort_unstable` is questionable, but this is
only in a test, so it doesn't matter in our case.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 09 Jan 2023 17:40:03 +0100 |
parents | 37bc3edef76f |
children |
rev | line source |
---|---|
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
1 use std::{ |
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
2 ffi::{OsStr, OsString}, |
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
3 os::unix::prelude::OsStrExt, |
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
4 }; |
49484
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 use crate::error::CommandError; |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 use hg::{self, utils::hg_path::HgPath}; |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 pub const HELP_TEXT: &str = ""; |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
11 pub fn args() -> clap::Command { |
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
12 clap::command!("debugrhgsparse") |
49484
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 .arg( |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
14 clap::Arg::new("files") |
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
15 .value_name("FILES") |
49484
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 .required(true) |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
17 .num_args(1..) |
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
18 .value_parser(clap::value_parser!(std::ffi::OsString)) |
49484
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 .help("Files to check against sparse profile"), |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 ) |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 .about(HELP_TEXT) |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 } |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 let repo = invocation.repo?; |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 |
49914
58074252db3c
rust: run `cargo clippy`
Raphaël Gomès <rgomes@octobus.net>
parents:
49640
diff
changeset
|
27 let (matcher, _warnings) = hg::sparse::matcher(repo).unwrap(); |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
28 let files = invocation.subcommand_args.get_many::<OsString>("files"); |
49484
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 if let Some(files) = files { |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
30 let files: Vec<&OsStr> = files |
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
31 .filter(|s| !s.is_empty()) |
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
32 .map(|s| s.as_os_str()) |
37bc3edef76f
rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents:
49484
diff
changeset
|
33 .collect(); |
49484
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 for file in files { |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 invocation.ui.write_stdout(b"matches: ")?; |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 invocation.ui.write_stdout( |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 if matcher.matches(HgPath::new(file.as_bytes())) { |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 b"yes" |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 } else { |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 b"no" |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 }, |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 )?; |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 invocation.ui.write_stdout(b" | file: ")?; |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 invocation.ui.write_stdout(file.as_bytes())?; |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 invocation.ui.write_stdout(b"\n")?; |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 } |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 } |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 Ok(()) |
85f5d11c77dd
rhg: add debugrhgsparse command to help figure out bugs in rhg
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 } |