| 1 |
use clap::Arg; |
| 2 |
use hg::dirstate::status::StatusError; |
| 3 |
use hg::file_patterns::RegexCompleteness; |
| 4 |
use hg::matchers::get_ignore_matcher_pre; |
| 5 |
use hg::matchers::ReSyntax; |
| 6 |
use hg::repo::Repo; |
| 7 |
use hg::warnings::HgWarningContext; |
| 8 |
|
| 9 |
use crate::error::CommandError; |
| 10 |
use crate::ui::print_warnings; |
| 11 |
use crate::ui::Ui; |
| 12 |
|
| 13 |
pub const HELP_TEXT: &str = " |
| 14 |
Show effective hgignore patterns used by rhg. |
| 15 |
|
| 16 |
This is a pure Rust version of `hg debugignore`. |
| 17 |
|
| 18 |
Some options might be missing, check the list below. |
| 19 |
"; |
| 20 |
|
| 21 |
pub fn args() -> clap::Command { |
| 22 |
clap::command!("debugignorerhg") |
| 23 |
.args_override_self(true) |
| 24 |
.arg( |
| 25 |
Arg::new("all-patterns") |
| 26 |
.help("include all patterns, including ones for exact file matches") |
| 27 |
.short('a') |
| 28 |
.action(clap::ArgAction::SetTrue) |
| 29 |
.long("all-patterns"), |
| 30 |
) |
| 31 |
.about(HELP_TEXT) |
| 32 |
} |
| 33 |
|
| 34 |
pub enum WhichPatterns { |
| 35 |
All, |
| 36 |
SlowPathOnly, |
| 37 |
} |
| 38 |
|
| 39 |
pub fn work( |
| 40 |
repo: &Repo, |
| 41 |
ui: &Ui, |
| 42 |
which: WhichPatterns, |
| 43 |
syntax: ReSyntax, |
| 44 |
) -> Result<(), CommandError> { |
| 45 |
let ignore_file = repo.working_directory_vfs().join(".hgignore"); // TODO hardcoded |
| 46 |
let all_patterns = matches!(which, WhichPatterns::All); |
| 47 |
|
| 48 |
let warning_context = HgWarningContext::new(); |
| 49 |
|
| 50 |
let ignore_matcher = get_ignore_matcher_pre( |
| 51 |
vec![ignore_file], |
| 52 |
repo.working_directory_path(), |
| 53 |
&mut |_source, _pattern_bytes| (), |
| 54 |
warning_context.sender(), |
| 55 |
) |
| 56 |
.map_err(StatusError::from)?; |
| 57 |
|
| 58 |
print_warnings(ui, warning_context, repo.working_directory_path()); |
| 59 |
|
| 60 |
let regex_config = if all_patterns { |
| 61 |
RegexCompleteness::Complete |
| 62 |
} else { |
| 63 |
RegexCompleteness::ExcludeExactFiles |
| 64 |
}; |
| 65 |
let ignore_matcher = ignore_matcher |
| 66 |
.build_debug_matcher(regex_config) |
| 67 |
.map_err(StatusError::from)?; |
| 68 |
|
| 69 |
let patterns = ignore_matcher.debug_get_patterns(syntax); |
| 70 |
ui.write_stdout(&patterns)?; |
| 71 |
ui.write_stdout(b"\n")?; |
| 72 |
Ok(()) |
| 73 |
} |
| 74 |
|
| 75 |
pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
| 76 |
let repo = invocation.repo?; |
| 77 |
let args = invocation.subcommand_args; |
| 78 |
|
| 79 |
let all_patterns = args.get_flag("all-patterns"); |
| 80 |
let patterns = if all_patterns { |
| 81 |
WhichPatterns::All |
| 82 |
} else { |
| 83 |
WhichPatterns::SlowPathOnly |
| 84 |
}; |
| 85 |
|
| 86 |
work(repo, invocation.ui, patterns, ReSyntax::Internal) |
| 87 |
} |