##// END OF EJS Templates
rhg: Make `files` work on repo-relative paths when possible...
Simon Sapin -
r47687:b5e8bf10 default
parent child Browse files
Show More
@@ -53,21 +53,35 b" fn display_files<'a>("
53 repo: &Repo,
53 repo: &Repo,
54 files: impl IntoIterator<Item = &'a HgPath>,
54 files: impl IntoIterator<Item = &'a HgPath>,
55 ) -> Result<(), CommandError> {
55 ) -> Result<(), CommandError> {
56 let cwd = HgPathBuf::from(get_bytes_from_path(hg::utils::current_dir()?));
57 let working_directory = repo.working_directory_path();
58 let working_directory = current_dir()?.join(working_directory); // Make it absolute
59 let working_directory =
60 HgPathBuf::from(get_bytes_from_path(working_directory));
61
62 let mut stdout = ui.stdout_buffer();
56 let mut stdout = ui.stdout_buffer();
63
57
58 let cwd = current_dir()?;
59 let working_directory = repo.working_directory_path();
60 let working_directory = cwd.join(working_directory); // Make it absolute
61
64 let mut any = false;
62 let mut any = false;
65 for file in files {
63 if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(&working_directory) {
66 any = true;
64 // The current directory is inside the repo, so we can work with
67 let file = working_directory.join(file);
65 // relative paths
68 stdout.write_all(relativize_path(&file, &cwd).as_ref())?;
66 let cwd = HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo));
69 stdout.write_all(b"\n")?;
67 for file in files {
68 any = true;
69 stdout.write_all(relativize_path(&file, &cwd).as_ref())?;
70 stdout.write_all(b"\n")?;
71 }
72 } else {
73 let working_directory =
74 HgPathBuf::from(get_bytes_from_path(working_directory));
75 let cwd = HgPathBuf::from(get_bytes_from_path(cwd));
76 for file in files {
77 any = true;
78 // Absolute path in the filesystem
79 let file = working_directory.join(file);
80 stdout.write_all(relativize_path(&file, &cwd).as_ref())?;
81 stdout.write_all(b"\n")?;
82 }
70 }
83 }
84
71 stdout.flush()?;
85 stdout.flush()?;
72 if any {
86 if any {
73 Ok(())
87 Ok(())
General Comments 0
You need to be logged in to leave comments. Login now