summaryrefslogtreecommitdiffstats
path: root/ignore/src
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2020-02-17 18:08:47 -0500
committerAndrew Gallant <jamslam@gmail.com>2020-02-17 19:24:53 -0500
commit0bc4f0447b05468f043e06278a3ca2b1c5646f9b (patch)
tree8a7e03399262af04a47ad1397fca74f654bfea5b /ignore/src
parentc95f29e3ba46ef622481995ab01fd9f4e931345c (diff)
style: rustfmt everything
This is why I was so intent on clearing the PR queue. This will effectively invalidate all existing patches, so I wanted to start from a clean slate. We do make one little tweak: we put the default type definitions in their own file and tell rustfmt to keep its grubby mits off of it. We also sort it lexicographically and hopefully will enforce that from here on.
Diffstat (limited to 'ignore/src')
-rw-r--r--ignore/src/default_types.rs244
-rw-r--r--ignore/src/dir.rs77
-rw-r--r--ignore/src/gitignore.rs55
-rw-r--r--ignore/src/lib.rs98
-rw-r--r--ignore/src/overrides.rs18
-rw-r--r--ignore/src/pathutil.rs4
-rw-r--r--ignore/src/types.rs288
-rw-r--r--ignore/src/walk.rs161
8 files changed, 490 insertions, 455 deletions
diff --git a/ignore/src/default_types.rs b/ignore/src/default_types.rs
new file mode 100644
index 00000000..8a077796
--- /dev/null
+++ b/ignore/src/default_types.rs
@@ -0,0 +1,244 @@
+/// This list represents the default file types that ripgrep ships with. In
+/// general, any file format is fair game, although it should generally be
+/// limited to reasonably popular open formats. For other cases, you can add
+/// types to each invocation of ripgrep with the '--type-add' flag.
+///
+/// If you would like to add or improve this list, please file a PR:
+/// https://github.com/BurntSushi/ripgrep
+///
+/// Please try to keep this list sorted lexicographically and wrapped to 79
+/// columns (inclusive).
+#[rustfmt::skip]
+pub const DEFAULT_TYPES: &[(&str, &[&str])] = &[
+ ("agda", &["*.agda", "*.lagda"]),
+ ("aidl", &["*.aidl"]),
+ ("amake", &["*.mk", "*.bp"]),
+ ("asciidoc", &["*.adoc", "*.asc", "*.asciidoc"]),
+ ("asm", &["*.asm", "*.s", "*.S"]),
+ ("asp", &[
+ "*.aspx", "*.aspx.cs", "*.aspx.cs", "*.ascx", "*.ascx.cs", "*.ascx.vb",
+ ]),
+ ("ats", &["*.ats", "*.dats", "*.sats", "*.hats"]),
+ ("avro", &["*.avdl", "*.avpr", "*.avsc"]),
+ ("awk", &["*.awk"]),
+ ("bazel", &["*.bzl", "WORKSPACE", "BUILD", "BUILD.bazel"]),
+ ("bitbake", &["*.bb", "*.bbappend", "*.bbclass", "*.conf", "*.inc"]),
+ ("brotli", &["*.br"]),
+ ("buildstream", &["*.bst"]),
+ ("bzip2", &["*.bz2", "*.tbz2"]),
+ ("c", &["*.[chH]", "*.[chH].in", "*.cats"]),
+ ("cabal", &["*.cabal"]),
+ ("cbor", &["*.cbor"]),
+ ("ceylon", &["*.ceylon"]),
+ ("clojure", &["*.clj", "*.cljc", "*.cljs", "*.cljx"]),
+ ("cmake", &["*.cmake", "CMakeLists.txt"]),
+ ("coffeescript", &["*.coffee"]),
+ ("config", &["*.cfg", "*.conf", "*.config", "*.ini"]),
+ ("cpp", &[
+ "*.[ChH]", "*.cc", "*.[ch]pp", "*.[ch]xx", "*.hh", "*.inl",
+ "*.[ChH].in", "*.cc.in", "*.[ch]pp.in", "*.[ch]xx.in", "*.hh.in",
+ ]),
+ ("creole", &["*.creole"]),
+ ("crystal", &["Projectfile", "*.cr"]),
+ ("cs", &["*.cs"]),
+ ("csharp", &["*.cs"]),
+ ("cshtml", &["*.cshtml"]),
+ ("css", &["*.css", "*.scss"]),
+ ("csv", &["*.csv"]),
+ ("cython", &["*.pyx", "*.pxi", "*.pxd"]),
+ ("d", &["*.d"]),
+ ("dart", &["*.dart"]),
+ ("dhall", &["*.dhall"]),
+ ("diff", &["*.patch", "*.diff"]),
+ ("docker", &["*Dockerfile*"]),
+ ("edn", &["*.edn"]),
+ ("elisp", &["*.el"]),
+ ("elixir", &["*.ex", "*.eex", "*.exs"]),
+ ("elm", &["*.elm"]),
+ ("erb", &["*.erb"]),
+ ("erlang", &["*.erl", "*.hrl"]),
+ ("fidl", &["*.fidl"]),
+ ("fish", &["*.fish"]),
+ ("fortran", &[
+ "*.f", "*.F", "*.f77", "*.F77", "*.pfo",
+ "*.f90", "*.F90", "*.f95", "*.F95",
+ ]),
+ ("fsharp", &["*.fs", "*.fsx", "*.fsi"]),
+ ("gap", &["*.g", "*.gap", "*.gi", "*.gd", "*.tst"]),
+ ("gn", &["*.gn", "*.gni"]),
+ ("go", &["*.go"]),
+ ("gradle", &["*.gradle"]),
+ ("groovy", &["*.groovy", "*.gradle"]),
+ ("gzip", &["*.gz", "*.tgz"]),
+ ("h", &["*.h", "*.hpp"]),
+ ("haml", &["*.haml"]),
+ ("haskell", &["*.hs", "*.lhs", "*.cpphs", "*.c2hs", "*.hsc"]),
+ ("hbs", &["*.hbs"]),
+ ("hs", &["*.hs", "*.lhs"]),
+ ("html", &["*.htm", "*.html", "*.ejs"]),
+ ("idris", &["*.idr", "*.lidr"]),
+ ("java", &["*.java", "*.jsp", "*.jspx", "*.properties"]),
+ ("jinja", &["*.j2", "*.jinja", "*.jinja2"]),
+ ("jl", &["*.jl"]),
+ ("js", &["*.js", "*.jsx", "*.vue"]),
+ ("json", &["*.json", "composer.lock"]),
+ ("jsonl", &["*.jsonl"]),
+ ("julia", &["*.jl"]),
+ ("jupyter", &["*.ipynb", "*.jpynb"]),
+ ("kotlin", &["*.kt", "*.kts"]),
+ ("less", &["*.less"]),
+ ("license", &[
+ // General
+ "COPYING", "COPYING[.-]*",
+ "COPYRIGHT", "COPYRIGHT[.-]*",
+ "EULA", "EULA[.-]*",
+ "licen[cs]e", "licen[cs]e.*",
+ "LICEN[CS]E", "LICEN[CS]E[.-]*", "*[.-]LICEN[CS]E*",
+ "NOTICE", "NOTICE[.-]*",
+ "PATENTS", "PATENTS[.-]*",
+ "UNLICEN[CS]E", "UNLICEN[CS]E[.-]*",
+ // GPL (gpl.txt, etc.)
+ "agpl[.-]*",
+ "gpl[.-]*",
+ "lgpl[.-]*",
+ // Other license-specific (APACHE-2.0.txt, etc.)
+ "AGPL-*[0-9]*",
+ "APACHE-*[0-9]*",
+ "BSD-*[0-9]*",
+ "CC-BY-*",
+ "GFDL-*[0-9]*",
+ "GNU-*[0-9]*",
+ "GPL-*[0-9]*",
+ "LGPL-*[0-9]*",
+ "MIT-*[0-9]*",
+ "MPL-*[0-9]*",
+ "OFL-*[0-9]*",
+ ]),
+ ("lisp", &["*.el", "*.jl", "*.lisp", "*.lsp", "*.sc", "*.scm"]),
+ ("lock", &["*.lock", "package-lock.json"]),
+ ("log", &["*.log"]),
+ ("lua", &["*.lua"]),
+ ("lz4", &["*.lz4"]),
+ ("lzma", &["*.lzma"]),
+ ("m4", &["*.ac", "*.m4"]),
+ ("make", &[
+ "[Gg][Nn][Uu]makefile", "[Mm]akefile",
+ "[Gg][Nn][Uu]makefile.am", "[Mm]akefile.am",
+ "[Gg][Nn][Uu]makefile.in", "[Mm]akefile.in",
+ "*.mk", "*.mak"
+ ]),
+ ("mako", &["*.mako", "*.mao"]),
+ ("man", &["*.[0-9lnpx]", "*.[0-9][cEFMmpSx]"]),
+ ("markdown", &["*.markdown", "*.md", "*.mdown", "*.mkdn"]),
+ ("matlab", &["*.m"]),
+ ("md", &["*.markdown", "*.md", "*.mdown", "*.mkdn"]),
+ ("mk", &["mkfile"]),
+ ("ml", &["*.ml"]),
+ ("msbuild", &[
+ "*.csproj", "*.fsproj", "*.vcxproj", "*.proj", "*.props", "*.targets",
+ ]),
+ ("nim", &["*.nim", "*.nimf", "*.nimble", "*.nims"]),
+ ("nix", &["*.nix"]),
+ ("objc", &["*.h", "*.m"]),
+ ("objcpp", &["*.h", "*.mm"]),
+ ("ocaml", &["*.ml", "*.mli", "*.mll", "*.mly"]),
+ ("org", &["*.org", "*.org_archive"]),
+ ("pascal", &["*.pas", "*.dpr", "*.lpr", "*.pp", "*.inc"]),
+ ("pdf", &["*.pdf"]),
+ ("perl", &["*.perl", "*.pl", "*.PL", "*.plh", "*.plx", "*.pm", "*.t"]),
+ ("php", &["*.php", "*.php3", "*.php4", "*.php5", "*.phtml"]),
+ ("pod", &["*.pod"]),
+ ("postscript", &["*.eps", "*.ps"]),
+ ("protobuf", &["*.proto"]),
+ ("ps", &["*.cdxml", "*.ps1", "*.ps1xml", "*.psd1", "*.psm1"]),
+ ("puppet", &["*.erb", "*.pp", "*.rb"]),
+ ("purs", &["*.purs"]),
+ ("py", &["*.py"]),
+ ("qmake", &["*.pro", "*.pri", "*.prf"]),
+ ("qml", &["*.qml"]),
+ ("r", &["*.R", "*.r", "*.Rmd", "*.Rnw"]),
+ ("rdoc", &["*.rdoc"]),
+ ("readme", &["README*", "*README"]),
+ ("robot", &["*.robot"]),
+ ("rst", &["*.rst"]),
+ ("ruby", &["Gemfile", "*.gemspec", ".irbrc", "Rakefile", "*.rb"]),
+ ("rust", &["*.rs"]),
+ ("sass", &["*.sass", "*.scss"]),
+ ("scala", &["*.scala", "*.sbt"]),
+ ("sh", &[
+ // Portable/misc. init files
+ ".login", ".logout", ".profile", "profile",
+ // bash-specific init files
+ ".bash_login", "bash_login",
+ ".bash_logout", "bash_logout",
+ ".bash_profile", "bash_profile",
+ ".bashrc", "bashrc", "*.bashrc",
+ // csh-specific init files
+ ".cshrc", "*.cshrc",
+ // ksh-specific init files
+ ".kshrc", "*.kshrc",
+ // tcsh-specific init files
+ ".tcshrc",
+ // zsh-specific init files
+ ".zshenv", "zshenv",
+ ".zlogin", "zlogin",
+ ".zlogout", "zlogout",
+ ".zprofile", "zprofile",
+ ".zshrc", "zshrc",
+ // Extensions
+ "*.bash", "*.csh", "*.ksh", "*.sh", "*.tcsh", "*.zsh",
+ ]),
+ ("slim", &["*.skim", "*.slim", "*.slime"]),
+ ("smarty", &["*.tpl"]),
+ ("sml", &["*.sml", "*.sig"]),
+ ("soy", &["*.soy"]),
+ ("spark", &["*.spark"]),
+ ("spec", &["*.spec"]),
+ ("sql", &["*.sql", "*.psql"]),
+ ("stylus", &["*.styl"]),
+ ("sv", &["*.v", "*.vg", "*.sv", "*.svh", "*.h"]),
+ ("svg", &["*.svg"]),
+ ("swift", &["*.swift"]),
+ ("swig", &["*.def", "*.i"]),
+ ("systemd", &[
+ "*.automount", "*.conf", "*.device", "*.link", "*.mount", "*.path",
+ "*.scope", "*.service", "*.slice", "*.socket", "*.swap", "*.target",
+ "*.timer",
+ ]),
+ ("taskpaper", &["*.taskpaper"]),
+ ("tcl", &["*.tcl"]),
+ ("tex", &["*.tex", "*.ltx", "*.cls", "*.sty", "*.bib", "*.dtx", "*.ins"]),
+ ("textile", &["*.textile"]),
+ ("tf", &["*.tf"]),
+ ("thrift", &["*.thrift"]),
+ ("toml", &["*.toml", "Cargo.lock"]),
+ ("ts", &["*.ts", "*.tsx"]),
+ ("twig", &["*.twig"]),
+ ("txt", &["*.txt"]),
+ ("typoscript", &["*.typoscript", "*.ts"]),
+ ("vala", &["*.vala"]),
+ ("vb", &["*.vb"]),
+ ("verilog", &["*.v", "*.vh", "*.sv", "*.svh"]),
+ ("vhdl", &["*.vhd", "*.vhdl"]),
+ ("vim", &["*.vim"]),
+ ("vimscript", &["*.vim"]),
+ ("webidl", &["*.idl", "*.webidl", "*.widl"]),
+ ("wiki", &["*.mediawiki", "*.wiki"]),
+ ("xml", &[
+ "*.xml", "*.xml.dist", "*.dtd", "*.xsl", "*.xslt", "*.xsd", "*.xjb",
+ "*.rng", "*.sch", "*.xhtml",
+ ]),
+ ("xz", &["*.xz", "*.txz"]),
+ ("yacc", &["*.y"]),
+ ("yaml", &["*.yaml", "*.yml"]),
+ ("zig", &["*.zig"]),
+ ("zsh", &[
+ ".zshenv", "zshenv",
+ ".zlogin", "zlogin",
+ ".zlogout", "zlogout",
+ ".zprofile", "zprofile",
+ ".zshrc", "zshrc",
+ "*.zsh",
+ ]),
+ ("zstd", &["*.zst", "*.zstd"]),
+];
diff --git a/ignore/src/dir.rs b/ignore/src/dir.rs
index 3f4d10bb..83a1faf9 100644
--- a/ignore/src/dir.rs
+++ b/ignore/src/dir.rs
@@ -157,7 +157,10 @@ impl Ignore {
///
/// Note that this can only be called on an `Ignore` matcher with no
/// parents (i.e., `is_root` returns `true`). This will panic otherwise.
- pub fn add_parents<P: AsRef<Path>>(&self, path: P) -> (Ignore, Option<Error>) {
+ pub fn add_parents<P: AsRef<Path>>(
+ &self,
+ path: P,
+ ) -> (Ignore, Option<Error>) {
if !self.0.opts.parents
&& !self.0.opts.git_ignore
&& !self.0.opts.git_exclude
@@ -218,7 +221,10 @@ impl Ignore {
/// returned if it exists.
///
/// Note that all I/O errors are completely ignored.
- pub fn add_child<P: AsRef<Path>>(&self, dir: P) -> (Ignore, Option<Error>) {
+ pub fn add_child<P: AsRef<Path>>(
+ &self,
+ dir: P,
+ ) -> (Ignore, Option<Error>) {
let (ig, err) = self.add_child_path(dir.as_ref());
(Ignore(Arc::new(ig)), err)
}
@@ -313,7 +319,8 @@ impl Ignore {
/// Returns true if at least one type of ignore rule should be matched.
fn has_any_ignore_rules(&self) -> bool {
let opts = self.0.opts;
- let has_custom_ignore_files = !self.0.custom_ignore_filenames.is_empty();
+ let has_custom_ignore_files =
+ !self.0.custom_ignore_filenames.is_empty();
let has_explicit_ignores = !self.0.explicit_ignores.is_empty();
opts.ignore
@@ -325,7 +332,10 @@ impl Ignore {
}
/// Like `matched`, but works with a directory entry instead.
- pub fn matched_dir_entry<'a>(&'a self, dent: &DirEntry) -> Match<IgnoreMatch<'a>> {
+ pub fn matched_dir_entry<'a>(
+ &'a self,
+ dent: &DirEntry,
+ ) -> Match<IgnoreMatch<'a>> {
let m = self.matched(dent.path(), dent.is_dir());
if m.is_none() && self.0.opts.hidden && is_hidden(dent) {
return Match::Ignore(IgnoreMatch::hidden());
@@ -337,7 +347,11 @@ impl Ignore {
/// ignored or not.
///
/// The match contains information about its origin.
- fn matched<'a, P: AsRef<Path>>(&'a self, path: P, is_dir: bool) -> Match<IgnoreMatch<'a>> {
+ fn matched<'a, P: AsRef<Path>>(
+ &'a self,
+ path: P,
+ is_dir: bool,
+ ) -> Match<IgnoreMatch<'a>> {
// We need to be careful with our path. If it has a leading ./, then
// strip it because it causes nothing but trouble.
let mut path = path.as_ref();
@@ -368,7 +382,8 @@ impl Ignore {
}
}
if !self.0.types.is_empty() {
- let mat = self.0.types.matched(path, is_dir).map(IgnoreMatch::types);
+ let mat =
+ self.0.types.matched(path, is_dir).map(IgnoreMatch::types);
if mat.is_ignore() {
return mat;
} else if mat.is_whitelist() {
@@ -380,17 +395,20 @@ impl Ignore {
/// Performs matching only on the ignore files for this directory and
/// all parent directories.
- fn matched_ignore<'a>(&'a self, path: &Path, is_dir: bool) -> Match<IgnoreMatch<'a>> {
- let (mut m_custom_ignore, mut m_ignore, mut m_gi, mut m_gi_exclude, mut m_explicit) = (
- Match::None,
- Match::None,
- Match::None,
- Match::None,
- Match::None,
- );
+ fn matched_ignore<'a>(
+ &'a self,
+ path: &Path,
+ is_dir: bool,
+ ) -> Match<IgnoreMatch<'a>> {
+ let (
+ mut m_custom_ignore,
+ mut m_ignore,
+ mut m_gi,
+ mut m_gi_exclude,
+ mut m_explicit,
+ ) = (Match::None, Match::None, Match::None, Match::None, Match::None);
let any_git =
- !self.0.opts.require_git
- || self.parents().any(|ig| ig.0.has_git);
+ !self.0.opts.require_git || self.parents().any(|ig| ig.0.has_git);
let mut saw_git = false;
for ig in self.parents().take_while(|ig| !ig.0.is_absolute_parent) {
if m_custom_ignore.is_none() {
@@ -422,7 +440,9 @@ impl Ignore {
if self.0.opts.parents {
if let Some(abs_parent_path) = self.absolute_base() {
let path = abs_parent_path.join(path);
- for ig in self.parents().skip_while(|ig| !ig.0.is_absolute_parent) {
+ for ig in
+ self.parents().skip_while(|ig| !ig.0.is_absolute_parent)
+ {
if m_custom_ignore.is_none() {
m_custom_ignore =
ig.0.custom_ignore_matcher
@@ -575,7 +595,9 @@ impl IgnoreBuilder {
is_absolute_parent: true,
absolute_base: None,
explicit_ignores: Arc::new(self.explicit_ignores.clone()),
- custom_ignore_filenames: Arc::new(self.custom_ignore_filenames.clone()),
+ custom_ignore_filenames: Arc::new(
+ self.custom_ignore_filenames.clone(),
+ ),
custom_ignore_matcher: Gitignore::empty(),
ignore_matcher: Gitignore::empty(),
git_global_matcher: Arc::new(git_global_matcher),
@@ -622,8 +644,7 @@ impl IgnoreBuilder {
&mut self,
file_name: S,
) -> &mut IgnoreBuilder {
- self.custom_ignore_filenames
- .push(file_name.as_ref().to_os_string());
+ self.custom_ignore_filenames.push(file_name.as_ref().to_os_string());
self
}
@@ -705,7 +726,10 @@ impl IgnoreBuilder {
/// Process ignore files case insensitively
///
/// This is disabled by default.
- pub fn ignore_case_insensitive(&mut self, yes: bool) -> &mut IgnoreBuilder {
+ pub fn ignore_case_insensitive(
+ &mut self,
+ yes: bool,
+ ) -> &mut IgnoreBuilder {
self.opts.ignore_case_insensitive = yes;
self
}
@@ -850,10 +874,8 @@ mod tests {
let (gi, err) = Gitignore::new(td.path().join("not-an-ignore"));
assert!(err.is_none());
- let (ig, err) = IgnoreBuilder::new()
- .add_ignore(gi)
- .build()
- .add_child(td.path());
+ let (ig, err) =
+ IgnoreBuilder::new().add_ignore(gi).build().add_child(td.path());
assert!(err.is_none());
assert!(ig.matched("foo", false).is_ignore());
assert!(ig.matched("bar", false).is_whitelist());
@@ -1125,9 +1147,8 @@ mod tests {
mkdirp(git_dir.join("info"));
wfile(git_dir.join("info/exclude"), "ignore_me");
mkdirp(git_dir.join("worktrees/linked-worktree"));
- let commondir_path = || {
- git_dir.join("worktrees/linked-worktree/commondir")
- };
+ let commondir_path =
+ || git_dir.join("worktrees/linked-worktree/commondir");
mkdirp(td.path().join("linked-worktree"));
let worktree_git_dir_abs = format!(
"gitdir: {}",
diff --git a/ignore/src/gitignore.rs b/ignore/src/gitignore.rs
index e9510dd0..2b8844b9 100644
--- a/ignore/src/gitignore.rs
+++ b/ignore/src/gitignore.rs
@@ -332,13 +332,10 @@ impl GitignoreBuilder {
pub fn build(&self) -> Result<Gitignore, Error> {
let nignore = self.globs.iter().filter(|g| !g.is_whitelist()).count();
let nwhite = self.globs.iter().filter(|g| g.is_whitelist()).count();
- let set =
- self.builder.build().map_err(|err| {
- Error::Glob {
- glob: None,
- err: err.to_string(),
- }
- })?;
+ let set = self
+ .builder
+ .build()
+ .map_err(|err| Error::Glob { glob: None, err: err.to_string() })?;
Ok(Gitignore {
set: set,
root: self.root.clone(),
@@ -499,18 +496,15 @@ impl GitignoreBuilder {
if glob.actual.ends_with("/**") {
glob.actual = format!("{}/*", glob.actual);
}
- let parsed =
- GlobBuilder::new(&glob.actual)
- .literal_separator(true)
- .case_insensitive(self.case_insensitive)
- .backslash_escape(true)
- .build()
- .map_err(|err| {
- Error::Glob {
- glob: Some(glob.original.clone()),
- err: err.kind().to_string(),
- }
- })?;
+ let parsed = GlobBuilder::new(&glob.actual)
+ .literal_separator(true)
+ .case_insensitive(self.case_insensitive)
+ .backslash_escape(true)
+ .build()
+ .map_err(|err| Error::Glob {
+ glob: Some(glob.original.clone()),
+ err: err.kind().to_string(),
+ })?;
self.builder.add(parsed);
self.globs.push(glob);
Ok(self)
@@ -599,9 +593,8 @@ fn parse_excludes_file(data: &[u8]) -> Option<PathBuf> {
// probably works in more circumstances. I guess we would ideally have
// a full INI parser. Yuck.
lazy_static! {
- static ref RE: Regex = Regex::new(
- r"(?im)^\s*excludesfile\s*=\s*(.+)\s*$"
- ).unwrap();
+ static ref RE: Regex =
+ Regex::new(r"(?im)^\s*excludesfile\s*=\s*(.+)\s*$").unwrap();
};
let caps = match RE.captures(data) {
None => return None,
@@ -630,8 +623,8 @@ fn home_dir() -> Option<PathBuf> {
#[cfg(test)]
mod tests {
- use std::path::Path;
use super::{Gitignore, GitignoreBuilder};
+ use std::path::Path;
fn gi_from_str<P: AsRef<Path>>(root: P, s: &str) -> Gitignore {
let mut builder = GitignoreBuilder::new(root);
@@ -726,8 +719,11 @@ mod tests {
not_ignored!(ignot12, ROOT, "\n\n\n", "foo");
not_ignored!(ignot13, ROOT, "foo/**", "foo", true);
not_ignored!(
- ignot14, "./third_party/protobuf", "m4/ltoptions.m4",
- "./third_party/protobuf/csharp/src/packages/repositories.config");
+ ignot14,
+ "./third_party/protobuf",
+ "m4/ltoptions.m4",
+ "./third_party/protobuf/csharp/src/packages/repositories.config"
+ );
not_ignored!(ignot15, ROOT, "!/bar", "foo/bar");
not_ignored!(ignot16, ROOT, "*\n!**/", "foo", true);
not_ignored!(ignot17, ROOT, "src/*.rs", "src/grep/src/main.rs");
@@ -771,9 +767,12 @@ mod tests {
#[test]
fn case_insensitive() {
let gi = GitignoreBuilder::new(ROOT)
- .case_insensitive(true).unwrap()
- .add_str(None, "*.html").unwrap()
- .build().unwrap();
+ .case_insensitive(true)
+ .unwrap()
+ .add_str(None, "*.html")
+ .unwrap()
+ .build()
+ .unwrap();
assert!(gi.matched("foo.html", false).is_ignore());
assert!(gi.matched("foo.HTML", false).is_ignore());
assert!(!gi.matched("foo.htm", false).is_ignore());
diff --git a/ignore/src/lib.rs b/ignore/src/lib.rs
index 6cbf4af2..71b112c7 100644
--- a/ignore/src/lib.rs
+++ b/ignore/src/lib.rs
@@ -66,10 +66,11 @@ use std::io;
use std::path::{Path, PathBuf};
pub use walk::{
- DirEntry, Walk, WalkBuilder, WalkParallel, WalkState,
- ParallelVisitorBuilder, ParallelVisitor,
+ DirEntry, ParallelVisitor, ParallelVisitorBuilder, Walk, WalkBuilder,
+ WalkParallel, WalkState,
};
+mod default_types;
mod dir;
pub mod gitignore;
pub mod overrides;
@@ -137,22 +138,16 @@ impl Clone for Error {
fn clone(&self) -> Error {
match *self {
Error::Partial(ref errs) => Error::Partial(errs.clone()),
- Error::WithLineNumber { line, ref err } => Error::WithLineNumber {
- line: line,
- err: err.clone(),
- },
- Error::WithPath { ref path, ref err } => Error::WithPath {
- path: path.clone(),
- err: err.clone(),
- },
- Error::WithDepth { depth, ref err } => Error::WithDepth {
- depth: depth,
- err: err.clone(),
- },
- Error::Loop {
- ref ancestor,
- ref child,
- } => Error::Loop {
+ Error::WithLineNumber { line, ref err } => {
+ Error::WithLineNumber { line: line, err: err.clone() }
+ }
+ Error::WithPath { ref path, ref err } => {
+ Error::WithPath { path: path.clone(), err: err.clone() }
+ }
+ Error::WithDepth { depth, ref err } => {
+ Error::WithDepth { depth: depth, err: err.clone() }
+ }
+ Error::Loop { ref ancestor, ref child } => Error::Loop {
ancestor: ancestor.clone(),
child: child.clone(),
},
@@ -160,11 +155,12 @@ impl Clone for Error {
Some(e) => Error::Io(io::Error::from_raw_os_error(e)),
None => Error::Io(io::Error::new(err.kind(), err.to_string())),
},
- Error::Glob { ref glob, ref err } => Error::Glob {
- glob: glob.clone(),
- err: err.clone(),
- },
- Error::UnrecognizedFileType(ref err) => Error::UnrecognizedFileType(err.clone()),
+ Error::Glob { ref glob, ref err } => {
+ Error::Glob { glob: glob.clone(), err: err.clone() }
+ }
+ Error::UnrecognizedFileType(ref err) => {
+ Error::UnrecognizedFileType(err.clone())
+ }
Error::InvalidDefinition => Error::InvalidDefinition,
}
}
@@ -221,19 +217,14 @@ impl Error {
/// Turn an error into a tagged error with the given depth.
fn with_depth(self, depth: usize) -> Error {
- Error::WithDepth {
- depth: depth,
- err: Box::new(self),
- }
+ Error::WithDepth { depth: depth, err: Box::new(self) }
}
/// Turn an error into a tagged error with the given file path and line
/// number. If path is empty, then it is omitted from the error.
fn tagged<P: AsRef<Path>>(self, path: P, lineno: u64) -> Error {
- let errline = Error::WithLineNumber {
- line: lineno,
- err: Box::new(self),
- };
+ let errline =
+ Error::WithLineNumber { line: lineno, err: Box::new(self) };
if path.as_ref().as_os_str().is_empty() {
return errline;
}
@@ -255,10 +246,7 @@ impl Error {
let path = err.path().map(|p| p.to_path_buf());
let mut ig_err = Error::Io(io::Error::from(err));
if let Some(path) = path {
- ig_err = Error::WithPath {
- path: path,
- err: Box::new(ig_err),
- };
+ ig_err = Error::WithPath { path: path, err: Box::new(ig_err) };
}
ig_err
}
@@ -285,16 +273,18 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Partial(ref errs) => {
- let msgs: Vec<String> = errs.iter().map(|err| err.to_string()).collect();
+ let msgs: Vec<String> =
+ errs.iter().map(|err| err.to_string()).collect();
write!(f, "{}", msgs.join("\n"))
}
- Error::WithLineNumber { line, ref err } => write!(f, "line {}: {}", line, err),
- Error::WithPath { ref path, ref err } => write!(f, "{}: {}", path.display(), err),
+ Error::WithLineNumber { line, ref err } => {
+ write!(f, "line {}: {}", line, err)
+ }
+ Error::WithPath { ref path, ref err } => {
+ write!(f, "{}: {}", path.display(), err)
+ }
Error::WithDepth { ref err, .. } => err.fmt(f),
- Error::Loop {
- ref ancestor,
- ref child,
- } => write!(
+ Error::Loop { ref ancestor, ref child } => write!(
f,
"File system loop found: \
{} points to an ancestor {}",
@@ -302,15 +292,13 @@ impl fmt::Display for Error {
ancestor.display()
),
Error::Io(ref err) => err.fmt(f),
- Error::Glob {
- glob: None,
- ref err,
- } => write!(f, "{}", err),
- Error::Glob {
- glob: Some(ref glob),
- ref err,
- } => write!(f, "error parsing glob '{}': {}", glob, err),
- Error::UnrecognizedFileType(ref ty) => write!(f, "unrecognized file type: {}", ty),
+ Error::Glob { glob: None, ref err } => write!(f, "{}", err),
+ Error::Glob { glob: Some(ref glob), ref err } => {
+ write!(f, "error parsing glob '{}': {}", glob, err)
+ }
+ Error::UnrecognizedFileType(ref ty) => {
+ write!(f, "unrecognized file type: {}", ty)
+ }
Error::InvalidDefinition => write!(
f,
"invalid definition (format is type:glob, e.g., \
@@ -456,7 +444,8 @@ mod tests {
use std::result;
/// A convenient result type alias.
- pub type Result<T> = result::Result<T, Box<dyn error::Error + Send + Sync>>;
+ pub type Result<T> =
+ result::Result<T, Box<dyn error::Error + Send + Sync>>;
macro_rules! err {
($($tt:tt)*) => {
@@ -494,8 +483,9 @@ mod tests {
if path.is_dir() {
continue;
}
- fs::create_dir_all(&path)
- .map_err(|e| err!("failed to create {}: {}", path.display(), e))?;
+ fs::create_dir_all(&path).map_err(|e| {
+ err!("failed to create {}: {}", path.display(), e)
+ })?;
return Ok(TempDir(path));
}
Err(err!("failed to create temp dir after {} tries", TRIES))
diff --git a/ignore/src/overrides.rs b/ignore/src/overrides.rs
index 08dbdac2..7c03fbf5 100644
--- a/ignore/src/overrides.rs
+++ b/ignore/src/overrides.rs
@@ -115,9 +115,7 @@ impl OverrideBuilder {
///
/// Matching is done relative to the directory path provided.
pub fn new<P: AsRef<Path>>(path: P) -> OverrideBuilder {
- OverrideBuilder {
- builder: GitignoreBuilder::new(path),
- }
+ OverrideBuilder { builder: GitignoreBuilder::new(path) }
}
/// Builds a new override matcher from the globs added so far.
@@ -240,9 +238,12 @@ mod tests {
#[test]
fn case_insensitive() {
let ov = OverrideBuilder::new(ROOT)
- .case_insensitive(true).unwrap()
- .add("*.html").unwrap()
- .build().unwrap();
+ .case_insensitive(true)
+ .unwrap()
+ .add("*.html")
+ .unwrap()
+ .build()
+ .unwrap();
assert!(ov.matched("foo.html", false).is_whitelist());
assert!(ov.matched("foo.HTML", false).is_whitelist());
assert!(ov.matched("foo.htm", false).is_ignore());
@@ -251,9 +252,8 @@ mod tests {
#[test]
fn default_case_sensitive() {
- let ov = OverrideBuilder::new(ROOT)
- .add("*.html").unwrap()
- .build().unwrap();
+ let ov =
+ OverrideBuilder::new(ROOT).add("*.html").unwrap().build().unwrap();
assert!(ov.matched("foo.html", false).is_whitelist());
assert!(ov.matched("foo.HTML", false).is_ignore());
assert!(ov.matched("foo.htm", false).is_ignore());
diff --git a/ignore/src/pathutil.rs b/ignore/src/pathutil.rs
index fbbc0f89..210d1ecb 100644
--- a/ignore/src/pathutil.rs
+++ b/ignore/src/pathutil.rs
@@ -91,8 +91,8 @@ pub fn strip_prefix<'a, P: AsRef<Path> + ?Sized>(
/// the empty string.
#[cfg(unix)]
pub fn is_file_name<P: AsRef<Path>>(path: P) -> bool {
- use std::os::unix::ffi::OsStrExt;
use memchr::memchr;
+ use std::os::unix::ffi::OsStrExt;
let path = path.as_ref().as_os_str().as_bytes();
memchr(b'/', path).is_none()
@@ -113,8 +113,8 @@ pub fn is_file_name<P: AsRef<Path>>(path: P) -> bool {
pub fn file_name<'a, P: AsRef<Path> + ?Sized>(
path: &'a P,
) -> Option<&'a OsStr> {
- use std::os::unix::ffi::OsStrExt;
use memchr::memrchr;
+ use std::os::unix::ffi::OsStrExt;
let path = path.as_ref().as_os_str().as_bytes();
if path.is_empty() {
diff --git a/ignore/src/types.rs b/ignore/src/types.rs
index 0b446447..d77e54eb 100644
--- a/ignore/src/types.rs
+++ b/ignore/src/types.rs
@@ -93,243 +93,10 @@ use globset::{GlobBuilder, GlobSet, GlobSetBuilder};
use regex::Regex;
use thread_local::ThreadLocal;
+use default_types::DEFAULT_TYPES;
use pathutil::file_name;
use {Error, Match};
-const DEFAULT_TYPES: &'static [(&'static str, &'static [&'static str])] = &[
- ("agda", &["*.agda", "*.lagda"]),
- ("ats", &["*.ats", "*.dats", "*.sats", "*.hats"]),
- ("aidl", &["*.aidl"]),
- ("amake", &["*.mk", "*.bp"]),
- ("asciidoc", &["*.adoc", "*.asc", "*.asciidoc"]),
- ("asm", &["*.asm", "*.s", "*.S"]),
- ("asp", &["*.aspx", "*.aspx.cs", "*.aspx.cs", "*.ascx", "*.ascx.cs", "*.ascx.vb"]),
- ("avro", &["*.avdl", "*.avpr", "*.avsc"]),
- ("awk", &["*.awk"]),
- ("bazel", &["*.bzl", "WORKSPACE", "BUILD", "BUILD.bazel"]),
- ("bitbake", &["*.bb", "*.bbappend", "*.bbclass", "*.conf", "*.inc"]),
- ("brotli", &["*.br"]),
- ("buildstream", &["*.bst"]),
- ("bzip2", &["*.bz2", "*.tbz2"]),
- ("c", &["*.[chH]", "*.[chH].in", "*.cats"]),
- ("cabal", &["*.cabal"]),
- ("cbor", &["*.cbor"]),
- ("ceylon", &["*.ceylon"]),
- ("clojure", &["*.clj", "*.cljc", "*.cljs", "*.cljx"]),
- ("cmake", &["*.cmake", "CMakeLists.txt"]),
- ("coffeescript", &["*.coffee"]),
- ("creole", &["*.creole"]),
- ("config", &["*.cfg", "*.conf", "*.config", "*.ini"]),
- ("cpp", &[
- "*.[ChH]", "*.cc", "*.[ch]pp", "*.[ch]xx", "*.hh", "*.inl",
- "*.[ChH].in", "*.cc.in", "*.[ch]pp.in", "*.[ch]xx.in", "*.hh.in",
- ]),
- ("crystal", &["Projectfile", "*.cr"]),
- ("cs", &["*.cs"]),
- ("csharp", &["*.cs"]),
- ("cshtml", &["*.cshtml"]),
- ("css", &["*.css", "*.scss"]),
- ("csv", &["*.csv"]),
- ("cython", &["*.pyx", "*.pxi", "*.pxd"]),
- ("dart", &["*.dart"]),
- ("d", &["*.d"]),
- ("dhall", &["*.dhall"]),
- ("diff", &["*.patch", "*.diff"]),
- ("docker", &["*Dockerfile*"]),
- ("edn", &["*.edn"]),
- ("elisp", &["*.el"]),
- ("elixir", &["*.ex", "*.eex", "*.exs"]),
- ("elm", &["*.elm"]),
- ("erb", &["*.erb"]),
- ("erlang", &["*.erl", "*.hrl"]),
- ("fidl", &["*.fidl"]),
- ("fish", &["*.fish"]),
- ("fortran", &[
- "*.f", "*.F", "*.f77", "*.F77", "*.pfo",
- "*.f90", "*.F90", "*.f95", "*.F95",
- ]),
- ("fsharp", &["*.fs", "*.fsx", "*.fsi"]),
- ("gap", &["*.g", "*.gap", "*.gi", "*.gd", "*.tst"]),
- ("gn", &["*.gn", "*.gni"]),
- ("go", &["*.go"]),
- ("gzip", &["*.gz", "*.tgz"]),
- ("groovy", &["*.groovy", "*.gradle"]),
- ("gradle", &["*.gradle"]),
- ("h", &["*.h", "*.hpp"]),
- ("hbs", &["*.hbs"]),
- ("haskell", &["*.hs", "*.lhs", "*.cpphs", "*.c2hs", "*.hsc"]),
- ("haml", &["*.haml"]),
- ("hs", &["*.hs", "*.lhs"]),
- ("html", &["*.htm", "*.html", "*.ejs"]),
- ("idris", &["*.idr", "*.lidr"]),
- ("java", &["*.java", "*.jsp", "*.jspx", "*.properties"]),
- ("jinja", &["*.j2", "*.jinja", "*.jinja2"]),
- ("js", &[
- "*.js", "*.jsx", "*.vue",
- ]),
- ("json", &["*.json", "composer.lock"]),
- ("jsonl", &["*.jsonl"]),
- ("julia", &["*.jl"]),