##// END OF EJS Templates
rhg: support `rhg files` with `ui.relative-paths=false`
Arseniy Alekseyev -
r51433:9db197c7 default
parent child Browse files
Show More
@@ -1,5 +1,7 b''
1 use crate::error::CommandError;
1 use crate::error::CommandError;
2 use crate::ui::{print_narrow_sparse_warnings, Ui, RelativePaths, relative_paths};
2 use crate::ui::{
3 print_narrow_sparse_warnings, relative_paths, RelativePaths, Ui,
4 };
3 use crate::utils::path_utils::RelativizePaths;
5 use crate::utils::path_utils::RelativizePaths;
4 use clap::Arg;
6 use clap::Arg;
5 use hg::narrow;
7 use hg::narrow;
@@ -28,14 +30,10 b' pub fn args() -> clap::Command {'
28 }
30 }
29
31
30 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
32 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
31 match relative_paths(invocation.config)? {
33 let relative_paths = match relative_paths(invocation.config)? {
32 RelativePaths::Legacy | RelativePaths::Bool(true) => (),
34 RelativePaths::Legacy => true,
33 RelativePaths::Bool(false) => {
35 RelativePaths::Bool(v) => v,
34 return Err(CommandError::unsupported(
36 };
35 "non-default ui.relative-paths",
36 ));
37 }
38 }
39
37
40 let rev = invocation.subcommand_args.get_one::<String>("rev");
38 let rev = invocation.subcommand_args.get_one::<String>("rev");
41
39
@@ -59,7 +57,7 b' pub fn run(invocation: &crate::CliInvoca'
59 if let Some(rev) = rev {
57 if let Some(rev) = rev {
60 let files = list_rev_tracked_files(repo, rev, narrow_matcher)
58 let files = list_rev_tracked_files(repo, rev, narrow_matcher)
61 .map_err(|e| (e, rev.as_ref()))?;
59 .map_err(|e| (e, rev.as_ref()))?;
62 display_files(invocation.ui, repo, files.iter())
60 display_files(invocation.ui, repo, relative_paths, files.iter())
63 } else {
61 } else {
64 // The dirstate always reflects the sparse narrowspec.
62 // The dirstate always reflects the sparse narrowspec.
65 let dirstate = repo.dirstate_map()?;
63 let dirstate = repo.dirstate_map()?;
@@ -79,6 +77,7 b' pub fn run(invocation: &crate::CliInvoca'
79 display_files(
77 display_files(
80 invocation.ui,
78 invocation.ui,
81 repo,
79 repo,
80 relative_paths,
82 files.into_iter().map::<Result<_, CommandError>, _>(Ok),
81 files.into_iter().map::<Result<_, CommandError>, _>(Ok),
83 )
82 )
84 }
83 }
@@ -87,6 +86,7 b' pub fn run(invocation: &crate::CliInvoca'
87 fn display_files<'a, E>(
86 fn display_files<'a, E>(
88 ui: &Ui,
87 ui: &Ui,
89 repo: &Repo,
88 repo: &Repo,
89 relative_paths: bool,
90 files: impl IntoIterator<Item = Result<&'a HgPath, E>>,
90 files: impl IntoIterator<Item = Result<&'a HgPath, E>>,
91 ) -> Result<(), CommandError>
91 ) -> Result<(), CommandError>
92 where
92 where
@@ -98,7 +98,11 b' where'
98 let relativize = RelativizePaths::new(repo)?;
98 let relativize = RelativizePaths::new(repo)?;
99 for result in files {
99 for result in files {
100 let path = result?;
100 let path = result?;
101 stdout.write_all(&relativize.relativize(path))?;
101 if relative_paths {
102 stdout.write_all(&relativize.relativize(path))?;
103 } else {
104 stdout.write_all(path.as_bytes())?;
105 }
102 stdout.write_all(b"\n")?;
106 stdout.write_all(b"\n")?;
103 any = true;
107 any = true;
104 }
108 }
@@ -77,8 +77,9 b' Listing tracked files from subdirectory'
77 ../../../file3
77 ../../../file3
78
78
79 $ $NO_FALLBACK rhg files --config ui.relative-paths=false
79 $ $NO_FALLBACK rhg files --config ui.relative-paths=false
80 unsupported feature: non-default ui.relative-paths
80 file1
81 [252]
81 file2
82 file3
82
83
83 $ $NO_FALLBACK rhg files --config ui.relative-paths=true
84 $ $NO_FALLBACK rhg files --config ui.relative-paths=true
84 ../../../file1
85 ../../../file1
General Comments 0
You need to be logged in to leave comments. Login now