rhg: make `rhg files` work if `ui.relative-files=true` is specified
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Mon, 29 May 2023 16:53:18 +0100
changeset 50539 74e4dbb0fcd5
parent 50538 a7513d0d451b
child 50540 9db197c73138
rhg: make `rhg files` work if `ui.relative-files=true` is specified
rust/rhg/src/commands/files.rs
rust/rhg/src/ui.rs
tests/test-rhg.t
--- a/rust/rhg/src/commands/files.rs	Mon May 29 16:47:39 2023 +0100
+++ b/rust/rhg/src/commands/files.rs	Mon May 29 16:53:18 2023 +0100
@@ -1,5 +1,5 @@
 use crate::error::CommandError;
-use crate::ui::{print_narrow_sparse_warnings, Ui};
+use crate::ui::{print_narrow_sparse_warnings, Ui, RelativePaths, relative_paths};
 use crate::utils::path_utils::RelativizePaths;
 use clap::Arg;
 use hg::narrow;
@@ -28,11 +28,13 @@
 }
 
 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
-    let relative = invocation.config.get(b"ui", b"relative-paths");
-    if relative.is_some() {
+    match relative_paths(invocation.config)? {
+      RelativePaths::Legacy | RelativePaths::Bool(true) => (),
+      RelativePaths::Bool(false) => {
         return Err(CommandError::unsupported(
             "non-default ui.relative-paths",
         ));
+      }
     }
 
     let rev = invocation.subcommand_args.get_one::<String>("rev");
--- a/rust/rhg/src/ui.rs	Mon May 29 16:47:39 2023 +0100
+++ b/rust/rhg/src/ui.rs	Mon May 29 16:53:18 2023 +0100
@@ -221,6 +221,18 @@
     }
 }
 
+pub enum RelativePaths {
+    Legacy,
+    Bool(bool),
+}
+
+pub fn relative_paths(config: &Config) -> Result<RelativePaths, HgError> {
+    Ok(match config.get(b"ui", b"relative-paths") {
+        None | Some(b"legacy") => RelativePaths::Legacy,
+        _ => RelativePaths::Bool(config.get_bool(b"ui", b"relative-paths")?),
+    })
+}
+
 fn isatty(config: &Config) -> Result<bool, HgError> {
     Ok(if config.get_bool(b"ui", b"nontty")? {
         false
--- a/tests/test-rhg.t	Mon May 29 16:47:39 2023 +0100
+++ b/tests/test-rhg.t	Mon May 29 16:53:18 2023 +0100
@@ -72,16 +72,18 @@
   ../../../file3
 
   $ $NO_FALLBACK rhg files --config ui.relative-paths=legacy
-  unsupported feature: non-default ui.relative-paths
-  [252]
+  ../../../file1
+  ../../../file2
+  ../../../file3
 
   $ $NO_FALLBACK rhg files --config ui.relative-paths=false
   unsupported feature: non-default ui.relative-paths
   [252]
 
   $ $NO_FALLBACK rhg files --config ui.relative-paths=true
-  unsupported feature: non-default ui.relative-paths
-  [252]
+  ../../../file1
+  ../../../file2
+  ../../../file3
 
 Listing tracked files through broken pipe
   $ $NO_FALLBACK rhg files | head -n 1