author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Thu, 02 Jan 2025 14:50:06 +0100 | |
changeset 52592 | 87ceb51d124c |
parent 52343 | 393ad2685fb4 |
permissions | -rw-r--r-- |
46434
3e2d539d0d1a
rust: remove `FooError` structs with only `kind: FooErrorKind` enum field
Simon Sapin <simon.sapin@octobus.net>
parents:
46167
diff
changeset
|
1 |
use crate::error::CommandError; |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
2 |
use clap::Arg; |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
3 |
use clap::ArgGroup; |
51863
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51117
diff
changeset
|
4 |
use hg::operations::debug_data; |
52178
bd8081e9fd62
rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51863
diff
changeset
|
5 |
use hg::revlog::RevlogType; |
45528
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
6 |
|
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
7 |
pub const HELP_TEXT: &str = " |
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
8 |
Dump the contents of a data file revision |
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
9 |
"; |
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
10 |
|
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
11 |
pub fn args() -> clap::Command { |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
12 |
clap::command!("debugdata") |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
13 |
.arg( |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
14 |
Arg::new("changelog") |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
15 |
.help("open changelog") |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
16 |
.short('c') |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
17 |
.action(clap::ArgAction::SetTrue), |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
18 |
) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
19 |
.arg( |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
20 |
Arg::new("manifest") |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
21 |
.help("open manifest") |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
22 |
.short('m') |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
23 |
.action(clap::ArgAction::SetTrue), |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
24 |
) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
25 |
.group( |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
26 |
ArgGroup::new("revlog") |
51117
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49913
diff
changeset
|
27 |
.args(["changelog", "manifest"]) |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
28 |
.required(true), |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
29 |
) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
30 |
.arg( |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
31 |
Arg::new("rev") |
46501
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
32 |
.help("revision") |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
33 |
.required(true) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
34 |
.value_name("REV"), |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
35 |
) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
36 |
.about(HELP_TEXT) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
37 |
} |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46500
diff
changeset
|
38 |
|
49913
c15b415d1bff
rust: use `logging_timer` instead of `micro_timer`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49640
diff
changeset
|
39 |
#[logging_timer::time("trace")] |
46592
80840b651721
rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46503
diff
changeset
|
40 |
pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
80840b651721
rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46503
diff
changeset
|
41 |
let args = invocation.subcommand_args; |
46500
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
42 |
let rev = args |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
43 |
.get_one::<String>("rev") |
46500
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
44 |
.expect("rev should be a required argument"); |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
45 |
let kind = match ( |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
46 |
args.get_one::<bool>("changelog").unwrap(), |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
47 |
args.get_one::<bool>("manifest").unwrap(), |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
48 |
) { |
51863
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51117
diff
changeset
|
49 |
(true, false) => RevlogType::Changelog, |
69b804c8e09e
rust: use new revlog configs in all revlog opening code
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51117
diff
changeset
|
50 |
(false, true) => RevlogType::Manifestlog, |
49640
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
51 |
(true, true) => { |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
52 |
unreachable!("Should not happen since options are exclusive") |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
53 |
} |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
54 |
(false, false) => { |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
55 |
unreachable!("Should not happen since options are required") |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
56 |
} |
37bc3edef76f
rhg: upgrade `clap` dependency
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49480
diff
changeset
|
57 |
}; |
45528
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
58 |
|
46593
5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46592
diff
changeset
|
59 |
let repo = invocation.repo?; |
49480
0199712c7a6d
rhg: fallback in `debugdata` if repo has `narrow`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46593
diff
changeset
|
60 |
if repo.has_narrow() { |
0199712c7a6d
rhg: fallback in `debugdata` if repo has `narrow`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46593
diff
changeset
|
61 |
return Err(CommandError::unsupported( |
0199712c7a6d
rhg: fallback in `debugdata` if repo has `narrow`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46593
diff
changeset
|
62 |
"support for ellipsis nodes is missing and repo has narrow enabled", |
0199712c7a6d
rhg: fallback in `debugdata` if repo has `narrow`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46593
diff
changeset
|
63 |
)); |
0199712c7a6d
rhg: fallback in `debugdata` if repo has `narrow`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46593
diff
changeset
|
64 |
} |
52343
393ad2685fb4
rust: make RevlogError AmbiguousPrefix case contain the actual prefix
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
52178
diff
changeset
|
65 |
let data = debug_data(repo, rev, kind)?; |
45528
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
66 |
|
46592
80840b651721
rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46503
diff
changeset
|
67 |
let mut stdout = invocation.ui.stdout_buffer(); |
46500
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
68 |
stdout.write_all(&data)?; |
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
69 |
stdout.flush()?; |
45528
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
70 |
|
46500
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
71 |
Ok(()) |
45528
66756b34c06e
rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
72 |
} |