[Updated] D11751: rhg: only complain about poorly configured fallback when falling back
aalekseyev (Arseniy Alekseyev)
phabricator at mercurial-scm.org
Mon Nov 29 12:45:45 UTC 2021
Closed by commit rHG8960295b9246: rhg: only complain about poorly configured fallback when falling back (authored by aalekseyev).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D11751?vs=31167&id=31184
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D11751/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D11751
AFFECTED FILES
rust/rhg/src/main.rs
tests/test-rhg.t
CHANGE DETAILS
diff --git a/tests/test-rhg.t b/tests/test-rhg.t
--- a/tests/test-rhg.t
+++ b/tests/test-rhg.t
@@ -168,13 +168,12 @@
$ rhg cat original --exclude="*.rs"
original content
- $ FALLBACK_EXE="$RHG_FALLBACK_EXECUTABLE"
- $ unset RHG_FALLBACK_EXECUTABLE
- $ rhg cat original --exclude="*.rs"
+ $ (unset RHG_FALLBACK_EXECUTABLE; rhg cat original --exclude="*.rs")
abort: 'rhg.on-unsupported=fallback' without 'rhg.fallback-executable' set.
[255]
- $ RHG_FALLBACK_EXECUTABLE="$FALLBACK_EXE"
- $ export RHG_FALLBACK_EXECUTABLE
+
+ $ (unset RHG_FALLBACK_EXECUTABLE; rhg cat original)
+ original content
$ rhg cat original --exclude="*.rs" --config rhg.fallback-executable=false
[1]
diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs
+++ b/rust/rhg/src/main.rs
@@ -179,7 +179,7 @@
exit(
&initial_current_dir,
&ui,
- OnUnsupported::from_config(&ui, &non_repo_config),
+ OnUnsupported::from_config(&non_repo_config),
Err(error.into()),
non_repo_config
.get_bool(b"ui", b"detailed-exit-code")
@@ -197,7 +197,7 @@
exit(
&initial_current_dir,
&ui,
- OnUnsupported::from_config(&ui, &non_repo_config),
+ OnUnsupported::from_config(&non_repo_config),
Err(CommandError::UnsupportedFeature {
message: format_bytes!(
b"URL-like --repository {}",
@@ -287,7 +287,7 @@
Err(error) => exit(
&initial_current_dir,
&ui,
- OnUnsupported::from_config(&ui, &non_repo_config),
+ OnUnsupported::from_config(&non_repo_config),
Err(error.into()),
// TODO: show a warning or combine with original error if
// `get_bool` returns an error
@@ -302,7 +302,7 @@
} else {
&non_repo_config
};
- let on_unsupported = OnUnsupported::from_config(&ui, config);
+ let on_unsupported = OnUnsupported::from_config(config);
let result = main_with_result(
&process_start_time,
@@ -362,6 +362,20 @@
) = (&on_unsupported, &result)
{
let mut args = std::env::args_os();
+ let executable = match executable {
+ None => {
+ exit_no_fallback(
+ ui,
+ OnUnsupported::Abort,
+ Err(CommandError::abort(
+ "abort: 'rhg.on-unsupported=fallback' without \
+ 'rhg.fallback-executable' set.",
+ )),
+ false,
+ );
+ }
+ Some(executable) => executable,
+ };
let executable_path = get_path_from_bytes(&executable);
let this_executable = args.next().expect("exepcted argv[0] to exist");
if executable_path == &PathBuf::from(this_executable) {
@@ -374,7 +388,8 @@
));
on_unsupported = OnUnsupported::Abort
} else {
- // `args` is now `argv[1..]` since we’ve already consumed `argv[0]`
+ // `args` is now `argv[1..]` since we’ve already consumed
+ // `argv[0]`
let mut command = Command::new(executable_path);
command.args(args);
if let Some(initial) = initial_current_dir {
@@ -549,13 +564,13 @@
/// Silently exit with code 252.
AbortSilent,
/// Try running a Python implementation
- Fallback { executable: Vec<u8> },
+ Fallback { executable: Option<Vec<u8>> },
}
impl OnUnsupported {
const DEFAULT: Self = OnUnsupported::Abort;
- fn from_config(ui: &Ui, config: &Config) -> Self {
+ fn from_config(config: &Config) -> Self {
match config
.get(b"rhg", b"on-unsupported")
.map(|value| value.to_ascii_lowercase())
@@ -566,18 +581,7 @@
Some(b"fallback") => OnUnsupported::Fallback {
executable: config
.get(b"rhg", b"fallback-executable")
- .unwrap_or_else(|| {
- exit_no_fallback(
- ui,
- Self::Abort,
- Err(CommandError::abort(
- "abort: 'rhg.on-unsupported=fallback' without \
- 'rhg.fallback-executable' set."
- )),
- false,
- )
- })
- .to_owned(),
+ .map(|x| x.to_owned()),
},
None => Self::DEFAULT,
Some(_) => {
To: aalekseyev, #hg-reviewers, Alphare
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20211129/c4330fd8/attachment-0002.html>
More information about the Mercurial-patches
mailing list