comparison rust/rhg/src/commands/status.rs @ 48490:4a983b69e519

rhg: Add support for ui.ignore and ui.ignore.* config This fixes some but not all failures in `tests/test-hgignore.t` when running with `rhg status` enabled. Differential Revision: https://phab.mercurial-scm.org/D11907
author Simon Sapin <simon.sapin@octobus.net>
date Fri, 10 Dec 2021 14:27:00 +0100
parents 112184713852
children 2afaa0145584
comparison
equal deleted inserted replaced
48489:b5f8d9e55d42 48490:4a983b69e519
19 use hg::lock::LockError; 19 use hg::lock::LockError;
20 use hg::manifest::Manifest; 20 use hg::manifest::Manifest;
21 use hg::matchers::AlwaysMatcher; 21 use hg::matchers::AlwaysMatcher;
22 use hg::repo::Repo; 22 use hg::repo::Repo;
23 use hg::utils::files::get_bytes_from_os_string; 23 use hg::utils::files::get_bytes_from_os_string;
24 use hg::utils::files::get_path_from_bytes;
24 use hg::utils::hg_path::{hg_path_to_path_buf, HgPath}; 25 use hg::utils::hg_path::{hg_path_to_path_buf, HgPath};
25 use hg::{HgPathCow, StatusOptions}; 26 use hg::{HgPathCow, StatusOptions};
26 use log::{info, warn}; 27 use log::{info, warn};
27 use std::io; 28 use std::io;
29 use std::path::PathBuf;
28 30
29 pub const HELP_TEXT: &str = " 31 pub const HELP_TEXT: &str = "
30 Show changed files in the working directory 32 Show changed files in the working directory
31 33
32 This is a pure Rust version of `hg status`. 34 This is a pure Rust version of `hg status`.
211 list_clean: display_states.clean, 213 list_clean: display_states.clean,
212 list_unknown: display_states.unknown, 214 list_unknown: display_states.unknown,
213 list_ignored: display_states.ignored, 215 list_ignored: display_states.ignored,
214 collect_traversed_dirs: false, 216 collect_traversed_dirs: false,
215 }; 217 };
216 let ignore_file = repo.working_directory_vfs().join(".hgignore"); // TODO hardcoded
217 let (mut ds_status, pattern_warnings) = dmap.status( 218 let (mut ds_status, pattern_warnings) = dmap.status(
218 &AlwaysMatcher, 219 &AlwaysMatcher,
219 repo.working_directory_path().to_owned(), 220 repo.working_directory_path().to_owned(),
220 vec![ignore_file], 221 ignore_files(repo, config),
221 options, 222 options,
222 )?; 223 )?;
223 if !pattern_warnings.is_empty() { 224 if !pattern_warnings.is_empty() {
224 warn!("Pattern warnings: {:?}", &pattern_warnings); 225 warn!("Pattern warnings: {:?}", &pattern_warnings);
225 } 226 }
394 } 395 }
395 } 396 }
396 Ok(()) 397 Ok(())
397 } 398 }
398 399
400 fn ignore_files(repo: &Repo, config: &Config) -> Vec<PathBuf> {
401 let mut ignore_files = Vec::new();
402 let repo_ignore = repo.working_directory_vfs().join(".hgignore");
403 if repo_ignore.exists() {
404 ignore_files.push(repo_ignore)
405 }
406 for (key, value) in config.iter_section(b"ui") {
407 if key == b"ignore" || key.starts_with(b"ignore.") {
408 let path = get_path_from_bytes(value);
409 // TODO: expand "~/" and environment variable here, like Python
410 // does with `os.path.expanduser` and `os.path.expandvars`
411
412 let joined = repo.working_directory_path().join(path);
413 ignore_files.push(joined);
414 }
415 }
416 ignore_files
417 }
418
399 // Probably more elegant to use a Deref or Borrow trait rather than 419 // Probably more elegant to use a Deref or Borrow trait rather than
400 // harcode HgPathBuf, but probably not really useful at this point 420 // harcode HgPathBuf, but probably not really useful at this point
401 fn display_status_paths( 421 fn display_status_paths(
402 ui: &Ui, 422 ui: &Ui,
403 repo: &Repo, 423 repo: &Repo,