annotate rust/rhg/src/main.rs @ 49420:3a53871048dc stable

rhg: fix bugs around [use-dirstate-tracked-hint] and repo auto-upgrade This makes two changes: - make rhg support the [dirstate-tracked-key-v1] requirement. I believe rhg never changes the tracked file set, so it's OK that it doesn't have any logic for writing this file. - fix the name of [format.use-dirstate-v2.automatic-upgrade-of-mismatching-repositories] config option in rhg, which makes rhg actually honor the auto-upgrade. These two issues cancelled each other out in tests (auto-upgrade was happening because [dirstate-tracked-key-v1] forced the fallback, not because of the config), which is I think why they went unnoticed earlier.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 22 Sep 2022 16:05:22 -0400
parents 411d591e0a27
children 44bc045a43ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45536
b1cea0dc9db0 rhg: Add debug timing
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45535
diff changeset
1 extern crate log;
48385
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
2 use crate::error::CommandError;
48773
f19be290756a rhg: signal when falling back in logs
Raphaël Gomès <rgomes@octobus.net>
parents: 48744
diff changeset
3 use crate::ui::{local_to_utf8, Ui};
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
4 use clap::App;
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
5 use clap::AppSettings;
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
6 use clap::Arg;
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
7 use clap::ArgMatches;
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
8 use format_bytes::{format_bytes, join};
47410
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
9 use hg::config::{Config, ConfigSource};
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
10 use hg::repo::{Repo, RepoError};
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
11 use hg::utils::files::{get_bytes_from_os_str, get_path_from_bytes};
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
12 use hg::utils::SliceExt;
49224
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
13 use hg::{exit_codes, requirements};
48480
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
14 use std::collections::HashSet;
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
15 use std::ffi::OsString;
48846
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
16 use std::os::unix::prelude::CommandExt;
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
17 use std::path::PathBuf;
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
18 use std::process::Command;
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
19
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
20 mod blackbox;
48743
39c447e03dbc rhg: Add support for colored output
Simon Sapin <simon.sapin@octobus.net>
parents: 48742
diff changeset
21 mod color;
45002
bacf6c7ef01b rhg: add Command trait for subcommands implemented by rhg
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45001
diff changeset
22 mod error;
45050
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45002
diff changeset
23 mod ui;
48186
9ecf802b06e0 rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48091
diff changeset
24 pub mod utils {
9ecf802b06e0 rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48091
diff changeset
25 pub mod path_utils;
9ecf802b06e0 rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48091
diff changeset
26 }
45001
cf04f62d1579 rhg: add rhg crate
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
27
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
28 fn main_with_result(
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
29 argv: Vec<OsString>,
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
30 process_start_time: &blackbox::ProcessStartTime,
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
31 ui: &ui::Ui,
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
32 repo: Result<&Repo, &NoRepoInCwdError>,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
33 config: &Config,
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
34 ) -> Result<(), CommandError> {
48744
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48743
diff changeset
35 check_unsupported(config, repo)?;
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
36
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
37 let app = App::new("rhg")
46647
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
38 .global_setting(AppSettings::AllowInvalidUtf8)
46759
eb14264b98e8 rhg: Fall back to Python for --version
Simon Sapin <simon.sapin@octobus.net>
parents: 46757
diff changeset
39 .global_setting(AppSettings::DisableVersion)
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
40 .setting(AppSettings::SubcommandRequired)
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
41 .setting(AppSettings::VersionlessSubcommands)
46647
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
42 .arg(
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
43 Arg::with_name("repository")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
44 .help("repository root directory")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
45 .short("-R")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
46 .long("--repository")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
47 .value_name("REPO")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
48 .takes_value(true)
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
49 // Both ok: `hg -R ./foo log` or `hg log -R ./foo`
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
50 .global(true),
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
51 )
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
52 .arg(
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
53 Arg::with_name("config")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
54 .help("set/override config option (use 'section.name=value')")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
55 .long("--config")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
56 .value_name("CONFIG")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
57 .takes_value(true)
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
58 .global(true)
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
59 // Ok: `--config section.key1=val --config section.key2=val2`
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
60 .multiple(true)
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
61 // Not ok: `--config section.key1=val section.key2=val2`
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
62 .number_of_values(1),
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
63 )
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
64 .arg(
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
65 Arg::with_name("cwd")
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
66 .help("change working directory")
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
67 .long("--cwd")
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
68 .value_name("DIR")
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
69 .takes_value(true)
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
70 .global(true),
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
71 )
48742
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
72 .arg(
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
73 Arg::with_name("color")
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
74 .help("when to colorize (boolean, always, auto, never, or debug)")
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
75 .long("--color")
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
76 .value_name("TYPE")
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
77 .takes_value(true)
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
78 .global(true),
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
79 )
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
80 .version("0.0.1");
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
81 let app = add_subcommand_args(app);
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
82
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
83 let matches = app.clone().get_matches_from_safe(argv.iter())?;
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
84
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
85 let (subcommand_name, subcommand_matches) = matches.subcommand();
48089
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
86
48090
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
87 // Mercurial allows users to define "defaults" for commands, fallback
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
88 // if a default is detected for the current command
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
89 let defaults = config.get_str(b"defaults", subcommand_name.as_bytes());
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
90 if defaults?.is_some() {
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
91 let msg = "`defaults` config set";
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
92 return Err(CommandError::unsupported(msg));
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
93 }
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
94
48089
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
95 for prefix in ["pre", "post", "fail"].iter() {
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
96 // Mercurial allows users to define generic hooks for commands,
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
97 // fallback if any are detected
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
98 let item = format!("{}-{}", prefix, subcommand_name);
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
99 let hook_for_command = config.get_str(b"hooks", item.as_bytes())?;
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
100 if hook_for_command.is_some() {
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
101 let msg = format!("{}-{} hook defined", prefix, subcommand_name);
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
102 return Err(CommandError::unsupported(msg));
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
103 }
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
104 }
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
105 let run = subcommand_run_fn(subcommand_name)
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
106 .expect("unknown subcommand name from clap despite AppSettings::SubcommandRequired");
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
107 let subcommand_args = subcommand_matches
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
108 .expect("no subcommand arguments from clap despite AppSettings::SubcommandRequired");
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
109
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
110 let invocation = CliInvocation {
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
111 ui,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
112 subcommand_args,
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
113 config,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
114 repo,
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
115 };
48091
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
116
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
117 if let Ok(repo) = repo {
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
118 // We don't support subrepos, fallback if the subrepos file is present
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
119 if repo.working_directory_vfs().join(".hgsub").exists() {
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
120 let msg = "subrepos (.hgsub is present)";
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
121 return Err(CommandError::unsupported(msg));
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
122 }
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
123 }
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
124
48461
9ff246cd6200 rhg: don't run `blackbox` if not activated
Raphaël Gomès <rgomes@octobus.net>
parents: 48457
diff changeset
125 if config.is_extension_enabled(b"blackbox") {
9ff246cd6200 rhg: don't run `blackbox` if not activated
Raphaël Gomès <rgomes@octobus.net>
parents: 48457
diff changeset
126 let blackbox =
9ff246cd6200 rhg: don't run `blackbox` if not activated
Raphaël Gomès <rgomes@octobus.net>
parents: 48457
diff changeset
127 blackbox::Blackbox::new(&invocation, process_start_time)?;
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
128 blackbox.log_command_start(argv.iter());
48461
9ff246cd6200 rhg: don't run `blackbox` if not activated
Raphaël Gomès <rgomes@octobus.net>
parents: 48457
diff changeset
129 let result = run(&invocation);
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
130 blackbox.log_command_end(
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
131 argv.iter(),
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
132 exit_code(
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
133 &result,
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
134 // TODO: show a warning or combine with original error if
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
135 // `get_bool` returns an error
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
136 config
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
137 .get_bool(b"ui", b"detailed-exit-code")
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
138 .unwrap_or(false),
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
139 ),
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
140 );
48461
9ff246cd6200 rhg: don't run `blackbox` if not activated
Raphaël Gomès <rgomes@octobus.net>
parents: 48457
diff changeset
141 result
9ff246cd6200 rhg: don't run `blackbox` if not activated
Raphaël Gomès <rgomes@octobus.net>
parents: 48457
diff changeset
142 } else {
9ff246cd6200 rhg: don't run `blackbox` if not activated
Raphaël Gomès <rgomes@octobus.net>
parents: 48457
diff changeset
143 run(&invocation)
9ff246cd6200 rhg: don't run `blackbox` if not activated
Raphaël Gomès <rgomes@octobus.net>
parents: 48457
diff changeset
144 }
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
145 }
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
146
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
147 fn rhg_main(argv: Vec<OsString>) -> ! {
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
148 // Run this first, before we find out if the blackbox extension is even
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
149 // enabled, in order to include everything in-between in the duration
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
150 // measurements. Reading config files can be slow if they’re on NFS.
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
151 let process_start_time = blackbox::ProcessStartTime::now();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
152
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
153 env_logger::init();
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
154
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
155 let early_args = EarlyArgs::parse(&argv);
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
156
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
157 let initial_current_dir = early_args.cwd.map(|cwd| {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
158 let cwd = get_path_from_bytes(&cwd);
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
159 std::env::current_dir()
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
160 .and_then(|initial| {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
161 std::env::set_current_dir(cwd)?;
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
162 Ok(initial)
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
163 })
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
164 .unwrap_or_else(|error| {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
165 exit(
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
166 &argv,
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
167 &None,
48741
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
168 &Ui::new_infallible(&Config::empty()),
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
169 OnUnsupported::Abort,
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
170 Err(CommandError::abort(format!(
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
171 "abort: {}: '{}'",
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
172 error,
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
173 cwd.display()
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
174 ))),
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
175 false,
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
176 )
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
177 })
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
178 });
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
179
47412
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
180 let mut non_repo_config =
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
181 Config::load_non_repo().unwrap_or_else(|error| {
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
182 // Normally this is decided based on config, but we don’t have that
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
183 // available. As of this writing config loading never returns an
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
184 // "unsupported" error but that is not enforced by the type system.
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
185 let on_unsupported = OnUnsupported::Abort;
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
186
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
187 exit(
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
188 &argv,
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
189 &initial_current_dir,
48741
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
190 &Ui::new_infallible(&Config::empty()),
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
191 on_unsupported,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
192 Err(error.into()),
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
193 false,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
194 )
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
195 });
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
196
47412
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
197 non_repo_config
48742
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
198 .load_cli_args(early_args.config, early_args.color)
47412
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
199 .unwrap_or_else(|error| {
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
200 exit(
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
201 &argv,
47412
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
202 &initial_current_dir,
48741
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
203 &Ui::new_infallible(&non_repo_config),
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
204 OnUnsupported::from_config(&non_repo_config),
47412
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
205 Err(error.into()),
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
206 non_repo_config
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
207 .get_bool(b"ui", b"detailed-exit-code")
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
208 .unwrap_or(false),
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
209 )
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
210 });
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
211
46742
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
212 if let Some(repo_path_bytes) = &early_args.repo {
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
213 lazy_static::lazy_static! {
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
214 static ref SCHEME_RE: regex::bytes::Regex =
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
215 // Same as `_matchscheme` in `mercurial/util.py`
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
216 regex::bytes::Regex::new("^[a-zA-Z0-9+.\\-]+:").unwrap();
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
217 }
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
218 if SCHEME_RE.is_match(&repo_path_bytes) {
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
219 exit(
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
220 &argv,
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
221 &initial_current_dir,
48741
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
222 &Ui::new_infallible(&non_repo_config),
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
223 OnUnsupported::from_config(&non_repo_config),
46742
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
224 Err(CommandError::UnsupportedFeature {
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
225 message: format_bytes!(
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
226 b"URL-like --repository {}",
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
227 repo_path_bytes
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
228 ),
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
229 }),
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
230 // TODO: show a warning or combine with original error if
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
231 // `get_bool` returns an error
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
232 non_repo_config
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
233 .get_bool(b"ui", b"detailed-exit-code")
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
234 .unwrap_or(false),
46742
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
235 )
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
236 }
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
237 }
47410
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
238 let repo_arg = early_args.repo.unwrap_or(Vec::new());
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
239 let repo_path: Option<PathBuf> = {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
240 if repo_arg.is_empty() {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
241 None
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
242 } else {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
243 let local_config = {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
244 if std::env::var_os("HGRCSKIPREPO").is_none() {
47411
88119fffecc8 rhg: look for repository in ancestors also instead of cwd only
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47410
diff changeset
245 // TODO: handle errors from find_repo_root
88119fffecc8 rhg: look for repository in ancestors also instead of cwd only
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47410
diff changeset
246 if let Ok(current_dir_path) = Repo::find_repo_root() {
47410
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
247 let config_files = vec![
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
248 ConfigSource::AbsPath(
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
249 current_dir_path.join(".hg/hgrc"),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
250 ),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
251 ConfigSource::AbsPath(
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
252 current_dir_path.join(".hg/hgrc-not-shared"),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
253 ),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
254 ];
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
255 // TODO: handle errors from
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
256 // `load_from_explicit_sources`
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
257 Config::load_from_explicit_sources(config_files).ok()
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
258 } else {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
259 None
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
260 }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
261 } else {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
262 None
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
263 }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
264 };
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
265
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
266 let non_repo_config_val = {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
267 let non_repo_val = non_repo_config.get(b"paths", &repo_arg);
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
268 match &non_repo_val {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
269 Some(val) if val.len() > 0 => home::home_dir()
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
270 .unwrap_or_else(|| PathBuf::from("~"))
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
271 .join(get_path_from_bytes(val))
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
272 .canonicalize()
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
273 // TODO: handle error and make it similar to python
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
274 // implementation maybe?
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
275 .ok(),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
276 _ => None,
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
277 }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
278 };
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
279
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
280 let config_val = match &local_config {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
281 None => non_repo_config_val,
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
282 Some(val) => {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
283 let local_config_val = val.get(b"paths", &repo_arg);
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
284 match &local_config_val {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
285 Some(val) if val.len() > 0 => {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
286 // presence of a local_config assures that
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
287 // current_dir
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
288 // wont result in an Error
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
289 let canpath = hg::utils::current_dir()
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
290 .unwrap()
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
291 .join(get_path_from_bytes(val))
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
292 .canonicalize();
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
293 canpath.ok().or(non_repo_config_val)
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
294 }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
295 _ => non_repo_config_val,
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
296 }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
297 }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
298 };
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
299 config_val.or(Some(get_path_from_bytes(&repo_arg).to_path_buf()))
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
300 }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
301 };
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
302
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
303 let repo_result = match Repo::find(&non_repo_config, repo_path.to_owned())
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
304 {
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
305 Ok(repo) => Ok(repo),
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
306 Err(RepoError::NotFound { at }) if repo_path.is_none() => {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
307 // Not finding a repo is not fatal yet, if `-R` was not given
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
308 Err(NoRepoInCwdError { cwd: at })
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
309 }
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
310 Err(error) => exit(
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
311 &argv,
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
312 &initial_current_dir,
48741
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
313 &Ui::new_infallible(&non_repo_config),
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
314 OnUnsupported::from_config(&non_repo_config),
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
315 Err(error.into()),
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
316 // TODO: show a warning or combine with original error if
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
317 // `get_bool` returns an error
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
318 non_repo_config
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
319 .get_bool(b"ui", b"detailed-exit-code")
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
320 .unwrap_or(false),
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
321 ),
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
322 };
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
323
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
324 let config = if let Ok(repo) = &repo_result {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
325 repo.config()
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
326 } else {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
327 &non_repo_config
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
328 };
48741
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
329 let ui = Ui::new(&config).unwrap_or_else(|error| {
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
330 exit(
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
331 &argv,
48741
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
332 &initial_current_dir,
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
333 &Ui::new_infallible(&config),
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
334 OnUnsupported::from_config(&config),
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
335 Err(error.into()),
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
336 config
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
337 .get_bool(b"ui", b"detailed-exit-code")
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
338 .unwrap_or(false),
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
339 )
f591b377375f rhg: Make Ui::new falliable, add Ui::new_infallible
Simon Sapin <simon.sapin@octobus.net>
parents: 48740
diff changeset
340 });
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
341 let on_unsupported = OnUnsupported::from_config(config);
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
342
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
343 let result = main_with_result(
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
344 argv.iter().map(|s| s.to_owned()).collect(),
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
345 &process_start_time,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
346 &ui,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
347 repo_result.as_ref(),
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
348 config,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
349 );
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
350 exit(
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
351 &argv,
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
352 &initial_current_dir,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
353 &ui,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
354 on_unsupported,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
355 result,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
356 // TODO: show a warning or combine with original error if `get_bool`
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
357 // returns an error
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
358 config
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
359 .get_bool(b"ui", b"detailed-exit-code")
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
360 .unwrap_or(false),
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
361 )
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
362 }
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
363
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
364 fn main() -> ! {
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
365 rhg_main(std::env::args_os().collect())
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
366 }
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
367
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
368 fn exit_code(
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
369 result: &Result<(), CommandError>,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
370 use_detailed_exit_code: bool,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
371 ) -> i32 {
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
372 match result {
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
373 Ok(()) => exit_codes::OK,
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
374 Err(CommandError::Abort {
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
375 message: _,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
376 detailed_exit_code,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
377 }) => {
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
378 if use_detailed_exit_code {
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
379 *detailed_exit_code
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
380 } else {
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
381 exit_codes::ABORT
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
382 }
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
383 }
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
384 Err(CommandError::Unsuccessful) => exit_codes::UNSUCCESSFUL,
46513
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
385 // Exit with a specific code and no error message to let a potential
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
386 // wrapper script fallback to Python-based Mercurial.
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
387 Err(CommandError::UnsupportedFeature { .. }) => {
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
388 exit_codes::UNIMPLEMENTED
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
389 }
48846
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
390 Err(CommandError::InvalidFallback { .. }) => {
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
391 exit_codes::INVALID_FALLBACK
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
392 }
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
393 }
45001
cf04f62d1579 rhg: add rhg crate
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
394 }
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
395
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
396 fn exit<'a>(
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
397 original_args: &'a [OsString],
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
398 initial_current_dir: &Option<PathBuf>,
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
399 ui: &Ui,
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
400 mut on_unsupported: OnUnsupported,
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
401 result: Result<(), CommandError>,
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
402 use_detailed_exit_code: bool,
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
403 ) -> ! {
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
404 if let (
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
405 OnUnsupported::Fallback { executable },
48773
f19be290756a rhg: signal when falling back in logs
Raphaël Gomès <rgomes@octobus.net>
parents: 48744
diff changeset
406 Err(CommandError::UnsupportedFeature { message }),
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
407 ) = (&on_unsupported, &result)
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
408 {
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
409 let mut args = original_args.iter();
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
410 let executable = match executable {
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
411 None => {
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
412 exit_no_fallback(
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
413 ui,
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
414 OnUnsupported::Abort,
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
415 Err(CommandError::abort(
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
416 "abort: 'rhg.on-unsupported=fallback' without \
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
417 'rhg.fallback-executable' set.",
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
418 )),
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
419 false,
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
420 );
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
421 }
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
422 Some(executable) => executable,
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
423 };
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
424 let executable_path = get_path_from_bytes(&executable);
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
425 let this_executable = args.next().expect("exepcted argv[0] to exist");
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
426 if executable_path == &PathBuf::from(this_executable) {
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
427 // Avoid spawning infinitely many processes until resource
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
428 // exhaustion.
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
429 let _ = ui.write_stderr(&format_bytes!(
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
430 b"Blocking recursive fallback. The 'rhg.fallback-executable = {}' config \
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
431 points to `rhg` itself.\n",
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
432 executable
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
433 ));
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
434 on_unsupported = OnUnsupported::Abort
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
435 } else {
48773
f19be290756a rhg: signal when falling back in logs
Raphaël Gomès <rgomes@octobus.net>
parents: 48744
diff changeset
436 log::debug!("falling back (see trace-level log)");
f19be290756a rhg: signal when falling back in logs
Raphaël Gomès <rgomes@octobus.net>
parents: 48744
diff changeset
437 log::trace!("{}", local_to_utf8(message));
48846
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
438 if let Err(err) = which::which(executable_path) {
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
439 exit_no_fallback(
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
440 ui,
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
441 OnUnsupported::Abort,
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
442 Err(CommandError::InvalidFallback {
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
443 path: executable.to_owned(),
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
444 err: err.to_string(),
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
445 }),
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
446 use_detailed_exit_code,
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
447 )
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
448 }
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
449 // `args` is now `argv[1..]` since we’ve already consumed
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
450 // `argv[0]`
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
451 let mut command = Command::new(executable_path);
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
452 command.args(args);
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
453 if let Some(initial) = initial_current_dir {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
454 command.current_dir(initial);
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
455 }
48846
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
456 // We don't use subprocess because proper signal handling is harder
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
457 // and we don't want to keep `rhg` around after a fallback anyway.
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
458 // For example, if `rhg` is run in the background and falls back to
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
459 // `hg` which, in turn, waits for a signal, we'll get stuck if
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
460 // we're doing plain subprocess.
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
461 //
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
462 // If `exec` returns, we can only assume our process is very broken
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
463 // (see its documentation), so only try to forward the error code
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
464 // when exiting.
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
465 let err = command.exec();
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
466 std::process::exit(
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
467 err.raw_os_error().unwrap_or(exit_codes::ABORT),
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
468 );
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
469 }
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
470 }
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
471 exit_no_fallback(ui, on_unsupported, result, use_detailed_exit_code)
46761
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
472 }
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
473
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
474 fn exit_no_fallback(
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
475 ui: &Ui,
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
476 on_unsupported: OnUnsupported,
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
477 result: Result<(), CommandError>,
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
478 use_detailed_exit_code: bool,
46761
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
479 ) -> ! {
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
480 match &result {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
481 Ok(_) => {}
46757
b1f2c2b336ec rhg: `cat` command: print error messages for missing files
Simon Sapin <simon.sapin@octobus.net>
parents: 46749
diff changeset
482 Err(CommandError::Unsuccessful) => {}
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
483 Err(CommandError::Abort {
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
484 message,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
485 detailed_exit_code: _,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
486 }) => {
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
487 if !message.is_empty() {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
488 // Ignore errors when writing to stderr, we’re already exiting
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
489 // with failure code so there’s not much more we can do.
46744
3d692e724d06 rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46742
diff changeset
490 let _ = ui.write_stderr(&format_bytes!(b"{}\n", message));
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
491 }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
492 }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
493 Err(CommandError::UnsupportedFeature { message }) => {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
494 match on_unsupported {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
495 OnUnsupported::Abort => {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
496 let _ = ui.write_stderr(&format_bytes!(
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
497 b"unsupported feature: {}\n",
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
498 message
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
499 ));
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
500 }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
501 OnUnsupported::AbortSilent => {}
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
502 OnUnsupported::Fallback { .. } => unreachable!(),
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
503 }
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
504 }
48846
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
505 Err(CommandError::InvalidFallback { path, err }) => {
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
506 let _ = ui.write_stderr(&format_bytes!(
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
507 b"abort: invalid fallback '{}': {}\n",
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
508 path,
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
509 err.as_bytes(),
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
510 ));
006688e36e12 rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
511 }
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
512 }
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
513 std::process::exit(exit_code(&result, use_detailed_exit_code))
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
514 }
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
515
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
516 macro_rules! subcommands {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
517 ($( $command: ident )+) => {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
518 mod commands {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
519 $(
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
520 pub mod $command;
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
521 )+
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
522 }
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
523
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
524 fn add_subcommand_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
525 app
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
526 $(
46647
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
527 .subcommand(commands::$command::args())
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
528 )+
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
529 }
46543
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46513
diff changeset
530
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
531 pub type RunFn = fn(&CliInvocation) -> Result<(), CommandError>;
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
532
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
533 fn subcommand_run_fn(name: &str) -> Option<RunFn> {
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
534 match name {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
535 $(
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
536 stringify!($command) => Some(commands::$command::run),
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
537 )+
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
538 _ => None,
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
539 }
45548
33ded2d3f4fc rhg: add a limited `rhg cat -r` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45543
diff changeset
540 }
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
541 };
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
542 }
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
543
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
544 subcommands! {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
545 cat
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
546 debugdata
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
547 debugrequirements
48403
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48401
diff changeset
548 debugignorerhg
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
549 files
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
550 root
46557
a25033eb43b5 rhg: add limited support for the `config` sub-command
Simon Sapin <simon.sapin@octobus.net>
parents: 46556
diff changeset
551 config
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents: 46820
diff changeset
552 status
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
553 }
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents: 46820
diff changeset
554
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
555 pub struct CliInvocation<'a> {
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
556 ui: &'a Ui,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
557 subcommand_args: &'a ArgMatches<'a>,
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
558 config: &'a Config,
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
559 /// References inside `Result` is a bit peculiar but allow
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
560 /// `invocation.repo?` to work out with `&CliInvocation` since this
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
561 /// `Result` type is `Copy`.
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
562 repo: Result<&'a Repo, &'a NoRepoInCwdError>,
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
563 }
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
564
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
565 struct NoRepoInCwdError {
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
566 cwd: PathBuf,
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
567 }
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
568
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
569 /// CLI arguments to be parsed "early" in order to be able to read
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
570 /// configuration before using Clap. Ideally we would also use Clap for this,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
571 /// see <https://github.com/clap-rs/clap/discussions/2366>.
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
572 ///
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
573 /// These arguments are still declared when we do use Clap later, so that Clap
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
574 /// does not return an error for their presence.
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
575 struct EarlyArgs {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
576 /// Values of all `--config` arguments. (Possibly none)
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
577 config: Vec<Vec<u8>>,
48742
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
578 /// Value of all the `--color` argument, if any.
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
579 color: Option<Vec<u8>>,
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
580 /// Value of the `-R` or `--repository` argument, if any.
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
581 repo: Option<Vec<u8>>,
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
582 /// Value of the `--cwd` argument, if any.
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
583 cwd: Option<Vec<u8>>,
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
584 }
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
585
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
586 impl EarlyArgs {
49125
137a93125902 rhg: refactor to pass argv down, instead of caling args_os()
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49064
diff changeset
587 fn parse<'a>(args: impl IntoIterator<Item = &'a OsString>) -> Self {
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
588 let mut args = args.into_iter().map(get_bytes_from_os_str);
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
589 let mut config = Vec::new();
48742
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
590 let mut color = None;
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
591 let mut repo = None;
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
592 let mut cwd = None;
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
593 // Use `while let` instead of `for` so that we can also call
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
594 // `args.next()` inside the loop.
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
595 while let Some(arg) = args.next() {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
596 if arg == b"--config" {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
597 if let Some(value) = args.next() {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
598 config.push(value)
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
599 }
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
600 } else if let Some(value) = arg.drop_prefix(b"--config=") {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
601 config.push(value.to_owned())
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
602 }
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
603
48742
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
604 if arg == b"--color" {
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
605 if let Some(value) = args.next() {
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
606 color = Some(value)
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
607 }
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
608 } else if let Some(value) = arg.drop_prefix(b"--color=") {
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
609 color = Some(value.to_owned())
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
610 }
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
611
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
612 if arg == b"--cwd" {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
613 if let Some(value) = args.next() {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
614 cwd = Some(value)
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
615 }
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
616 } else if let Some(value) = arg.drop_prefix(b"--cwd=") {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
617 cwd = Some(value.to_owned())
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
618 }
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
619
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
620 if arg == b"--repository" || arg == b"-R" {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
621 if let Some(value) = args.next() {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
622 repo = Some(value)
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
623 }
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
624 } else if let Some(value) = arg.drop_prefix(b"--repository=") {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
625 repo = Some(value.to_owned())
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
626 } else if let Some(value) = arg.drop_prefix(b"-R") {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
627 repo = Some(value.to_owned())
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
628 }
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
629 }
48742
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
630 Self {
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
631 config,
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
632 color,
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
633 repo,
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
634 cwd,
d4a5c2197208 rhg: Add parsing for the --color global CLI argument
Simon Sapin <simon.sapin@octobus.net>
parents: 48741
diff changeset
635 }
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
636 }
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
637 }
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
638
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
639 /// What to do when encountering some unsupported feature.
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
640 ///
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
641 /// See `HgError::UnsupportedFeature` and `CommandError::UnsupportedFeature`.
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
642 enum OnUnsupported {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
643 /// Print an error message describing what feature is not supported,
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
644 /// and exit with code 252.
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
645 Abort,
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
646 /// Silently exit with code 252.
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
647 AbortSilent,
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
648 /// Try running a Python implementation
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
649 Fallback { executable: Option<Vec<u8>> },
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
650 }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
651
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
652 impl OnUnsupported {
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
653 const DEFAULT: Self = OnUnsupported::Abort;
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
654
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
655 fn from_config(config: &Config) -> Self {
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
656 match config
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
657 .get(b"rhg", b"on-unsupported")
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
658 .map(|value| value.to_ascii_lowercase())
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
659 .as_deref()
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
660 {
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
661 Some(b"abort") => OnUnsupported::Abort,
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
662 Some(b"abort-silent") => OnUnsupported::AbortSilent,
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
663 Some(b"fallback") => OnUnsupported::Fallback {
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
664 executable: config
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
665 .get(b"rhg", b"fallback-executable")
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
666 .map(|x| x.to_owned()),
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
667 },
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
668 None => Self::DEFAULT,
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
669 Some(_) => {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
670 // TODO: warn about unknown config value
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
671 Self::DEFAULT
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
672 }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
673 }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
674 }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
675 }
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
676
48480
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
677 /// The `*` extension is an edge-case for config sub-options that apply to all
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
678 /// extensions. For now, only `:required` exists, but that may change in the
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
679 /// future.
48457
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48403
diff changeset
680 const SUPPORTED_EXTENSIONS: &[&[u8]] =
48480
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
681 &[b"blackbox", b"share", b"sparse", b"narrow", b"*"];
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
682
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
683 fn check_extensions(config: &Config) -> Result<(), CommandError> {
49058
6b31c0676147 rhg: add support for ignoring all extensions
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
684 if let Some(b"*") = config.get(b"rhg", b"ignored-extensions") {
6b31c0676147 rhg: add support for ignoring all extensions
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
685 // All extensions are to be ignored, nothing to do here
6b31c0676147 rhg: add support for ignoring all extensions
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
686 return Ok(());
6b31c0676147 rhg: add support for ignoring all extensions
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
687 }
6b31c0676147 rhg: add support for ignoring all extensions
Raphaël Gomès <rgomes@octobus.net>
parents: 48773
diff changeset
688
48480
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
689 let enabled: HashSet<&[u8]> = config
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
690 .get_section_keys(b"extensions")
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
691 .into_iter()
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
692 .map(|extension| {
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
693 // Ignore extension suboptions. Only `required` exists for now.
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
694 // `rhg` either supports an extension or doesn't, so it doesn't
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
695 // make sense to consider the loading of an extension.
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
696 extension.split_2(b':').unwrap_or((extension, b"")).0
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
697 })
9cf5ac8c7109 rhg: support the new extension suboptions syntax
Raphaël Gomès <rgomes@octobus.net>
parents: 48461
diff changeset
698 .collect();
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
699
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
700 let mut unsupported = enabled;
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
701 for supported in SUPPORTED_EXTENSIONS {
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
702 unsupported.remove(supported);
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
703 }
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
704
47979
cff41e168c25 rhg: Switch rhg.ignored-extensions config to Python-compatible list syntax
Simon Sapin <simon.sapin@octobus.net>
parents: 47413
diff changeset
705 if let Some(ignored_list) = config.get_list(b"rhg", b"ignored-extensions")
46747
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
706 {
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
707 for ignored in ignored_list {
47979
cff41e168c25 rhg: Switch rhg.ignored-extensions config to Python-compatible list syntax
Simon Sapin <simon.sapin@octobus.net>
parents: 47413
diff changeset
708 unsupported.remove(ignored.as_slice());
46747
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
709 }
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
710 }
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
711
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
712 if unsupported.is_empty() {
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
713 Ok(())
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
714 } else {
49064
c75dae6e4ca7 rhg: sort unsupported extensions in error message
Raphaël Gomès <rgomes@octobus.net>
parents: 49058
diff changeset
715 let mut unsupported: Vec<_> = unsupported.into_iter().collect();
c75dae6e4ca7 rhg: sort unsupported extensions in error message
Raphaël Gomès <rgomes@octobus.net>
parents: 49058
diff changeset
716 // Sort the extensions to get a stable output
c75dae6e4ca7 rhg: sort unsupported extensions in error message
Raphaël Gomès <rgomes@octobus.net>
parents: 49058
diff changeset
717 unsupported.sort();
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
718 Err(CommandError::UnsupportedFeature {
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
719 message: format_bytes!(
46747
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
720 b"extensions: {} (consider adding them to 'rhg.ignored-extensions' config)",
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
721 join(unsupported, b", ")
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
722 ),
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
723 })
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
724 }
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
725 }
48385
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
726
49224
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
727 /// Array of tuples of (auto upgrade conf, feature conf, local requirement)
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
728 const AUTO_UPGRADES: &[((&str, &str), (&str, &str), &str)] = &[
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
729 (
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
730 ("format", "use-share-safe.automatic-upgrade-of-mismatching-repositories"),
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
731 ("format", "use-share-safe"),
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
732 requirements::SHARESAFE_REQUIREMENT,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
733 ),
49226
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49224
diff changeset
734 (
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49224
diff changeset
735 ("format", "use-dirstate-tracked-hint.automatic-upgrade-of-mismatching-repositories"),
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49224
diff changeset
736 ("format", "use-dirstate-tracked-hint"),
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49224
diff changeset
737 requirements::DIRSTATE_TRACKED_HINT_V1,
e4b31016e194 auto-upgrade: introduce a way to auto-upgrade to/from tracked-hint
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49224
diff changeset
738 ),
49227
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49226
diff changeset
739 (
49420
3a53871048dc rhg: fix bugs around [use-dirstate-tracked-hint] and repo auto-upgrade
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49227
diff changeset
740 ("format", "use-dirstate-v2.automatic-upgrade-of-mismatching-repositories"),
49227
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49226
diff changeset
741 ("format", "use-dirstate-v2"),
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49226
diff changeset
742 requirements::DIRSTATE_V2_REQUIREMENT,
411d591e0a27 auto-upgrade: introduce a way to auto-upgrade to/from dirstate-v2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49226
diff changeset
743 ),
49224
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
744 ];
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
745
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
746 /// Mercurial allows users to automatically upgrade their repository.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
747 /// `rhg` does not have the ability to upgrade yet, so fallback if an upgrade
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
748 /// is needed.
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
749 fn check_auto_upgrade(
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
750 config: &Config,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
751 reqs: &HashSet<String>,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
752 ) -> Result<(), CommandError> {
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
753 for (upgrade_conf, feature_conf, local_req) in AUTO_UPGRADES.iter() {
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
754 let auto_upgrade = config
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
755 .get_bool(upgrade_conf.0.as_bytes(), upgrade_conf.1.as_bytes())?;
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
756
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
757 if auto_upgrade {
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
758 let want_it = config.get_bool(
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
759 feature_conf.0.as_bytes(),
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
760 feature_conf.1.as_bytes(),
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
761 )?;
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
762 let have_it = reqs.contains(*local_req);
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
763
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
764 let action = match (want_it, have_it) {
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
765 (true, false) => Some("upgrade"),
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
766 (false, true) => Some("downgrade"),
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
767 _ => None,
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
768 };
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
769 if let Some(action) = action {
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
770 let message = format!(
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
771 "automatic {} {}.{}",
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
772 action, upgrade_conf.0, upgrade_conf.1
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
773 );
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
774 return Err(CommandError::unsupported(message));
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
775 }
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
776 }
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
777 }
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
778 Ok(())
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
779 }
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
780
48389
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
781 fn check_unsupported(
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
782 config: &Config,
48547
7f633432ca92 rhg: Sub-repositories are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48480
diff changeset
783 repo: Result<&Repo, &NoRepoInCwdError>,
48389
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
784 ) -> Result<(), CommandError> {
48385
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
785 check_extensions(config)?;
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
786
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
787 if std::env::var_os("HG_PENDING").is_some() {
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
788 // TODO: only if the value is `== repo.working_directory`?
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
789 // What about relative v.s. absolute paths?
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
790 Err(CommandError::unsupported("$HG_PENDING"))?
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
791 }
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
792
48547
7f633432ca92 rhg: Sub-repositories are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48480
diff changeset
793 if let Ok(repo) = repo {
7f633432ca92 rhg: Sub-repositories are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48480
diff changeset
794 if repo.has_subrepos()? {
7f633432ca92 rhg: Sub-repositories are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48480
diff changeset
795 Err(CommandError::unsupported("sub-repositories"))?
7f633432ca92 rhg: Sub-repositories are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48480
diff changeset
796 }
49224
2ab79873786e auto-upgrade: introduce a way to auto-upgrade to/from share-safe
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49201
diff changeset
797 check_auto_upgrade(config, repo.requirements())?;
48547
7f633432ca92 rhg: Sub-repositories are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48480
diff changeset
798 }
7f633432ca92 rhg: Sub-repositories are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48480
diff changeset
799
48388
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
800 if config.has_non_empty_section(b"encode") {
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
801 Err(CommandError::unsupported("[encode] config"))?
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
802 }
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
803
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
804 if config.has_non_empty_section(b"decode") {
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
805 Err(CommandError::unsupported("[decode] config"))?
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
806 }
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
807
48385
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
808 Ok(())
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
809 }