From 7a435be018a96e12dd290ac209136cfb22dfa166 Mon Sep 17 00:00:00 2001 From: expikr <77922942+expikr@users.noreply.github.com> Date: Tue, 18 Apr 2023 01:53:38 +0800 Subject: [PATCH 1/2] Update init.md --- guide/src/cli/init.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/guide/src/cli/init.md b/guide/src/cli/init.md index 99c0be09..9256d860 100644 --- a/guide/src/cli/init.md +++ b/guide/src/cli/init.md @@ -67,4 +67,12 @@ mdbook init --title="my amazing book" Create a `.gitignore` file configured to ignore the `book` directory created when [building] a book. If not supplied, an interactive prompt will ask whether it should be created. +```bash +mdbook init --ignore=none +``` + +```bash +mdbook init --ignore=git +``` + [building]: build.md From 35fdd0020318048c3f6040ded9862da5bc783acc Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 22 Apr 2023 12:49:39 -0700 Subject: [PATCH 2/2] Switch from gitignore to ignore --- .github/workflows/main.yml | 2 +- Cargo.lock | 57 +++++++++++++++++++++++++-------- Cargo.toml | 10 +++--- guide/src/guide/installation.md | 2 +- src/cmd/watch.rs | 30 ++++++++--------- 5 files changed, 64 insertions(+), 37 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 51254983..fd6841d4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,7 +32,7 @@ jobs: - build: msrv os: ubuntu-20.04 # sync MSRV with docs: guide/src/guide/installation.md and Cargo.toml - rust: 1.60.0 + rust: 1.63.0 steps: - uses: actions/checkout@v3 - name: Install Rust diff --git a/Cargo.lock b/Cargo.lock index d3ac85e2..f9dfe4ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,9 +97,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.0.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca0852af221f458706eb0725c03e4ed6c46af9ac98e6a689d5e634215d594dd" +checksum = "c3d4260bcc2e8fc9df1eac4919a720effeb63a3f0952f5bf4944adfa18897f09" dependencies = [ "memchr", "once_cell", @@ -510,20 +510,18 @@ dependencies = [ ] [[package]] -name = "gitignore" -version = "1.0.7" +name = "globset" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78aa90e4620c1498ac434c06ba6e521b525794bbdacf085d490cc794b4a2f9a4" +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" 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]] name = "h2" version = "0.3.17" @@ -718,6 +716,23 @@ dependencies = [ "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]] name = "indexmap" version = "1.9.2" @@ -823,6 +838,12 @@ dependencies = [ "libc", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.138" @@ -914,8 +935,8 @@ dependencies = [ "elasticlunr-rs", "env_logger", "futures-util", - "gitignore", "handlebars", + "ignore", "log", "memchr", "notify", @@ -1658,6 +1679,16 @@ dependencies = [ "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]] name = "tinyvec" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index ab3eae1f..f12e22ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ license = "MPL-2.0" readme = "README.md" repository = "https://github.com/rust-lang/mdBook" description = "Creates a book from markdown files" -rust-version = "1.60" +rust-version = "1.63" [dependencies] anyhow = "1.0.28" @@ -39,7 +39,7 @@ topological-sort = "0.2.2" # Watch feature notify = { version = "5.0.0", 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 futures-util = { version = "0.3.4", optional = true } @@ -60,9 +60,9 @@ walkdir = "2.0" [features] default = ["watch", "serve", "search"] -watch = ["notify", "notify-debouncer-mini", "gitignore"] -serve = ["futures-util", "tokio", "warp"] -search = ["elasticlunr-rs", "ammonia"] +watch = ["dep:notify", "dep:notify-debouncer-mini", "dep:ignore"] +serve = ["dep:futures-util", "dep:tokio", "dep:warp"] +search = ["dep:elasticlunr-rs", "dep:ammonia"] [[bin]] doc = false diff --git a/guide/src/guide/installation.md b/guide/src/guide/installation.md index e6ddc1ac..34b9c9e4 100644 --- a/guide/src/guide/installation.md +++ b/guide/src/guide/installation.md @@ -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. 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: diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs index bbc6bde7..4cc1b131 100644 --- a/src/cmd/watch.rs +++ b/src/cmd/watch.rs @@ -1,5 +1,6 @@ use super::command_prelude::*; use crate::{get_book_dir, open}; +use ignore::gitignore::Gitignore; use mdbook::errors::Result; use mdbook::utils; use mdbook::MDBook; @@ -62,14 +63,14 @@ fn remove_ignored_files(book_root: &Path, paths: &[PathBuf]) -> Vec { match find_gitignore(book_root) { Some(gitignore_path) => { - match gitignore::File::new(gitignore_path.as_path()) { - Ok(exclusion_checker) => filter_ignored_files(exclusion_checker, paths), - Err(_) => { - // We're unable to read the .gitignore file, so we'll silently allow everything. - // Please see discussion: https://github.com/rust-lang/mdBook/pull/1051 - paths.iter().map(|path| path.to_path_buf()).collect() - } + let (ignore, err) = Gitignore::new(&gitignore_path); + if let Some(err) = err { + warn!( + "error reading gitignore `{}`: {err}", + gitignore_path.display() + ); } + filter_ignored_files(ignore, paths) } None => { // There is no .gitignore file. @@ -85,18 +86,13 @@ fn find_gitignore(book_root: &Path) -> Option { .find(|p| p.exists()) } -fn filter_ignored_files(exclusion_checker: gitignore::File, paths: &[PathBuf]) -> Vec { +fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec { paths .iter() - .filter(|path| match exclusion_checker.is_excluded(path) { - Ok(exclude) => !exclude, - Err(error) => { - warn!( - "Unable to determine if {:?} is excluded: {:?}. Including it.", - &path, error - ); - true - } + .filter(|path| { + !ignore + .matched_path_or_any_parents(path, path.is_dir()) + .is_ignore() }) .map(|path| path.to_path_buf()) .collect()