Show More
@@ -0,0 +1,40 b'' | |||||
|
1 | use crate::error::CommandError; | |||
|
2 | use clap::SubCommand; | |||
|
3 | use hg; | |||
|
4 | use hg::matchers::get_ignore_matcher; | |||
|
5 | use hg::StatusError; | |||
|
6 | use log::warn; | |||
|
7 | ||||
|
8 | pub const HELP_TEXT: &str = " | |||
|
9 | Show effective hgignore patterns used by rhg. | |||
|
10 | ||||
|
11 | This is a pure Rust version of `hg debugignore`. | |||
|
12 | ||||
|
13 | Some options might be missing, check the list below. | |||
|
14 | "; | |||
|
15 | ||||
|
16 | pub fn args() -> clap::App<'static, 'static> { | |||
|
17 | SubCommand::with_name("debugignorerhg").about(HELP_TEXT) | |||
|
18 | } | |||
|
19 | ||||
|
20 | pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { | |||
|
21 | let repo = invocation.repo?; | |||
|
22 | ||||
|
23 | let ignore_file = repo.working_directory_vfs().join(".hgignore"); // TODO hardcoded | |||
|
24 | ||||
|
25 | let (ignore_matcher, warnings) = get_ignore_matcher( | |||
|
26 | vec![ignore_file], | |||
|
27 | &repo.working_directory_path().to_owned(), | |||
|
28 | &mut |_pattern_bytes| (), | |||
|
29 | ) | |||
|
30 | .map_err(|e| StatusError::from(e))?; | |||
|
31 | ||||
|
32 | if !warnings.is_empty() { | |||
|
33 | warn!("Pattern warnings: {:?}", &warnings); | |||
|
34 | } | |||
|
35 | ||||
|
36 | let patterns = ignore_matcher.debug_get_patterns(); | |||
|
37 | invocation.ui.write_stdout(patterns)?; | |||
|
38 | invocation.ui.write_stdout(b"\n")?; | |||
|
39 | Ok(()) | |||
|
40 | } |
@@ -561,11 +561,11 b" fn build_match<'a, 'b>(" | |||||
561 | /// Parses all "ignore" files with their recursive includes and returns a |
|
561 | /// Parses all "ignore" files with their recursive includes and returns a | |
562 | /// function that checks whether a given file (in the general sense) should be |
|
562 | /// function that checks whether a given file (in the general sense) should be | |
563 | /// ignored. |
|
563 | /// ignored. | |
564 |
pub fn get_ignore_ |
|
564 | pub fn get_ignore_matcher<'a>( | |
565 | mut all_pattern_files: Vec<PathBuf>, |
|
565 | mut all_pattern_files: Vec<PathBuf>, | |
566 | root_dir: &Path, |
|
566 | root_dir: &Path, | |
567 | inspect_pattern_bytes: &mut impl FnMut(&[u8]), |
|
567 | inspect_pattern_bytes: &mut impl FnMut(&[u8]), | |
568 |
) -> PatternResult<(I |
|
568 | ) -> PatternResult<(IncludeMatcher<'a>, Vec<PatternFileWarning>)> { | |
569 | let mut all_patterns = vec![]; |
|
569 | let mut all_patterns = vec![]; | |
570 | let mut all_warnings = vec![]; |
|
570 | let mut all_warnings = vec![]; | |
571 |
|
571 | |||
@@ -588,10 +588,25 b" pub fn get_ignore_function<'a>(" | |||||
588 | all_warnings.extend(warnings); |
|
588 | all_warnings.extend(warnings); | |
589 | } |
|
589 | } | |
590 | let matcher = IncludeMatcher::new(all_patterns)?; |
|
590 | let matcher = IncludeMatcher::new(all_patterns)?; | |
591 | Ok(( |
|
591 | Ok((matcher, all_warnings)) | |
592 | Box::new(move |path: &HgPath| matcher.matches(path)), |
|
592 | } | |
593 | all_warnings, |
|
593 | ||
594 | )) |
|
594 | /// Parses all "ignore" files with their recursive includes and returns a | |
|
595 | /// function that checks whether a given file (in the general sense) should be | |||
|
596 | /// ignored. | |||
|
597 | pub fn get_ignore_function<'a>( | |||
|
598 | all_pattern_files: Vec<PathBuf>, | |||
|
599 | root_dir: &Path, | |||
|
600 | inspect_pattern_bytes: &mut impl FnMut(&[u8]), | |||
|
601 | ) -> PatternResult<(IgnoreFnType<'a>, Vec<PatternFileWarning>)> { | |||
|
602 | let res = | |||
|
603 | get_ignore_matcher(all_pattern_files, root_dir, inspect_pattern_bytes); | |||
|
604 | res.map(|(matcher, all_warnings)| { | |||
|
605 | let res: IgnoreFnType<'a> = | |||
|
606 | Box::new(move |path: &HgPath| matcher.matches(path)); | |||
|
607 | ||||
|
608 | (res, all_warnings) | |||
|
609 | }) | |||
595 | } |
|
610 | } | |
596 |
|
611 | |||
597 | impl<'a> IncludeMatcher<'a> { |
|
612 | impl<'a> IncludeMatcher<'a> { | |
@@ -626,6 +641,10 b" impl<'a> IncludeMatcher<'a> {" | |||||
626 | .chain(self.parents.iter()); |
|
641 | .chain(self.parents.iter()); | |
627 | DirsChildrenMultiset::new(thing, Some(&self.parents)) |
|
642 | DirsChildrenMultiset::new(thing, Some(&self.parents)) | |
628 | } |
|
643 | } | |
|
644 | ||||
|
645 | pub fn debug_get_patterns(&self) -> &[u8] { | |||
|
646 | self.patterns.as_ref() | |||
|
647 | } | |||
629 | } |
|
648 | } | |
630 |
|
649 | |||
631 | impl<'a> Display for IncludeMatcher<'a> { |
|
650 | impl<'a> Display for IncludeMatcher<'a> { |
General Comments 0
You need to be logged in to leave comments.
Login now