Switch from gitignore to ignore

This commit is contained in:
Eric Huss 2023-04-22 12:49:39 -07:00
parent dec0e24275
commit 35fdd00203
5 changed files with 64 additions and 37 deletions

View File

@ -32,7 +32,7 @@ jobs:
- build: msrv - build: msrv
os: ubuntu-20.04 os: ubuntu-20.04
# sync MSRV with docs: guide/src/guide/installation.md and Cargo.toml # sync MSRV with docs: guide/src/guide/installation.md and Cargo.toml
rust: 1.60.0 rust: 1.63.0
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Install Rust - name: Install Rust

57
Cargo.lock generated
View File

@ -97,9 +97,9 @@ dependencies = [
[[package]] [[package]]
name = "bstr" name = "bstr"
version = "1.0.1" version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fca0852af221f458706eb0725c03e4ed6c46af9ac98e6a689d5e634215d594dd" checksum = "c3d4260bcc2e8fc9df1eac4919a720effeb63a3f0952f5bf4944adfa18897f09"
dependencies = [ dependencies = [
"memchr", "memchr",
"once_cell", "once_cell",
@ -510,20 +510,18 @@ dependencies = [
] ]
[[package]] [[package]]
name = "gitignore" name = "globset"
version = "1.0.7" version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78aa90e4620c1498ac434c06ba6e521b525794bbdacf085d490cc794b4a2f9a4" checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc"
dependencies = [ dependencies = [
"glob", "aho-corasick",
"bstr",
"fnv",
"log",
"regex",
] ]
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.17" version = "0.3.17"
@ -718,6 +716,23 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "ignore"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492"
dependencies = [
"globset",
"lazy_static",
"log",
"memchr",
"regex",
"same-file",
"thread_local",
"walkdir",
"winapi-util",
]
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.9.2" version = "1.9.2"
@ -823,6 +838,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.138" version = "0.2.138"
@ -914,8 +935,8 @@ dependencies = [
"elasticlunr-rs", "elasticlunr-rs",
"env_logger", "env_logger",
"futures-util", "futures-util",
"gitignore",
"handlebars", "handlebars",
"ignore",
"log", "log",
"memchr", "memchr",
"notify", "notify",
@ -1658,6 +1679,16 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "thread_local"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.6.0" version = "1.6.0"

View File

@ -14,7 +14,7 @@ license = "MPL-2.0"
readme = "README.md" readme = "README.md"
repository = "https://github.com/rust-lang/mdBook" repository = "https://github.com/rust-lang/mdBook"
description = "Creates a book from markdown files" description = "Creates a book from markdown files"
rust-version = "1.60" rust-version = "1.63"
[dependencies] [dependencies]
anyhow = "1.0.28" anyhow = "1.0.28"
@ -39,7 +39,7 @@ topological-sort = "0.2.2"
# Watch feature # Watch feature
notify = { version = "5.0.0", optional = true } notify = { version = "5.0.0", optional = true }
notify-debouncer-mini = { version = "0.2.1", optional = true } notify-debouncer-mini = { version = "0.2.1", optional = true }
gitignore = { version = "1.0", optional = true } ignore = { version = "0.4.20", optional = true }
# Serve feature # Serve feature
futures-util = { version = "0.3.4", optional = true } futures-util = { version = "0.3.4", optional = true }
@ -60,9 +60,9 @@ walkdir = "2.0"
[features] [features]
default = ["watch", "serve", "search"] default = ["watch", "serve", "search"]
watch = ["notify", "notify-debouncer-mini", "gitignore"] watch = ["dep:notify", "dep:notify-debouncer-mini", "dep:ignore"]
serve = ["futures-util", "tokio", "warp"] serve = ["dep:futures-util", "dep:tokio", "dep:warp"]
search = ["elasticlunr-rs", "ammonia"] search = ["dep:elasticlunr-rs", "dep:ammonia"]
[[bin]] [[bin]]
doc = false doc = false

View File

@ -20,7 +20,7 @@ To make it easier to run, put the path to the binary into your `PATH`.
To build the `mdbook` executable from source, you will first need to install Rust and Cargo. To build the `mdbook` executable from source, you will first need to install Rust and Cargo.
Follow the instructions on the [Rust installation page]. Follow the instructions on the [Rust installation page].
mdBook currently requires at least Rust version 1.60. mdBook currently requires at least Rust version 1.63.
Once you have installed Rust, the following command can be used to build and install mdBook: Once you have installed Rust, the following command can be used to build and install mdBook:

View File

@ -1,5 +1,6 @@
use super::command_prelude::*; use super::command_prelude::*;
use crate::{get_book_dir, open}; use crate::{get_book_dir, open};
use ignore::gitignore::Gitignore;
use mdbook::errors::Result; use mdbook::errors::Result;
use mdbook::utils; use mdbook::utils;
use mdbook::MDBook; use mdbook::MDBook;
@ -62,14 +63,14 @@ fn remove_ignored_files(book_root: &Path, paths: &[PathBuf]) -> Vec<PathBuf> {
match find_gitignore(book_root) { match find_gitignore(book_root) {
Some(gitignore_path) => { Some(gitignore_path) => {
match gitignore::File::new(gitignore_path.as_path()) { let (ignore, err) = Gitignore::new(&gitignore_path);
Ok(exclusion_checker) => filter_ignored_files(exclusion_checker, paths), if let Some(err) = err {
Err(_) => { warn!(
// We're unable to read the .gitignore file, so we'll silently allow everything. "error reading gitignore `{}`: {err}",
// Please see discussion: https://github.com/rust-lang/mdBook/pull/1051 gitignore_path.display()
paths.iter().map(|path| path.to_path_buf()).collect() );
}
} }
filter_ignored_files(ignore, paths)
} }
None => { None => {
// There is no .gitignore file. // There is no .gitignore file.
@ -85,18 +86,13 @@ fn find_gitignore(book_root: &Path) -> Option<PathBuf> {
.find(|p| p.exists()) .find(|p| p.exists())
} }
fn filter_ignored_files(exclusion_checker: gitignore::File, paths: &[PathBuf]) -> Vec<PathBuf> { fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
paths paths
.iter() .iter()
.filter(|path| match exclusion_checker.is_excluded(path) { .filter(|path| {
Ok(exclude) => !exclude, !ignore
Err(error) => { .matched_path_or_any_parents(path, path.is_dir())
warn!( .is_ignore()
"Unable to determine if {:?} is excluded: {:?}. Including it.",
&path, error
);
true
}
}) })
.map(|path| path.to_path_buf()) .map(|path| path.to_path_buf())
.collect() .collect()