summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-10-01 14:36:44 +0200
committerCanop <cano.petrole@gmail.com>2021-10-01 14:36:44 +0200
commit4604efc5ae865fee3c9401ab0b7ea375a8c640c2 (patch)
tree8b6e8d346699a2b2ec664acbc7fbb7963de4233d /src
parent0882307b7c36adc90c50b55551e77eb47c0f97a5 (diff)
add more info in log about gitignore files parsing
Diffstat (limited to 'src')
-rw-r--r--src/git/ignore.rs47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/git/ignore.rs b/src/git/ignore.rs
index 4c6558e..d0f8623 100644
--- a/src/git/ignore.rs
+++ b/src/git/ignore.rs
@@ -7,6 +7,7 @@ use {
lazy_regex::regex,
once_cell::sync::Lazy,
std::{
+ fmt,
fs::File,
io::{BufRead, BufReader, Result},
path::{Path, PathBuf},
@@ -27,6 +28,17 @@ struct GitIgnoreRule {
pattern_options: glob::MatchOptions,
}
+impl fmt::Debug for GitIgnoreRule {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("GitIgnoreRule")
+ .field("ok", &self.ok)
+ .field("directory", &self.directory)
+ .field("filename", &self.filename)
+ .field("pattern", &self.pattern.as_str())
+ .finish()
+ }
+}
+
impl GitIgnoreRule {
/// parse a line of a .gitignore file.
/// The ref_dir is used if the line starts with '/'
@@ -50,19 +62,24 @@ impl GitIgnoreRule {
if has_separator && p.starts_with('/') {
p = ref_dir.to_string_lossy().to_string() + &p;
}
- if let Ok(pattern) = glob::Pattern::new(&p) {
- let pattern_options = glob::MatchOptions {
- case_sensitive: true,
- require_literal_leading_dot: false,
- require_literal_separator: has_separator,
- };
- return Some(GitIgnoreRule {
- ok: c.get(1).is_some(), // if negation
- pattern,
- directory: c.get(3).is_some(),
- filename: !has_separator,
- pattern_options,
- });
+ match glob::Pattern::new(&p) {
+ Ok(pattern) => {
+ let pattern_options = glob::MatchOptions {
+ case_sensitive: true,
+ require_literal_leading_dot: false,
+ require_literal_separator: has_separator,
+ };
+ return Some(GitIgnoreRule {
+ ok: c.get(1).is_some(), // if negation
+ pattern,
+ directory: c.get(3).is_some(),
+ filename: !has_separator,
+ pattern_options,
+ });
+ }
+ Err(e) => {
+ debug!(" wrong glob pattern {:?} : {}", &p, e);
+ }
}
}
}
@@ -71,7 +88,7 @@ impl GitIgnoreRule {
}
/// The rules of a gitignore file
-#[derive(Clone)]
+#[derive(Debug, Clone)]
pub struct GitIgnoreFile {
rules: Vec<GitIgnoreRule>,
}
@@ -147,6 +164,7 @@ impl GitIgnorer {
}
}
if let Ok(gif) = GitIgnoreFile::new(&ignore_file, dir) {
+ debug!("pushing GIF {:#?}", &gif);
chain.push(self.files.alloc(gif));
}
if is_repo {
@@ -210,6 +228,7 @@ impl GitIgnorer {
rule.pattern.matches_path_with(path, rule.pattern_options)
};
if ok {
+ // as we read the rules in reverse, the first applying is OK
return rule.ok;
}
}