[Request] [+- ] D10910: rhg: refactor code a little around printing of relative paths
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Fri Jun 25 09:34:24 UTC 2021
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
It's easier to understand when setup to compute relative path is decoupled from
actual iteration over list of files.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D10910
AFFECTED FILES
rust/rhg/src/commands/files.rs
CHANGE DETAILS
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()?;
To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210625/4db3a852/attachment-0001.html>
More information about the Mercurial-patches
mailing list