diff --git a/rust/rhg/src/commands/files.rs b/rust/rhg/src/commands/files.rs --- a/rust/rhg/src/commands/files.rs +++ b/rust/rhg/src/commands/files.rs @@ -58,28 +58,32 @@ let cwd = current_dir()?; let working_directory = repo.working_directory_path(); let working_directory = cwd.join(working_directory); // Make it absolute + let working_directory_hgpath = + HgPathBuf::from(get_bytes_from_path(working_directory.to_owned())); - let mut any = false; + let outside_repo: bool; + let cwd_hgpath: HgPathBuf; if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(&working_directory) { // The current directory is inside the repo, so we can work with // relative paths - let cwd = HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo)); - for file in files { - any = true; - stdout.write_all(relativize_path(&file, &cwd).as_ref())?; - stdout.write_all(b"\n")?; - } + outside_repo = false; + cwd_hgpath = + HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo)); } else { - let working_directory = - HgPathBuf::from(get_bytes_from_path(working_directory)); - let cwd = HgPathBuf::from(get_bytes_from_path(cwd)); - for file in files { - any = true; - // Absolute path in the filesystem - let file = working_directory.join(file); - stdout.write_all(relativize_path(&file, &cwd).as_ref())?; - stdout.write_all(b"\n")?; + outside_repo = true; + cwd_hgpath = HgPathBuf::from(get_bytes_from_path(cwd)); + } + + let mut any = false; + for file in files { + any = true; + if outside_repo { + let file = working_directory_hgpath.join(file); + stdout.write_all(relativize_path(&file, &cwd_hgpath).as_ref())?; + } else { + stdout.write_all(relativize_path(&file, &cwd_hgpath).as_ref())?; } + stdout.write_all(b"\n")?; } stdout.flush()?;