rust/rhg/src/main.rs
author Arseniy Alekseyev <aalekseyev@janestreet.com>
Tue, 16 Nov 2021 11:53:58 +0000
changeset 48457 005ae1a343f8
parent 48403 6d4daf51283c
child 48461 9ff246cd6200
permissions -rw-r--r--
rhg: add support for narrow clones and sparse checkouts This adds a minimal support that can be implemented without parsing the narrowspec. We can parse the narrowspec and add support for more operations later. The reason we need so few code changes is as follows: Most operations need no special treatment of sparse because some of them only read dirstate (`rhg files` without `-r`), which bakes in the filtering, some of them only read store (`rhg files -r`, `rhg cat`), and some of them read no data at all (`rhg root`, `rhg debugrequirements`). `status` is the command that might care about sparse, so we just disable rhg on it. For narrow clones, `rhg files` clearly needs the narrowspec to work correctly, so we fall back. `rhg cat` seems to work consistently with `hg cat` if the file exists. If the file is hidden by narrow spec, the error message is different and confusing, so that's something that we should improve in follow-up patches. Differential Revision: https://phab.mercurial-scm.org/D11764
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
     3
use crate::ui::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};
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
    10
use hg::exit_codes;
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
    11
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
    12
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
    13
use hg::utils::SliceExt;
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
    14
use std::ffi::OsString;
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
    15
use std::path::PathBuf;
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
    16
use std::process::Command;
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
    17
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
    18
mod blackbox;
45002
bacf6c7ef01b rhg: add Command trait for subcommands implemented by rhg
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45001
diff changeset
    19
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
    20
mod ui;
48186
9ecf802b06e0 rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48091
diff changeset
    21
pub mod utils {
9ecf802b06e0 rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48091
diff changeset
    22
    pub mod path_utils;
9ecf802b06e0 rhg: refactor function to relativize paths in utils
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48091
diff changeset
    23
}
45001
cf04f62d1579 rhg: add rhg crate
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
    24
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
    25
fn main_with_result(
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
    26
    process_start_time: &blackbox::ProcessStartTime,
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
    27
    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
    28
    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
    29
    config: &Config,
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
    30
) -> Result<(), CommandError> {
48389
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
    31
    check_unsupported(config, ui)?;
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
    32
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
    33
    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
    34
        .global_setting(AppSettings::AllowInvalidUtf8)
46759
eb14264b98e8 rhg: Fall back to Python for --version
Simon Sapin <simon.sapin@octobus.net>
parents: 46757
diff changeset
    35
        .global_setting(AppSettings::DisableVersion)
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
    36
        .setting(AppSettings::SubcommandRequired)
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
    37
        .setting(AppSettings::VersionlessSubcommands)
46647
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    38
        .arg(
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    39
            Arg::with_name("repository")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    40
                .help("repository root directory")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    41
                .short("-R")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    42
                .long("--repository")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    43
                .value_name("REPO")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    44
                .takes_value(true)
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    45
                // 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
    46
                .global(true),
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    47
        )
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    48
        .arg(
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    49
            Arg::with_name("config")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    50
                .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
    51
                .long("--config")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    52
                .value_name("CONFIG")
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    53
                .takes_value(true)
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    54
                .global(true)
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    55
                // 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
    56
                .multiple(true)
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    57
                // 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
    58
                .number_of_values(1),
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
    59
        )
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
    60
        .arg(
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
    61
            Arg::with_name("cwd")
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
    62
                .help("change working directory")
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
    63
                .long("--cwd")
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
    64
                .value_name("DIR")
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
    65
                .takes_value(true)
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
    66
                .global(true),
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
    67
        )
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    68
        .version("0.0.1");
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    69
    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
    70
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    71
    let matches = app.clone().get_matches_safe()?;
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    72
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    73
    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
    74
48090
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
    75
    // 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
    76
    // 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
    77
    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
    78
    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
    79
        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
    80
        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
    81
    }
b44e1184b7e1 rhg: fallback if `defaults` config is set for the current command
Raphaël Gomès <rgomes@octobus.net>
parents: 48089
diff changeset
    82
48089
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
    83
    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
    84
        // 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
    85
        // 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
    86
        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
    87
        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
    88
        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
    89
            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
    90
            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
    91
        }
f11f233546ce rhg: fallback if the current command has any generic hook defined
Raphaël Gomès <rgomes@octobus.net>
parents: 47979
diff changeset
    92
    }
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    93
    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
    94
        .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
    95
    let subcommand_args = subcommand_matches
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    96
        .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
    97
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
    98
    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
    99
        ui,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   100
        subcommand_args,
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   101
        config,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   102
        repo,
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   103
    };
48091
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
   104
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
   105
    if let Ok(repo) = repo {
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
   106
        // 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
   107
        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
   108
            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
   109
            return Err(CommandError::unsupported(msg));
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
   110
        }
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
   111
    }
ba773bd99203 rhg: fall back if subrepos are detected
Raphaël Gomès <rgomes@octobus.net>
parents: 48090
diff changeset
   112
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   113
    let blackbox = blackbox::Blackbox::new(&invocation, process_start_time)?;
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   114
    blackbox.log_command_start();
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   115
    let result = run(&invocation);
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   116
    blackbox.log_command_end(exit_code(
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   117
        &result,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   118
        // 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
   119
        // returns an error
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   120
        config
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   121
            .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
   122
            .unwrap_or(false),
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   123
    ));
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   124
    result
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
   125
}
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   126
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
   127
fn main() {
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   128
    // 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
   129
    // 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
   130
    // 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
   131
    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
   132
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   133
    env_logger::init();
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   134
    let ui = ui::Ui::new();
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
   135
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   136
    let early_args = EarlyArgs::parse(std::env::args_os());
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   137
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   138
    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
   139
        let cwd = get_path_from_bytes(&cwd);
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   140
        std::env::current_dir()
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   141
            .and_then(|initial| {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   142
                std::env::set_current_dir(cwd)?;
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   143
                Ok(initial)
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   144
            })
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   145
            .unwrap_or_else(|error| {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   146
                exit(
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   147
                    &None,
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   148
                    &ui,
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   149
                    OnUnsupported::Abort,
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   150
                    Err(CommandError::abort(format!(
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   151
                        "abort: {}: '{}'",
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   152
                        error,
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   153
                        cwd.display()
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   154
                    ))),
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   155
                    false,
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
            })
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   158
    });
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   159
47412
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   160
    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
   161
        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
   162
            // 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
   163
            // 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
   164
            // "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
   165
            let on_unsupported = OnUnsupported::Abort;
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   166
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   167
            exit(
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   168
                &initial_current_dir,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   169
                &ui,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   170
                on_unsupported,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   171
                Err(error.into()),
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   172
                false,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   173
            )
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   174
        });
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   175
47412
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   176
    non_repo_config
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   177
        .load_cli_args_config(early_args.config)
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   178
        .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
   179
            exit(
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   180
                &initial_current_dir,
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   181
                &ui,
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   182
                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
   183
                Err(error.into()),
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   184
                non_repo_config
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   185
                    .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
   186
                    .unwrap_or(false),
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   187
            )
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   188
        });
3237ed4dcda4 rhg: split non_repo_config and `--config` loading in different functions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47411
diff changeset
   189
46742
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
   190
    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
   191
        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
   192
            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
   193
                // 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
   194
                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
   195
        }
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
   196
        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
   197
            exit(
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   198
                &initial_current_dir,
46742
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
   199
                &ui,
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   200
                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
   201
                Err(CommandError::UnsupportedFeature {
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
   202
                    message: format_bytes!(
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
   203
                        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
   204
                        repo_path_bytes
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
   205
                    ),
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
   206
                }),
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   207
                // 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
   208
                // `get_bool` returns an error
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   209
                non_repo_config
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   210
                    .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
   211
                    .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
   212
            )
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
   213
        }
6cd9f53aaed8 rhg: Fall back to Python on --repository with an URL
Simon Sapin <simon.sapin@octobus.net>
parents: 46706
diff changeset
   214
    }
47410
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   215
    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
   216
    let repo_path: Option<PathBuf> = {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   217
        if repo_arg.is_empty() {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   218
            None
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   219
        } else {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   220
            let local_config = {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   221
                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
   222
                    // 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
   223
                    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
   224
                        let config_files = vec![
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   225
                            ConfigSource::AbsPath(
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   226
                                current_dir_path.join(".hg/hgrc"),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   227
                            ),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   228
                            ConfigSource::AbsPath(
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   229
                                current_dir_path.join(".hg/hgrc-not-shared"),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   230
                            ),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   231
                        ];
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   232
                        // TODO: handle errors from
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   233
                        // `load_from_explicit_sources`
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   234
                        Config::load_from_explicit_sources(config_files).ok()
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   235
                    } else {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   236
                        None
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   237
                    }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   238
                } else {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   239
                    None
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   240
                }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   241
            };
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   242
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   243
            let non_repo_config_val = {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   244
                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
   245
                match &non_repo_val {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   246
                    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
   247
                        .unwrap_or_else(|| PathBuf::from("~"))
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   248
                        .join(get_path_from_bytes(val))
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   249
                        .canonicalize()
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   250
                        // 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
   251
                        // implementation maybe?
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   252
                        .ok(),
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   253
                    _ => None,
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
            };
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   256
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   257
            let config_val = match &local_config {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   258
                None => non_repo_config_val,
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   259
                Some(val) => {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   260
                    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
   261
                    match &local_config_val {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   262
                        Some(val) if val.len() > 0 => {
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   263
                            // presence of a local_config assures that
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   264
                            // current_dir
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   265
                            // wont result in an Error
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   266
                            let canpath = hg::utils::current_dir()
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   267
                                .unwrap()
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   268
                                .join(get_path_from_bytes(val))
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   269
                                .canonicalize();
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   270
                            canpath.ok().or(non_repo_config_val)
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   271
                        }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   272
                        _ => non_repo_config_val,
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   273
                    }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   274
                }
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   275
            };
ebdef6283798 rhg: read [paths] for `--repository` value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46822
diff changeset
   276
            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
   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 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
   281
    {
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   282
        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
   283
        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
   284
            // 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
   285
            Err(NoRepoInCwdError { cwd: at })
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   286
        }
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   287
        Err(error) => exit(
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   288
            &initial_current_dir,
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   289
            &ui,
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   290
            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
   291
            Err(error.into()),
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   292
            // 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
   293
            // `get_bool` returns an error
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   294
            non_repo_config
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   295
                .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
   296
                .unwrap_or(false),
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   297
        ),
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   298
    };
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   299
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   300
    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
   301
        repo.config()
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   302
    } else {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   303
        &non_repo_config
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   304
    };
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   305
    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
   306
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   307
    let result = main_with_result(
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   308
        &process_start_time,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   309
        &ui,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   310
        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
   311
        config,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   312
    );
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   313
    exit(
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   314
        &initial_current_dir,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   315
        &ui,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   316
        on_unsupported,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   317
        result,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   318
        // 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
   319
        // returns an error
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   320
        config
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   321
            .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
   322
            .unwrap_or(false),
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   323
    )
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   324
}
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   325
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   326
fn exit_code(
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   327
    result: &Result<(), CommandError>,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   328
    use_detailed_exit_code: bool,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   329
) -> i32 {
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   330
    match result {
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
   331
        Ok(()) => exit_codes::OK,
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   332
        Err(CommandError::Abort {
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   333
            message: _,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   334
            detailed_exit_code,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   335
        }) => {
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   336
            if use_detailed_exit_code {
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   337
                *detailed_exit_code
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   338
            } else {
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
   339
                exit_codes::ABORT
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   340
            }
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   341
        }
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
   342
        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
   343
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
   344
        // 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
   345
        // 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
   346
        Err(CommandError::UnsupportedFeature { .. }) => {
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
   347
            exit_codes::UNIMPLEMENTED
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   348
        }
46640
755c31a1caf9 rhg: Add support for the blackbox extension
Simon Sapin <simon.sapin@octobus.net>
parents: 46635
diff changeset
   349
    }
45001
cf04f62d1579 rhg: add rhg crate
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
   350
}
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
   351
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   352
fn exit(
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   353
    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
   354
    ui: &Ui,
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   355
    mut on_unsupported: OnUnsupported,
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   356
    result: Result<(), CommandError>,
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   357
    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
   358
) -> ! {
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   359
    if let (
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   360
        OnUnsupported::Fallback { executable },
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   361
        Err(CommandError::UnsupportedFeature { .. }),
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   362
    ) = (&on_unsupported, &result)
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   363
    {
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   364
        let mut args = std::env::args_os();
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   365
        let executable = match executable {
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   366
            None => {
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   367
                exit_no_fallback(
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   368
                    ui,
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   369
                    OnUnsupported::Abort,
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   370
                    Err(CommandError::abort(
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   371
                        "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
   372
                                'rhg.fallback-executable' set.",
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   373
                    )),
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   374
                    false,
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   375
                );
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   376
            }
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   377
            Some(executable) => executable,
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   378
        };
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   379
        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
   380
        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
   381
        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
   382
            // 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
   383
            // exhaustion.
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   384
            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
   385
                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
   386
                points to `rhg` itself.\n",
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   387
                executable
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   388
            ));
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   389
            on_unsupported = OnUnsupported::Abort
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   390
        } else {
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   391
            // `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
   392
            // `argv[0]`
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   393
            let mut command = Command::new(executable_path);
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   394
            command.args(args);
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   395
            if let Some(initial) = initial_current_dir {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   396
                command.current_dir(initial);
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   397
            }
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   398
            let result = command.status();
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   399
            match result {
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   400
                Ok(status) => std::process::exit(
47413
6e49769b7f97 rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47412
diff changeset
   401
                    status.code().unwrap_or(exit_codes::ABORT),
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   402
                ),
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   403
                Err(error) => {
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   404
                    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
   405
                        b"tried to fall back to a '{}' sub-process but got error {}\n",
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   406
                        executable, format_bytes::Utf8(error)
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   407
                    ));
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   408
                    on_unsupported = OnUnsupported::Abort
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   409
                }
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   410
            }
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   411
        }
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   412
    }
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   413
    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
   414
}
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
   415
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
   416
fn exit_no_fallback(
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
   417
    ui: &Ui,
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
   418
    on_unsupported: OnUnsupported,
bde90e9b4507 rhg: Remove `rhg.fallback-executable=hg` default configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46759
diff changeset
   419
    result: Result<(), CommandError>,
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   420
    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
   421
) -> ! {
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   422
    match &result {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   423
        Ok(_) => {}
46757
b1f2c2b336ec rhg: `cat` command: print error messages for missing files
Simon Sapin <simon.sapin@octobus.net>
parents: 46749
diff changeset
   424
        Err(CommandError::Unsuccessful) => {}
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   425
        Err(CommandError::Abort {
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   426
            message,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   427
            detailed_exit_code: _,
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   428
        }) => {
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   429
            if !message.is_empty() {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   430
                // 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
   431
                // 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
   432
                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
   433
            }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   434
        }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   435
        Err(CommandError::UnsupportedFeature { message }) => {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   436
            match on_unsupported {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   437
                OnUnsupported::Abort => {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   438
                    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
   439
                        b"unsupported feature: {}\n",
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   440
                        message
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   441
                    ));
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   442
                }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   443
                OnUnsupported::AbortSilent => {}
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   444
                OnUnsupported::Fallback { .. } => unreachable!(),
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   445
            }
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   446
        }
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   447
    }
46820
821929d59e01 rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46761
diff changeset
   448
    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
   449
}
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   450
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   451
macro_rules! subcommands {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   452
    ($( $command: ident )+) => {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   453
        mod commands {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   454
            $(
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   455
                pub mod $command;
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   456
            )+
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   457
        }
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   458
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   459
        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
   460
            app
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   461
            $(
46647
4e4c70401028 rhg: Use clap’s support for global CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46640
diff changeset
   462
                .subcommand(commands::$command::args())
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   463
            )+
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   464
        }
46543
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46513
diff changeset
   465
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   466
        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
   467
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   468
        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
   469
            match name {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   470
                $(
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   471
                    stringify!($command) => Some(commands::$command::run),
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   472
                )+
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   473
                _ => None,
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   474
            }
45548
33ded2d3f4fc rhg: add a limited `rhg cat -r` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45543
diff changeset
   475
        }
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   476
    };
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
   477
}
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   478
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   479
subcommands! {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   480
    cat
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   481
    debugdata
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   482
    debugrequirements
48403
6d4daf51283c rhg: implement the debugignorerhg subcommand
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48401
diff changeset
   483
    debugignorerhg
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   484
    files
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   485
    root
46557
a25033eb43b5 rhg: add limited support for the `config` sub-command
Simon Sapin <simon.sapin@octobus.net>
parents: 46556
diff changeset
   486
    config
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents: 46820
diff changeset
   487
    status
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   488
}
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents: 46820
diff changeset
   489
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   490
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
   491
    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
   492
    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
   493
    config: &'a Config,
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   494
    /// 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
   495
    /// `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
   496
    /// `Result` type is `Copy`.
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   497
    repo: Result<&'a Repo, &'a NoRepoInCwdError>,
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   498
}
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   499
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   500
struct NoRepoInCwdError {
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   501
    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
   502
}
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
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
/// 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
   505
/// 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
   506
/// 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
   507
///
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   508
/// 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
   509
/// 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
   510
struct EarlyArgs {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   511
    /// 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
   512
    config: Vec<Vec<u8>>,
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   513
    /// 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
   514
    repo: Option<Vec<u8>>,
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   515
    /// Value of the `--cwd` argument, if any.
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   516
    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
   517
}
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   518
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   519
impl EarlyArgs {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   520
    fn parse(args: impl IntoIterator<Item = OsString>) -> Self {
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   521
        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
   522
        let mut config = Vec::new();
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   523
        let mut repo = None;
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   524
        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
   525
        // 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
   526
        // `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
   527
        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
   528
            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
   529
                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
   530
                    config.push(value)
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   531
                }
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   532
            } 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
   533
                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
   534
            }
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   535
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   536
            if arg == b"--cwd" {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   537
                if let Some(value) = args.next() {
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   538
                    cwd = Some(value)
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   539
                }
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   540
            } 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
   541
                cwd = Some(value.to_owned())
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   542
            }
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   543
46704
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   544
            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
   545
                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
   546
                    repo = Some(value)
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   547
                }
7284b524b441 rhg: Make configuration available as early as possible in main()
Simon Sapin <simon.sapin@octobus.net>
parents: 46647
diff changeset
   548
            } 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
   549
                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
   550
            } 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
   551
                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
   552
            }
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   553
        }
46749
2255e7eb39e5 rhg: Add support for --cwd
Simon Sapin <simon.sapin@octobus.net>
parents: 46747
diff changeset
   554
        Self { config, repo, cwd }
46632
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   555
    }
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46631
diff changeset
   556
}
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   557
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   558
/// 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
   559
///
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   560
/// 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
   561
enum OnUnsupported {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   562
    /// 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
   563
    /// and exit with code 252.
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   564
    Abort,
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   565
    /// Silently exit with code 252.
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   566
    AbortSilent,
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   567
    /// 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
   568
    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
   569
}
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   570
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   571
impl OnUnsupported {
46706
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   572
    const DEFAULT: Self = OnUnsupported::Abort;
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   573
48401
8960295b9246 rhg: only complain about poorly configured fallback when falling back
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48389
diff changeset
   574
    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
   575
        match config
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   576
            .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
   577
            .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
   578
            .as_deref()
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   579
        {
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   580
            Some(b"abort") => OnUnsupported::Abort,
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   581
            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
   582
            Some(b"fallback") => OnUnsupported::Fallback {
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   583
                executable: config
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   584
                    .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
   585
                    .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
   586
            },
93e9f448273c rhg: Add support for automatic fallback to Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46705
diff changeset
   587
            None => Self::DEFAULT,
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   588
            Some(_) => {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   589
                // 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
   590
                Self::DEFAULT
46705
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   591
            }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   592
        }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   593
    }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46704
diff changeset
   594
}
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   595
48457
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48403
diff changeset
   596
const SUPPORTED_EXTENSIONS: &[&[u8]] =
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48403
diff changeset
   597
    &[b"blackbox", b"share", b"sparse", b"narrow"];
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   598
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   599
fn check_extensions(config: &Config) -> Result<(), CommandError> {
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   600
    let enabled = config.get_section_keys(b"extensions");
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   601
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   602
    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
   603
    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
   604
        unsupported.remove(supported);
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   605
    }
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   606
47979
cff41e168c25 rhg: Switch rhg.ignored-extensions config to Python-compatible list syntax
Simon Sapin <simon.sapin@octobus.net>
parents: 47413
diff changeset
   607
    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
   608
    {
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
   609
        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
   610
            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
   611
        }
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
   612
    }
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
   613
46746
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   614
    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
   615
        Ok(())
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   616
    } else {
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   617
        Err(CommandError::UnsupportedFeature {
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   618
            message: format_bytes!(
46747
1a036d33bc18 rhg: Add an allow-list of ignored extensions
Simon Sapin <simon.sapin@octobus.net>
parents: 46746
diff changeset
   619
                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
   620
                join(unsupported, b", ")
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   621
            ),
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   622
        })
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   623
    }
1bac7764ceef rhg: Fall back to Python if unsupported extensions are enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 46744
diff changeset
   624
}
48385
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
   625
48389
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   626
fn check_unsupported(
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   627
    config: &Config,
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   628
    ui: &ui::Ui,
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   629
) -> Result<(), CommandError> {
48385
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
   630
    check_extensions(config)?;
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
   631
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
   632
    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
   633
        // 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
   634
        // What about relative v.s. absolute paths?
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
   635
        Err(CommandError::unsupported("$HG_PENDING"))?
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
   636
    }
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
   637
48388
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
   638
    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
   639
        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
   640
    }
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
   641
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
   642
    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
   643
        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
   644
    }
a2e278b5e265 rhg: [encode] and [decode] config sections are not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48385
diff changeset
   645
48389
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   646
    if let Some(color) = config.get(b"ui", b"color") {
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   647
        if (color == b"always" || color == b"debug") && !ui.plain() {
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   648
            Err(CommandError::unsupported("colored output"))?
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   649
        }
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   650
    }
d71b9902e2de rhg: Colored output is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48388
diff changeset
   651
48385
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
   652
    Ok(())
5b9865032533 rhg: $HG_PENDING is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48186
diff changeset
   653
}