mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-29 19:21:57 -07:00
Compare commits
98 Commits
ag/moarci
...
grep-regex
Author | SHA1 | Date | |
---|---|---|---|
|
92daa34eb3 | ||
|
a8c1fb7c88 | ||
|
52ec68799c | ||
|
c0d78240df | ||
|
cda9acb876 | ||
|
1ece50694e | ||
|
f3a966bcbc | ||
|
a38913b63a | ||
|
e772a95b58 | ||
|
9dd4bf8d7f | ||
|
c4c43c733e | ||
|
447506ebe0 | ||
|
12e4180985 | ||
|
daa8319398 | ||
|
3a6a24a52a | ||
|
aab3d80374 | ||
|
1856cda77b | ||
|
7340d8dbbe | ||
|
50d2047ae2 | ||
|
227436624f | ||
|
5bfdd3a652 | ||
|
ecec6147d1 | ||
|
db7a8cdcb5 | ||
|
eef7a7e7ff | ||
|
4176050cdd | ||
|
109460fce2 | ||
|
da3431b478 | ||
|
f314b0d55f | ||
|
fab5c812f3 | ||
|
c824d095a7 | ||
|
ee21897ebd | ||
|
0373f6ddb0 | ||
|
b44554c803 | ||
|
0874aa115c | ||
|
fdd8510fdd | ||
|
0bc4f0447b | ||
|
c95f29e3ba | ||
|
3644208b03 | ||
|
66f045e055 | ||
|
3d59bd98aa | ||
|
52d7f47420 | ||
|
75cbe88fa2 | ||
|
711426a632 | ||
|
01eeec56bb | ||
|
322fc75a3d | ||
|
b435eaafc8 | ||
|
f8e70294d5 | ||
|
578e2d47a8 | ||
|
9f7c2ebc09 | ||
|
5c1eac41a3 | ||
|
6f2b79f584 | ||
|
0c3b673e4c | ||
|
297b428c8c | ||
|
804b43ecd8 | ||
|
2263b8ac92 | ||
|
cd8ec38a68 | ||
|
6a0e0147e0 | ||
|
ad97e9c93f | ||
|
24f8a3e5ec | ||
|
1bdb767851 | ||
|
a4897eca23 | ||
|
a070722ff2 | ||
|
4628d77808 | ||
|
f8418c6a52 | ||
|
040ca45ba0 | ||
|
91470572cd | ||
|
027adbf485 | ||
|
e71eedf0eb | ||
|
88f46d12f1 | ||
|
a18cf6ec39 | ||
|
c78c3236a8 | ||
|
7cf21600cd | ||
|
647b0d3977 | ||
|
e572fc1683 | ||
|
9cb93abd11 | ||
|
41695c66fa | ||
|
cb0dfda936 | ||
|
74d1fe59e9 | ||
|
9fd1e202e0 | ||
|
e76807b1b5 | ||
|
f8fb65f7e3 | ||
|
98de8d248a | ||
|
c358700dfb | ||
|
8670a4a969 | ||
|
e3b1f86908 | ||
|
46b07bb2ee | ||
|
8bdf84e3a8 | ||
|
5a6e17fcc1 | ||
|
00bfcd14a6 | ||
|
bf0ddc4675 | ||
|
0fb3f6a159 | ||
|
837fb5e21f | ||
|
2e1815606e | ||
|
cb2f6ddc61 | ||
|
bd7a42602f | ||
|
528ce56e1b | ||
|
8892bf648c | ||
|
8cb7271b64 |
238
.github/workflows/ci.yml
vendored
238
.github/workflows/ci.yml
vendored
@@ -1,4 +1,3 @@
|
|||||||
# test
|
|
||||||
name: ci
|
name: ci
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -6,94 +5,191 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '00 01 * * *'
|
- cron: '00 01 * * *'
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: test
|
name: test
|
||||||
|
env:
|
||||||
|
# For some builds, we use cross to test on 32-bit and big-endian
|
||||||
|
# systems.
|
||||||
|
CARGO: cargo
|
||||||
|
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
|
||||||
|
TARGET_FLAGS:
|
||||||
|
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
|
||||||
|
TARGET_DIR: ./target
|
||||||
|
# Emit backtraces on panics.
|
||||||
|
RUST_BACKTRACE: 1
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
# The docs seem to suggest that we can have a matrix with just an
|
|
||||||
# include directive, but it result in a "matrix must define at least
|
|
||||||
# one vector" error in the CI system.
|
|
||||||
build:
|
build:
|
||||||
- pinned-glibc
|
# We test ripgrep on a pinned version of Rust, along with the moving
|
||||||
- pinned-musl
|
# targets of 'stable' and 'beta' for good measure.
|
||||||
|
- pinned
|
||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
# We test musl with nightly because every once in a while, this will
|
# Our release builds are generated by a nightly compiler to take
|
||||||
# catch an upstream regression.
|
# advantage of the latest optimizations/compile time improvements. So
|
||||||
- nightly-glibc
|
# we test all of them here. (We don't do mips releases, but test on
|
||||||
|
# mips for big-endian coverage.)
|
||||||
|
- nightly
|
||||||
- nightly-musl
|
- nightly-musl
|
||||||
|
- nightly-32
|
||||||
|
- nightly-mips
|
||||||
|
- nightly-arm
|
||||||
- macos
|
- macos
|
||||||
- win-msvc-32
|
- win-msvc
|
||||||
- win-msvc-64
|
- win-gnu
|
||||||
- win-gnu-32
|
|
||||||
- win-gnu-64
|
|
||||||
include:
|
include:
|
||||||
# - build: pinned-glibc
|
- build: pinned
|
||||||
# os: ubuntu-18.04
|
|
||||||
# rust: 1.34.0
|
|
||||||
# target: x86_64-unknown-linux-gnu
|
|
||||||
- build: pinned-musl
|
|
||||||
os: ubuntu-18.04
|
os: ubuntu-18.04
|
||||||
rust: 1.34.0
|
rust: 1.41.0
|
||||||
target: x86_64-unknown-linux-musl
|
|
||||||
- build: stable
|
- build: stable
|
||||||
os: ubuntu-18.04
|
os: ubuntu-18.04
|
||||||
rust: stable
|
rust: stable
|
||||||
target: x86_64-unknown-linux-gnu
|
- build: beta
|
||||||
# - build: beta
|
os: ubuntu-18.04
|
||||||
# os: ubuntu-18.04
|
rust: beta
|
||||||
# rust: beta
|
- build: nightly
|
||||||
# target: x86_64-unknown-linux-gnu
|
os: ubuntu-18.04
|
||||||
# - build: nightly-glibc
|
rust: nightly
|
||||||
# os: ubuntu-18.04
|
- build: nightly-musl
|
||||||
# rust: nightly
|
os: ubuntu-18.04
|
||||||
# target: x86_64-unknown-linux-gnu
|
rust: nightly
|
||||||
# - build: nightly-musl
|
target: x86_64-unknown-linux-musl
|
||||||
# os: ubuntu-18.04
|
- build: nightly-32
|
||||||
# rust: nightly
|
os: ubuntu-18.04
|
||||||
# target: x86_64-unknown-linux-musl
|
rust: nightly
|
||||||
# - build: macos
|
target: i686-unknown-linux-gnu
|
||||||
# os: macOS-10.14
|
- build: nightly-mips
|
||||||
# rust: stable
|
os: ubuntu-18.04
|
||||||
# target: x86_64-apple-darwin
|
rust: nightly
|
||||||
# - build: win-msvc-32
|
target: mips64-unknown-linux-gnuabi64
|
||||||
# os: windows-2019
|
- build: nightly-arm
|
||||||
# rust: stable
|
os: ubuntu-18.04
|
||||||
# target: i686-pc-windows-msvc
|
rust: nightly
|
||||||
# - build: win-msvc-64
|
# For stripping release binaries:
|
||||||
# os: windows-2019
|
# docker run --rm -v $PWD/target:/target:Z \
|
||||||
# rust: stable
|
# rustembedded/cross:arm-unknown-linux-gnueabihf \
|
||||||
# target: x86_64-pc-windows-msvc
|
# arm-linux-gnueabihf-strip \
|
||||||
# - build: win-gnu-32
|
# /target/arm-unknown-linux-gnueabihf/debug/rg
|
||||||
# os: windows-2019
|
target: arm-unknown-linux-gnueabihf
|
||||||
# rust: stable-i686-gnu
|
- build: macos
|
||||||
# target: i686-pc-windows-gnu
|
os: macos-latest
|
||||||
# - build: win-gnu-64
|
rust: nightly
|
||||||
# os: windows-2019
|
- build: win-msvc
|
||||||
# rust: stable-x86_64-gnu
|
os: windows-2019
|
||||||
# target: x86_64-pc-windows-gnu
|
rust: nightly
|
||||||
|
- build: win-gnu
|
||||||
|
os: windows-2019
|
||||||
|
rust: nightly-x86_64-gnu
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v1
|
||||||
with:
|
|
||||||
fetch-depth: 1
|
- name: Install packages (Ubuntu)
|
||||||
|
if: matrix.os == 'ubuntu-18.04'
|
||||||
|
run: |
|
||||||
|
ci/ubuntu-install-packages
|
||||||
|
|
||||||
|
- name: Install packages (macOS)
|
||||||
|
if: matrix.os == 'macos-latest'
|
||||||
|
run: |
|
||||||
|
ci/macos-install-packages
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: hecrj/setup-rust-action@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
rust-version: ${{ matrix.rust }}
|
toolchain: ${{ matrix.rust }}
|
||||||
- name: Install Rust Target
|
profile: minimal
|
||||||
run: rustup target add ${{ matrix.target }}
|
override: true
|
||||||
# - name: Install musl-gcc
|
|
||||||
# if: contains(matrix.target, 'musl')
|
- name: Use Cross
|
||||||
# run: |
|
if: matrix.target != ''
|
||||||
# apt-get install musl-tools
|
run: |
|
||||||
- name: Build everything
|
# FIXME: to work around bugs in latest cross release, install master.
|
||||||
run: cargo build --verbose --target ${{ matrix.target }} --all --features pcre2
|
# See: https://github.com/rust-embedded/cross/issues/357
|
||||||
- name: Test zsh auto-completions
|
cargo install --git https://github.com/rust-embedded/cross
|
||||||
if: matrix.build == 'stable'
|
echo "::set-env name=CARGO::cross"
|
||||||
run: ./ci/test_complete.sh
|
echo "::set-env name=TARGET_FLAGS::--target ${{ matrix.target }}"
|
||||||
- name: Run tests
|
echo "::set-env name=TARGET_DIR::./target/${{ matrix.target }}"
|
||||||
run: cargo test --verbose --target ${{ matrix.target }} --all --features pcre2
|
|
||||||
|
- name: Show command used for Cargo
|
||||||
|
run: |
|
||||||
|
echo "cargo command is: ${{ env.CARGO }}"
|
||||||
|
echo "target flag is: ${{ env.TARGET_FLAGS }}"
|
||||||
|
|
||||||
|
- name: Build ripgrep and all crates
|
||||||
|
run: ${{ env.CARGO }} build --verbose --all ${{ env.TARGET_FLAGS }}
|
||||||
|
|
||||||
|
- name: Build ripgrep with PCRE2
|
||||||
|
run: ${{ env.CARGO }} build --verbose --all --features pcre2 ${{ env.TARGET_FLAGS }}
|
||||||
|
|
||||||
|
# This is useful for debugging problems when the expected build artifacts
|
||||||
|
# (like shell completions and man pages) aren't generated.
|
||||||
|
- name: Show build.rs stderr
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set +x
|
||||||
|
stderr="$(find "${{ env.TARGET_DIR }}/debug" -name stderr -print0 | xargs -0 ls -t | head -n1)"
|
||||||
|
if [ -s "$stderr" ]; then
|
||||||
|
echo "===== $stderr ===== "
|
||||||
|
cat "$stderr"
|
||||||
|
echo "====="
|
||||||
|
fi
|
||||||
|
set -x
|
||||||
|
|
||||||
|
- name: Run tests with PCRE2 (sans cross)
|
||||||
|
if: matrix.target == ''
|
||||||
|
run: ${{ env.CARGO }} test --verbose --all --features pcre2 ${{ env.TARGET_FLAGS }}
|
||||||
|
|
||||||
|
- name: Run tests without PCRE2 (with cross)
|
||||||
|
# These tests should actually work, but they almost double the runtime.
|
||||||
|
# Every integration test spins up qemu to run 'rg', and when PCRE2 is
|
||||||
|
# enabled, every integration test is run twice: one with the default
|
||||||
|
# regex engine and once with PCRE2.
|
||||||
|
if: matrix.target != ''
|
||||||
|
run: ${{ env.CARGO }} test --verbose --all ${{ env.TARGET_FLAGS }}
|
||||||
|
|
||||||
|
- name: Test for existence of build artifacts (Windows)
|
||||||
|
if: matrix.os == 'windows-2019'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")"
|
||||||
|
ls "$outdir/_rg.ps1" && file "$outdir/_rg.ps1"
|
||||||
|
|
||||||
|
- name: Test for existence of build artifacts (Unix)
|
||||||
|
if: matrix.os != 'windows-2019'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")"
|
||||||
|
for f in rg.bash rg.fish rg.1; do
|
||||||
|
# We could use file -E here, but it isn't supported on macOS.
|
||||||
|
ls "$outdir/$f" && file "$outdir/$f"
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Test zsh shell completions (Unix, sans cross)
|
||||||
|
# We could test this when using Cross, but we'd have to execute the
|
||||||
|
# 'rg' binary (done in test-complete) with qemu, which is a pain and
|
||||||
|
# doesn't really gain us much. If shell completion works in one place,
|
||||||
|
# it probably works everywhere.
|
||||||
|
if: matrix.target == '' && matrix.os != 'windows-2019'
|
||||||
|
shell: bash
|
||||||
|
run: ci/test-complete
|
||||||
|
|
||||||
|
rustfmt:
|
||||||
|
name: rustfmt
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- name: Install Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
profile: minimal
|
||||||
|
components: rustfmt
|
||||||
|
- name: Check formatting
|
||||||
|
run: |
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
211
.github/workflows/release.yml
vendored
Normal file
211
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
# The way this works is a little weird. But basically, the create-release job
|
||||||
|
# runs purely to initialize the GitHub release itself. Once done, the upload
|
||||||
|
# URL of the release is saved as an artifact.
|
||||||
|
#
|
||||||
|
# The build-release job runs only once create-release is finished. It gets
|
||||||
|
# the release upload URL by downloading the corresponding artifact (which was
|
||||||
|
# uploaded by create-release). It then builds the release executables for each
|
||||||
|
# supported platform and attaches them as release assets to the previously
|
||||||
|
# created release.
|
||||||
|
#
|
||||||
|
# The key here is that we create the release only once.
|
||||||
|
|
||||||
|
name: release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
# Enable when testing release infrastructure on a branch.
|
||||||
|
# branches:
|
||||||
|
# - ag/release
|
||||||
|
tags:
|
||||||
|
- '[0-9]+.[0-9]+.[0-9]+'
|
||||||
|
jobs:
|
||||||
|
create-release:
|
||||||
|
name: create-release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
# Set to force version number, e.g., when no tag exists.
|
||||||
|
# RG_VERSION: TEST-0.0.0
|
||||||
|
steps:
|
||||||
|
- name: Create artifacts directory
|
||||||
|
run: mkdir artifacts
|
||||||
|
|
||||||
|
- name: Get the release version from the tag
|
||||||
|
if: env.RG_VERSION == ''
|
||||||
|
run: |
|
||||||
|
# Apparently, this is the right way to get a tag name. Really?
|
||||||
|
#
|
||||||
|
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
|
||||||
|
echo "::set-env name=RG_VERSION::${GITHUB_REF#refs/tags/}"
|
||||||
|
echo "version is: ${{ env.RG_VERSION }}"
|
||||||
|
|
||||||
|
- name: Create GitHub release
|
||||||
|
id: release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag_name: ${{ env.RG_VERSION }}
|
||||||
|
release_name: ripgrep ${{ env.RG_VERSION }}
|
||||||
|
|
||||||
|
- name: Save release upload URL to artifact
|
||||||
|
run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url
|
||||||
|
|
||||||
|
- name: Save version number to artifact
|
||||||
|
run: echo "${{ env.RG_VERSION }}" > artifacts/release-version
|
||||||
|
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: artifacts
|
||||||
|
path: artifacts
|
||||||
|
|
||||||
|
build-release:
|
||||||
|
name: build-release
|
||||||
|
needs: ['create-release']
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
# For some builds, we use cross to test on 32-bit and big-endian
|
||||||
|
# systems.
|
||||||
|
CARGO: cargo
|
||||||
|
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
|
||||||
|
TARGET_FLAGS:
|
||||||
|
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
|
||||||
|
TARGET_DIR: ./target
|
||||||
|
# Emit backtraces on panics.
|
||||||
|
RUST_BACKTRACE: 1
|
||||||
|
# Build static releases with PCRE2.
|
||||||
|
PCRE2_SYS_STATIC: 1
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
build: [linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc]
|
||||||
|
include:
|
||||||
|
- build: linux
|
||||||
|
os: ubuntu-18.04
|
||||||
|
rust: nightly
|
||||||
|
target: x86_64-unknown-linux-musl
|
||||||
|
- build: linux-arm
|
||||||
|
os: ubuntu-18.04
|
||||||
|
rust: nightly
|
||||||
|
target: arm-unknown-linux-gnueabihf
|
||||||
|
- build: macos
|
||||||
|
os: macos-latest
|
||||||
|
rust: nightly
|
||||||
|
target: x86_64-apple-darwin
|
||||||
|
- build: win-msvc
|
||||||
|
os: windows-2019
|
||||||
|
rust: nightly
|
||||||
|
target: x86_64-pc-windows-msvc
|
||||||
|
- build: win-gnu
|
||||||
|
os: windows-2019
|
||||||
|
rust: nightly-x86_64-gnu
|
||||||
|
target: x86_64-pc-windows-gnu
|
||||||
|
- build: win32-msvc
|
||||||
|
os: windows-2019
|
||||||
|
rust: nightly
|
||||||
|
target: i686-pc-windows-msvc
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
|
- name: Install packages (Ubuntu)
|
||||||
|
if: matrix.os == 'ubuntu-18.04'
|
||||||
|
run: |
|
||||||
|
ci/ubuntu-install-packages
|
||||||
|
|
||||||
|
- name: Install packages (macOS)
|
||||||
|
if: matrix.os == 'macos-latest'
|
||||||
|
run: |
|
||||||
|
ci/macos-install-packages
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: ${{ matrix.rust }}
|
||||||
|
profile: minimal
|
||||||
|
override: true
|
||||||
|
target: ${{ matrix.target }}
|
||||||
|
|
||||||
|
- name: Use Cross
|
||||||
|
# if: matrix.os != 'windows-2019'
|
||||||
|
run: |
|
||||||
|
# FIXME: to work around bugs in latest cross release, install master.
|
||||||
|
# See: https://github.com/rust-embedded/cross/issues/357
|
||||||
|
cargo install --git https://github.com/rust-embedded/cross
|
||||||
|
echo "::set-env name=CARGO::cross"
|
||||||
|
echo "::set-env name=TARGET_FLAGS::--target ${{ matrix.target }}"
|
||||||
|
echo "::set-env name=TARGET_DIR::./target/${{ matrix.target }}"
|
||||||
|
|
||||||
|
- name: Show command used for Cargo
|
||||||
|
run: |
|
||||||
|
echo "cargo command is: ${{ env.CARGO }}"
|
||||||
|
echo "target flag is: ${{ env.TARGET_FLAGS }}"
|
||||||
|
echo "target dir is: ${{ env.TARGET_DIR }}"
|
||||||
|
|
||||||
|
- name: Get release download URL
|
||||||
|
uses: actions/download-artifact@v1
|
||||||
|
with:
|
||||||
|
name: artifacts
|
||||||
|
path: artifacts
|
||||||
|
|
||||||
|
- name: Set release upload URL and release version
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
release_upload_url="$(cat artifacts/release-upload-url)"
|
||||||
|
echo "::set-env name=RELEASE_UPLOAD_URL::$release_upload_url"
|
||||||
|
echo "release upload url: $RELEASE_UPLOAD_URL"
|
||||||
|
release_version="$(cat artifacts/release-version)"
|
||||||
|
echo "::set-env name=RELEASE_VERSION::$release_version"
|
||||||
|
echo "release version: $RELEASE_VERSION"
|
||||||
|
|
||||||
|
- name: Build release binary
|
||||||
|
run: ${{ env.CARGO }} build --verbose --release --features pcre2 ${{ env.TARGET_FLAGS }}
|
||||||
|
|
||||||
|
- name: Strip release binary (linux and macos)
|
||||||
|
if: matrix.build == 'linux' || matrix.build == 'macos'
|
||||||
|
run: strip "target/${{ matrix.target }}/release/rg"
|
||||||
|
|
||||||
|
- name: Strip release binary (arm)
|
||||||
|
if: matrix.build == 'linux-arm'
|
||||||
|
run: |
|
||||||
|
docker run --rm -v \
|
||||||
|
"$PWD/target:/target:Z" \
|
||||||
|
rustembedded/cross:arm-unknown-linux-gnueabihf \
|
||||||
|
arm-linux-gnueabihf-strip \
|
||||||
|
/target/arm-unknown-linux-gnueabihf/release/rg
|
||||||
|
|
||||||
|
- name: Build archive
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")"
|
||||||
|
staging="ripgrep-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
|
||||||
|
mkdir -p "$staging"/{complete,doc}
|
||||||
|
|
||||||
|
cp {README.md,COPYING,UNLICENSE,LICENSE-MIT} "$staging/"
|
||||||
|
cp {CHANGELOG.md,FAQ.md,GUIDE.md} "$staging/doc/"
|
||||||
|
cp "$outdir"/{rg.bash,rg.fish,_rg.ps1} "$staging/complete/"
|
||||||
|
cp complete/_rg "$staging/complete/"
|
||||||
|
|
||||||
|
if [ "${{ matrix.os }}" = "windows-2019" ]; then
|
||||||
|
cp "target/${{ matrix.target }}/release/rg.exe" "$staging/"
|
||||||
|
7z a "$staging.zip" "$staging"
|
||||||
|
echo "::set-env name=ASSET::$staging.zip"
|
||||||
|
else
|
||||||
|
# The man page is only generated on Unix systems. ¯\_(ツ)_/¯
|
||||||
|
cp "$outdir"/rg.1 "$staging/doc/"
|
||||||
|
cp "target/${{ matrix.target }}/release/rg" "$staging/"
|
||||||
|
tar czf "$staging.tar.gz" "$staging"
|
||||||
|
echo "::set-env name=ASSET::$staging.tar.gz"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Upload release archive
|
||||||
|
uses: actions/upload-release-asset@v1.0.1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
|
||||||
|
asset_path: ${{ env.ASSET }}
|
||||||
|
asset_name: ${{ env.ASSET }}
|
||||||
|
asset_content_type: application/octet-stream
|
110
.travis.yml
110
.travis.yml
@@ -1,110 +0,0 @@
|
|||||||
language: rust
|
|
||||||
dist: xenial
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- PROJECT_NAME: ripgrep
|
|
||||||
- RUST_BACKTRACE: full
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
# For generating man page.
|
|
||||||
- libxslt1-dev
|
|
||||||
- asciidoc
|
|
||||||
- docbook-xsl
|
|
||||||
- xsltproc
|
|
||||||
- libxml2-utils
|
|
||||||
# Needed for completion-function test.
|
|
||||||
- zsh
|
|
||||||
# Needed for testing decompression search.
|
|
||||||
- xz-utils
|
|
||||||
- liblz4-tool
|
|
||||||
# For building MUSL static builds on Linux.
|
|
||||||
- musl-tools
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
include:
|
|
||||||
# Nightly channel.
|
|
||||||
# All *nix releases are done on the nightly channel to take advantage
|
|
||||||
# of the regex library's multiple pattern SIMD search.
|
|
||||||
- os: linux
|
|
||||||
rust: nightly
|
|
||||||
env: TARGET=i686-unknown-linux-musl
|
|
||||||
- os: linux
|
|
||||||
rust: nightly
|
|
||||||
env: TARGET=x86_64-unknown-linux-musl
|
|
||||||
- os: osx
|
|
||||||
rust: nightly
|
|
||||||
# XML_CATALOG_FILES is apparently necessary for asciidoc on macOS.
|
|
||||||
env: TARGET=x86_64-apple-darwin XML_CATALOG_FILES=/usr/local/etc/xml/catalog
|
|
||||||
- os: linux
|
|
||||||
rust: nightly
|
|
||||||
env: TARGET=arm-unknown-linux-gnueabihf GCC_VERSION=4.8
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- gcc-4.8-arm-linux-gnueabihf
|
|
||||||
- binutils-arm-linux-gnueabihf
|
|
||||||
- libc6-armhf-cross
|
|
||||||
- libc6-dev-armhf-cross
|
|
||||||
# For generating man page.
|
|
||||||
- libxslt1-dev
|
|
||||||
- asciidoc
|
|
||||||
- docbook-xsl
|
|
||||||
- xsltproc
|
|
||||||
- libxml2-utils
|
|
||||||
# Beta channel. We enable these to make sure there are no regressions in
|
|
||||||
# Rust beta releases.
|
|
||||||
- os: linux
|
|
||||||
rust: beta
|
|
||||||
env: TARGET=x86_64-unknown-linux-musl
|
|
||||||
- os: linux
|
|
||||||
rust: beta
|
|
||||||
env: TARGET=x86_64-unknown-linux-gnu
|
|
||||||
# Minimum Rust supported channel. We enable these to make sure ripgrep
|
|
||||||
# continues to work on the advertised minimum Rust version.
|
|
||||||
- os: linux
|
|
||||||
rust: 1.34.0
|
|
||||||
env: TARGET=x86_64-unknown-linux-gnu
|
|
||||||
- os: linux
|
|
||||||
rust: 1.34.0
|
|
||||||
env: TARGET=x86_64-unknown-linux-musl
|
|
||||||
- os: linux
|
|
||||||
rust: 1.34.0
|
|
||||||
env: TARGET=arm-unknown-linux-gnueabihf GCC_VERSION=4.8
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- gcc-4.8-arm-linux-gnueabihf
|
|
||||||
- binutils-arm-linux-gnueabihf
|
|
||||||
- libc6-armhf-cross
|
|
||||||
- libc6-dev-armhf-cross
|
|
||||||
# For generating man page.
|
|
||||||
- libxslt1-dev
|
|
||||||
- asciidoc
|
|
||||||
- docbook-xsl
|
|
||||||
- xsltproc
|
|
||||||
- libxml2-utils
|
|
||||||
install: ci/install.sh
|
|
||||||
script: ci/script.sh
|
|
||||||
before_deploy: ci/before_deploy.sh
|
|
||||||
deploy:
|
|
||||||
provider: releases
|
|
||||||
file_glob: true
|
|
||||||
file: deployment/${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.tar.gz
|
|
||||||
skip_cleanup: true
|
|
||||||
on:
|
|
||||||
condition: $TRAVIS_RUST_VERSION = nightly
|
|
||||||
branch: master # i guess we do need this after all?
|
|
||||||
tags: true
|
|
||||||
api_key:
|
|
||||||
secure: "IbSnsbGkxSydR/sozOf1/SRvHplzwRUHzcTjM7BKnr7GccL86gRPUrsrvD103KjQUGWIc1TnK1YTq5M0Onswg/ORDjqa1JEJPkPdPnVh9ipbF7M2De/7IlB4X4qXLKoApn8+bx2x/mfYXu4G+G1/2QdbaKK2yfXZKyjz0YFx+6CNrVCT2Nk8q7aHvOOzAL58vsG8iPDpupuhxlMDDn/UhyOWVInmPPQ0iJR1ZUJN8xJwXvKvBbfp3AhaBiAzkhXHNLgBR8QC5noWWMXnuVDMY3k4f3ic0V+p/qGUCN/nhptuceLxKFicMCYObSZeUzE5RAI0/OBW7l3z2iCoc+TbAnn+JrX/ObJCfzgAOXAU3tLaBFMiqQPGFKjKg1ltSYXomOFP/F7zALjpvFp4lYTBajRR+O3dqaxA9UQuRjw27vOeUpMcga4ZzL4VXFHzrxZKBHN//XIGjYAVhJ1NSSeGpeJV5/+jYzzWKfwSagRxQyVCzMooYFFXzn8Yxdm3PJlmp3GaAogNkdB9qKcrEvRINCelalzALPi0hD/HUDi8DD2PNTCLLMo6VSYtvc685Zbe+KgNzDV1YyTrRCUW6JotrS0r2ULLwnsh40hSB//nNv3XmwNmC/CmW5QAnIGj8cBMF4S2t6ohADIndojdAfNiptmaZOIT6owK7bWMgPMyopo="
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
# Pushes and PR to the master branch
|
|
||||||
- master
|
|
||||||
# Ruby regex to match tags. Required, or travis won't trigger deploys when
|
|
||||||
# a new tag is pushed.
|
|
||||||
- /^\d+\.\d+\.\d+.*$/
|
|
||||||
notifications:
|
|
||||||
email:
|
|
||||||
on_success: never
|
|
82
CHANGELOG.md
82
CHANGELOG.md
@@ -1,11 +1,85 @@
|
|||||||
TBD
|
12.0.0 (2020-03-15)
|
||||||
===
|
===================
|
||||||
TODO
|
ripgrep 12 is a new major version release of ripgrep that contains many bug
|
||||||
|
fixes, several important performance improvements and a few minor new features.
|
||||||
|
|
||||||
|
In a near future release, I am hoping to add an
|
||||||
|
[indexing feature](https://github.com/BurntSushi/ripgrep/issues/1497)
|
||||||
|
to ripgrep, which will dramatically speed up searching by building an index.
|
||||||
|
Feedback would very much be appreciated, especially on the user experience
|
||||||
|
which will be difficult to get right.
|
||||||
|
|
||||||
|
This release has no known breaking changes.
|
||||||
|
|
||||||
|
Deprecations:
|
||||||
|
|
||||||
|
* The `--no-pcre2-unicode` flag is deprecated. Instead, use the `--no-unicode`
|
||||||
|
flag, which applies to both the default regex engine and PCRE2. For now,
|
||||||
|
`--no-pcre2-unicode` and `--pcre2-unicode` are aliases to `--no-unicode`
|
||||||
|
and `--unicode`, respectively. The `--[no-]pcre2-unicode` flags may be
|
||||||
|
removed in a future release.
|
||||||
|
* The `--auto-hybrid-regex` flag is deprecated. Instead, use the new `--engine`
|
||||||
|
flag with the `auto` value.
|
||||||
|
|
||||||
|
Performance improvements:
|
||||||
|
|
||||||
|
* [PERF #1087](https://github.com/BurntSushi/ripgrep/pull/1087):
|
||||||
|
ripgrep is smarter when detected literals are whitespace.
|
||||||
|
* [PERF #1381](https://github.com/BurntSushi/ripgrep/pull/1381):
|
||||||
|
Directory traversal is sped up with speculative ignore-file existence checks.
|
||||||
|
* [PERF cd8ec38a](https://github.com/BurntSushi/ripgrep/commit/cd8ec38a):
|
||||||
|
Improve inner literal detection to cover more cases more effectively.
|
||||||
|
e.g., ` +Sherlock Holmes +` now has ` Sherlock Holmes ` extracted instead
|
||||||
|
of ` `.
|
||||||
|
* [PERF 6a0e0147](https://github.com/BurntSushi/ripgrep/commit/6a0e0147):
|
||||||
|
Improve literal detection when the `-w/--word-regexp` flag is used.
|
||||||
|
* [PERF ad97e9c9](https://github.com/BurntSushi/ripgrep/commit/ad97e9c9):
|
||||||
|
Improve overall performance of the `-w/--word-regexp` flag.
|
||||||
|
|
||||||
|
Feature enhancements:
|
||||||
|
|
||||||
|
* Added or improved file type filtering for erb, diff, Gradle, HAML, Org,
|
||||||
|
Postscript, Skim, Slim, Slime, RPM Spec files, Typoscript, xml.
|
||||||
|
* [FEATURE #1370](https://github.com/BurntSushi/ripgrep/pull/1370):
|
||||||
|
Add `--include-zero` flag that shows files searched without matches.
|
||||||
|
* [FEATURE #1390](https://github.com/BurntSushi/ripgrep/pull/1390):
|
||||||
|
Add `--no-context-separator` flag that always hides context separators.
|
||||||
|
* [FEATURE #1414](https://github.com/BurntSushi/ripgrep/pull/1414):
|
||||||
|
Add `--no-require-git` flag to allow ripgrep to respect gitignores anywhere.
|
||||||
|
* [FEATURE #1420](https://github.com/BurntSushi/ripgrep/pull/1420):
|
||||||
|
Add `--no-ignore-exclude` to disregard rules in `.git/info/exclude` files.
|
||||||
|
* [FEATURE #1466](https://github.com/BurntSushi/ripgrep/pull/1466):
|
||||||
|
Add `--no-ignore-files` flag to disable all `--ignore-file` flags.
|
||||||
|
* [FEATURE #1488](https://github.com/BurntSushi/ripgrep/pull/1488):
|
||||||
|
Add '--engine' flag for easier switching between regex engines.
|
||||||
|
* [FEATURE 75cbe88f](https://github.com/BurntSushi/ripgrep/commit/75cbe88f):
|
||||||
|
Add `--no-unicode` flag. This works on all supported regex engines.
|
||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
|
|
||||||
* [BUG #1335](https://github.com/BurntSushi/ripgrep/issues/1335):
|
* [BUG #1291](https://github.com/BurntSushi/ripgrep/issues/1291):
|
||||||
|
ripgrep now works in non-existent directories.
|
||||||
|
* [BUG #1319](https://github.com/BurntSushi/ripgrep/issues/1319):
|
||||||
|
Fix match bug due to errant literal detection.
|
||||||
|
* [**BUG #1335**](https://github.com/BurntSushi/ripgrep/issues/1335):
|
||||||
Fixes a performance bug when searching plain text files with very long lines.
|
Fixes a performance bug when searching plain text files with very long lines.
|
||||||
|
This was a serious performance regression in some cases.
|
||||||
|
* [BUG #1344](https://github.com/BurntSushi/ripgrep/issues/1344):
|
||||||
|
Document usage of `--type all`.
|
||||||
|
* [BUG #1389](https://github.com/BurntSushi/ripgrep/issues/1389):
|
||||||
|
Fixes a bug where ripgrep would panic when searching a symlinked directory.
|
||||||
|
* [BUG #1439](https://github.com/BurntSushi/ripgrep/issues/1439):
|
||||||
|
Improve documentation for ripgrep's automatic stdin detection.
|
||||||
|
* [BUG #1441](https://github.com/BurntSushi/ripgrep/issues/1441):
|
||||||
|
Remove CPU features from man page.
|
||||||
|
* [BUG #1442](https://github.com/BurntSushi/ripgrep/issues/1442),
|
||||||
|
[BUG #1478](https://github.com/BurntSushi/ripgrep/issues/1478):
|
||||||
|
Improve documentation of the `-g/--glob` flag.
|
||||||
|
* [BUG #1445](https://github.com/BurntSushi/ripgrep/issues/1445):
|
||||||
|
ripgrep now respects ignore rules from .git/info/exclude in worktrees.
|
||||||
|
* [BUG #1485](https://github.com/BurntSushi/ripgrep/issues/1485):
|
||||||
|
Fish shell completions from the release Debian package are now installed to
|
||||||
|
`/usr/share/fish/vendor_completions.d/rg.fish`.
|
||||||
|
|
||||||
|
|
||||||
11.0.2 (2019-08-01)
|
11.0.2 (2019-08-01)
|
||||||
|
408
Cargo.lock
generated
408
Cargo.lock
generated
@@ -2,62 +2,65 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
version = "0.7.6"
|
version = "0.7.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atty"
|
name = "atty"
|
||||||
version = "0.2.13"
|
version = "0.2.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hermit-abi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "autocfg"
|
||||||
version = "0.10.1"
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
|
||||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.1.0"
|
version = "1.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bstr"
|
name = "bstr"
|
||||||
version = "0.2.7"
|
version = "0.2.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex-automata 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytecount"
|
name = "bytecount"
|
||||||
version = "0.5.1"
|
version = "0.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
version = "1.3.2"
|
version = "1.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.41"
|
version = "1.0.50"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "0.1.9"
|
version = "0.1.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -65,44 +68,46 @@ name = "clap"
|
|||||||
version = "2.33.0"
|
version = "2.33.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-channel"
|
name = "crossbeam-channel"
|
||||||
version = "0.3.9"
|
version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.6.6"
|
version = "0.7.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encoding_rs"
|
name = "encoding_rs"
|
||||||
version = "0.8.17"
|
version = "0.8.22"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"packed_simd 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"packed_simd 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encoding_rs_io"
|
name = "encoding_rs_io"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"encoding_rs 0.8.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -122,122 +127,135 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "globset"
|
name = "globset"
|
||||||
version = "0.4.4"
|
version = "0.4.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bstr 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bstr 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grep"
|
name = "grep"
|
||||||
version = "0.2.4"
|
version = "0.2.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"grep-cli 0.1.3",
|
"grep-cli 0.1.4",
|
||||||
"grep-matcher 0.1.3",
|
"grep-matcher 0.1.4",
|
||||||
"grep-pcre2 0.1.3",
|
"grep-pcre2 0.1.4",
|
||||||
"grep-printer 0.1.3",
|
"grep-printer 0.1.4",
|
||||||
"grep-regex 0.1.5",
|
"grep-regex 0.1.6",
|
||||||
"grep-searcher 0.1.6",
|
"grep-searcher 0.1.7",
|
||||||
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grep-cli"
|
name = "grep-cli"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bstr 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bstr 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"globset 0.4.4",
|
"globset 0.4.5",
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grep-matcher"
|
name = "grep-matcher"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grep-pcre2"
|
name = "grep-pcre2"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"grep-matcher 0.1.3",
|
"grep-matcher 0.1.4",
|
||||||
"pcre2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pcre2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grep-printer"
|
name = "grep-printer"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bstr 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bstr 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"grep-matcher 0.1.3",
|
"grep-matcher 0.1.4",
|
||||||
"grep-regex 0.1.5",
|
"grep-regex 0.1.6",
|
||||||
"grep-searcher 0.1.6",
|
"grep-searcher 0.1.7",
|
||||||
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grep-regex"
|
name = "grep-regex"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"grep-matcher 0.1.3",
|
"bstr 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"grep-matcher 0.1.4",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex-syntax 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grep-searcher"
|
name = "grep-searcher"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bstr 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bstr 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bytecount 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"encoding_rs 0.8.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"encoding_rs_io 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"encoding_rs_io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"grep-matcher 0.1.3",
|
"grep-matcher 0.1.4",
|
||||||
"grep-regex 0.1.5",
|
"grep-regex 0.1.6",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hermit-abi"
|
||||||
|
version = "0.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ignore"
|
name = "ignore"
|
||||||
version = "0.4.10"
|
version = "0.4.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"crossbeam-channel 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"globset 0.4.4",
|
"crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"globset 0.4.5",
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "0.4.4"
|
version = "0.4.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -245,9 +263,9 @@ name = "jemalloc-sys"
|
|||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -256,7 +274,7 @@ version = "0.3.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -266,7 +284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.62"
|
version = "0.2.67"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -274,12 +292,17 @@ name = "log"
|
|||||||
version = "0.4.8"
|
version = "0.4.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "maybe-uninit"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.2.1"
|
version = "2.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -287,16 +310,17 @@ name = "memmap"
|
|||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num_cpus"
|
name = "num_cpus"
|
||||||
version = "1.10.1"
|
version = "1.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hermit-abi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -304,18 +328,18 @@ name = "packed_simd"
|
|||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pcre2"
|
name = "pcre2"
|
||||||
version = "0.2.1"
|
version = "0.2.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pcre2-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pcre2-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -323,19 +347,19 @@ name = "pcre2-sys"
|
|||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.15"
|
version = "0.3.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.1"
|
version = "1.0.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -343,91 +367,92 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.2"
|
version = "1.0.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.2.1"
|
version = "1.3.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex-syntax 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-automata"
|
name = "regex-automata"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.6.11"
|
version = "0.6.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ripgrep"
|
name = "ripgrep"
|
||||||
version = "11.0.2"
|
version = "12.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bstr 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bstr 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"grep 0.2.4",
|
"grep 0.2.5",
|
||||||
"ignore 0.4.10",
|
"ignore 0.4.12",
|
||||||
"jemallocator 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jemallocator 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.0"
|
version = "1.0.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "same-file"
|
name = "same-file"
|
||||||
version = "1.0.5"
|
version = "1.0.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.99"
|
version = "1.0.104"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.99"
|
version = "1.0.104"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.40"
|
version = "1.0.48"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ryu 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -437,20 +462,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.5"
|
version = "1.0.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "termcolor"
|
name = "termcolor"
|
||||||
version = "1.0.5"
|
version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -458,12 +483,12 @@ name = "textwrap"
|
|||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thread_local"
|
name = "thread_local"
|
||||||
version = "0.3.6"
|
version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -471,7 +496,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-width"
|
name = "unicode-width"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -481,12 +506,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "walkdir"
|
name = "walkdir"
|
||||||
version = "2.2.9"
|
version = "2.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -505,7 +530,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-util"
|
name = "winapi-util"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -516,66 +541,59 @@ name = "winapi-x86_64-pc-windows-gnu"
|
|||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wincolor"
|
|
||||||
version = "1.0.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
|
"checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
|
||||||
"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
|
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
|
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||||
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
|
"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
|
||||||
"checksum bstr 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94cdf78eb7e94c566c1f5dbe2abf8fc70a548fc902942a48c4b3a98b48ca9ade"
|
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
"checksum bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be0fdd54b507df8f22012890aadd099979befdba27713c767993f8380112ca7c"
|
"checksum bstr 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "2889e6d50f394968c8bf4240dc3f2a7eb4680844d27308f798229ac9d4725f41"
|
||||||
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
|
"checksum bytecount 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0017894339f586ccb943b01b9555de56770c11cda818e7e3d8bd93f4ed7f46e"
|
||||||
"checksum cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "8dae9c4b8fedcae85592ba623c4fd08cfdab3e3b72d6df780c6ead964a69bfff"
|
"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
|
||||||
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
|
"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
|
||||||
|
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||||
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
||||||
"checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa"
|
"checksum crossbeam-channel 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cced8691919c02aac3cb0a1bc2e9b73d89e832bf9a06fc579d4e71b68a2da061"
|
||||||
"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
|
"checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
|
||||||
"checksum encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "4155785c79f2f6701f185eb2e6b4caf0555ec03477cb4c70db67b465311620ed"
|
"checksum encoding_rs 0.8.22 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8d03faa7fe0c1431609dfad7bbe827af30f82e1e2ae6f7ee4fca6bd764bc28"
|
||||||
"checksum encoding_rs_io 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9619ee7a2bf4e777e020b95c1439abaf008f8ea8041b78a0552c4f1bcf4df32c"
|
"checksum encoding_rs_io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1cc3c5651fb62ab8aa3103998dade57efdd028544bd300516baa31840c252a83"
|
||||||
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||||
"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
|
"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
|
||||||
"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||||
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
|
"checksum hermit-abi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8"
|
||||||
|
"checksum itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
|
||||||
"checksum jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
|
"checksum jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
|
||||||
"checksum jemallocator 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69"
|
"checksum jemallocator 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69"
|
||||||
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba"
|
"checksum libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018"
|
||||||
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
|
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
|
||||||
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
|
"checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
|
||||||
|
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
|
||||||
"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
|
"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
|
||||||
"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273"
|
"checksum num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6"
|
||||||
"checksum packed_simd 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a85ea9fc0d4ac0deb6fe7911d38786b32fc11119afd9e9d38b84ff691ce64220"
|
"checksum packed_simd 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a85ea9fc0d4ac0deb6fe7911d38786b32fc11119afd9e9d38b84ff691ce64220"
|
||||||
"checksum pcre2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "603da5e101220b9b306bf28e4f1f8703458ce2f64d2787b374e1a19494317180"
|
"checksum pcre2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "85b30f2f69903b439dd9dc9e824119b82a55bf113b29af8d70948a03c1b11ab1"
|
||||||
"checksum pcre2-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "876c72d05059d23a84bd9fcdc3b1d31c50ea7fe00fe1522b4e68cd3608db8d5b"
|
"checksum pcre2-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "876c72d05059d23a84bd9fcdc3b1d31c50ea7fe00fe1522b4e68cd3608db8d5b"
|
||||||
"checksum pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c1d2cfa5a714db3b5f24f0915e74fcdf91d09d496ba61329705dda7774d2af"
|
"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
|
||||||
"checksum proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c5c2380ae88876faae57698be9e9775e3544decad214599c3a6266cca6ac802"
|
"checksum proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435"
|
||||||
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
|
"checksum quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
|
||||||
"checksum regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88c3d9193984285d544df4a30c23a4e62ead42edf70a4452ceb76dac1ce05c26"
|
"checksum regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8900ebc1363efa7ea1c399ccc32daed870b4002651e0bed86e72d501ebbe0048"
|
||||||
"checksum regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9"
|
"checksum regex-automata 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4"
|
||||||
"checksum regex-syntax 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b143cceb2ca5e56d5671988ef8b15615733e7ee16cd348e064333b251b89343f"
|
"checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae"
|
||||||
"checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
|
"checksum ryu 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535622e6be132bccd223f4bb2b8ac8d53cda3c7a6394944d3b2b33fb974f9d76"
|
||||||
"checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421"
|
"checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||||
"checksum serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "fec2851eb56d010dc9a21b89ca53ee75e6528bab60c11e89d38390904982da9f"
|
"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
|
||||||
"checksum serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425"
|
"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64"
|
||||||
"checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704"
|
"checksum serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25"
|
||||||
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||||
"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
|
"checksum syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)" = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859"
|
||||||
"checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e"
|
"checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
|
||||||
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
|
||||||
"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
|
"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
|
||||||
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||||
"checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e"
|
"checksum walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"
|
||||||
"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
|
"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
|
||||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9"
|
"checksum winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80"
|
||||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
"checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9"
|
|
||||||
|
41
Cargo.toml
41
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ripgrep"
|
name = "ripgrep"
|
||||||
version = "11.0.2" #:version
|
version = "12.0.0" #:version
|
||||||
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
ripgrep is a line-oriented search tool that recursively searches your current
|
ripgrep is a line-oriented search tool that recursively searches your current
|
||||||
@@ -25,7 +25,7 @@ appveyor = { repository = "BurntSushi/ripgrep" }
|
|||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
bench = false
|
bench = false
|
||||||
path = "src/main.rs"
|
path = "crates/core/main.rs"
|
||||||
name = "rg"
|
name = "rg"
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
@@ -34,30 +34,30 @@ path = "tests/tests.rs"
|
|||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"globset",
|
"crates/globset",
|
||||||
"grep",
|
"crates/grep",
|
||||||
"grep-cli",
|
"crates/cli",
|
||||||
"grep-matcher",
|
"crates/matcher",
|
||||||
"grep-pcre2",
|
"crates/pcre2",
|
||||||
"grep-printer",
|
"crates/printer",
|
||||||
"grep-regex",
|
"crates/regex",
|
||||||
"grep-searcher",
|
"crates/searcher",
|
||||||
"ignore",
|
"crates/ignore",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bstr = "0.2.0"
|
bstr = "0.2.12"
|
||||||
grep = { version = "0.2.4", path = "grep" }
|
grep = { version = "0.2.5", path = "crates/grep" }
|
||||||
ignore = { version = "0.4.7", path = "ignore" }
|
ignore = { version = "0.4.12", path = "crates/ignore" }
|
||||||
lazy_static = "1.1.0"
|
lazy_static = "1.1.0"
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
num_cpus = "1.8.0"
|
num_cpus = "1.8.0"
|
||||||
regex = "1.0.5"
|
regex = "1.3.5"
|
||||||
serde_json = "1.0.23"
|
serde_json = "1.0.23"
|
||||||
termcolor = "1.0.3"
|
termcolor = "1.1.0"
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
version = "2.32.0"
|
version = "2.33.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["suggestions"]
|
features = ["suggestions"]
|
||||||
|
|
||||||
@@ -68,13 +68,14 @@ version = "0.3.0"
|
|||||||
lazy_static = "1.1.0"
|
lazy_static = "1.1.0"
|
||||||
|
|
||||||
[build-dependencies.clap]
|
[build-dependencies.clap]
|
||||||
version = "2.32.0"
|
version = "2.33.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["suggestions"]
|
features = ["suggestions"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = "1.0.77"
|
serde = "1.0.77"
|
||||||
serde_derive = "1.0.77"
|
serde_derive = "1.0.77"
|
||||||
|
walkdir = "2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
simd-accel = ["grep/simd-accel"]
|
simd-accel = ["grep/simd-accel"]
|
||||||
@@ -97,11 +98,11 @@ assets = [
|
|||||||
# The man page is automatically generated by ripgrep's build process, so
|
# The man page is automatically generated by ripgrep's build process, so
|
||||||
# this file isn't actually commited. Instead, to create a dpkg, either
|
# this file isn't actually commited. Instead, to create a dpkg, either
|
||||||
# create a deployment/deb directory and copy the man page to it, or use the
|
# create a deployment/deb directory and copy the man page to it, or use the
|
||||||
# 'ci/build_deb.sh' script.
|
# 'ci/build-deb' script.
|
||||||
["deployment/deb/rg.1", "usr/share/man/man1/rg.1", "644"],
|
["deployment/deb/rg.1", "usr/share/man/man1/rg.1", "644"],
|
||||||
# Similarly for shell completions.
|
# Similarly for shell completions.
|
||||||
["deployment/deb/rg.bash", "usr/share/bash-completion/completions/rg", "644"],
|
["deployment/deb/rg.bash", "usr/share/bash-completion/completions/rg", "644"],
|
||||||
["deployment/deb/rg.fish", "usr/share/fish/completions/rg.fish", "644"],
|
["deployment/deb/rg.fish", "usr/share/fish/vendor_completions.d/rg.fish", "644"],
|
||||||
["deployment/deb/_rg", "usr/share/zsh/vendor-completions/", "644"],
|
["deployment/deb/_rg", "usr/share/zsh/vendor-completions/", "644"],
|
||||||
]
|
]
|
||||||
extended-description = """\
|
extended-description = """\
|
||||||
|
11
Cross.toml
11
Cross.toml
@@ -1,2 +1,11 @@
|
|||||||
[target.x86_64-unknown-linux-musl]
|
[target.x86_64-unknown-linux-musl]
|
||||||
image = "burntsushi/x86_64-unknown-linux-musl:v0.1.14"
|
image = "burntsushi/cross:x86_64-unknown-linux-musl"
|
||||||
|
|
||||||
|
[target.i686-unknown-linux-gnu]
|
||||||
|
image = "burntsushi/cross:i686-unknown-linux-gnu"
|
||||||
|
|
||||||
|
[target.mips64-unknown-linux-gnuabi64]
|
||||||
|
image = "burntsushi/cross:mips64-unknown-linux-gnuabi64"
|
||||||
|
|
||||||
|
[target.arm-unknown-linux-gnueabihf]
|
||||||
|
image = "burntsushi/cross:arm-unknown-linux-gnueabihf"
|
||||||
|
27
FAQ.md
27
FAQ.md
@@ -25,6 +25,7 @@
|
|||||||
* [How is ripgrep licensed?](#license)
|
* [How is ripgrep licensed?](#license)
|
||||||
* [Can ripgrep replace grep?](#posix4ever)
|
* [Can ripgrep replace grep?](#posix4ever)
|
||||||
* [What does the "rip" in ripgrep mean?](#intentcountsforsomething)
|
* [What does the "rip" in ripgrep mean?](#intentcountsforsomething)
|
||||||
|
* [How can I donate to ripgrep or its maintainers?](#donations)
|
||||||
|
|
||||||
|
|
||||||
<h3 name="config">
|
<h3 name="config">
|
||||||
@@ -50,9 +51,9 @@ ripgrep is a project whose contributors are volunteers. A release schedule
|
|||||||
adds undue stress to said volunteers. Therefore, releases are made on a best
|
adds undue stress to said volunteers. Therefore, releases are made on a best
|
||||||
effort basis and no dates **will ever be given**.
|
effort basis and no dates **will ever be given**.
|
||||||
|
|
||||||
One exception to this is high impact bugs. If a ripgrep release contains a
|
An exception to this _can be_ high impact bugs. If a ripgrep release contains
|
||||||
significant regression, then there will generally be a strong push to get a
|
a significant regression, then there will generally be a strong push to get a
|
||||||
patch release out with a fix.
|
patch release out with a fix. However, no promises are made.
|
||||||
|
|
||||||
|
|
||||||
<h3 name="manpage">
|
<h3 name="manpage">
|
||||||
@@ -934,7 +935,7 @@ Here are some cases where you might *not* want to use ripgrep. The same caveats
|
|||||||
for the previous section apply.
|
for the previous section apply.
|
||||||
|
|
||||||
* Are you writing portable shell scripts intended to work in a variety of
|
* Are you writing portable shell scripts intended to work in a variety of
|
||||||
environments? Great, probably not a good idea to use ripgrep! ripgrep is has
|
environments? Great, probably not a good idea to use ripgrep! ripgrep has
|
||||||
nowhere near the ubiquity of grep, so if you do use ripgrep, you might need
|
nowhere near the ubiquity of grep, so if you do use ripgrep, you might need
|
||||||
to futz with the installation process more than you would with grep.
|
to futz with the installation process more than you would with grep.
|
||||||
* Do you care about POSIX compatibility? If so, then you can't use ripgrep
|
* Do you care about POSIX compatibility? If so, then you can't use ripgrep
|
||||||
@@ -981,3 +982,21 @@ grep](#posix4ever),
|
|||||||
ripgrep is neither actually a "grep killer" nor was it ever intended to be. It
|
ripgrep is neither actually a "grep killer" nor was it ever intended to be. It
|
||||||
certainly does eat into some of its use cases, but that's nothing that other
|
certainly does eat into some of its use cases, but that's nothing that other
|
||||||
tools like ack or The Silver Searcher weren't already doing.
|
tools like ack or The Silver Searcher weren't already doing.
|
||||||
|
|
||||||
|
|
||||||
|
<h3 name="donations">
|
||||||
|
How can I donate to ripgrep or its maintainers?
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
As of now, you can't. While I believe the various efforts that are being
|
||||||
|
undertaken to help fund FOSS are extremely important, they aren't a good fit
|
||||||
|
for me. ripgrep is and I hope will remain a project of love that I develop in
|
||||||
|
my free time. As such, involving money---even in the form of donations given
|
||||||
|
without expectations---would severely change that dynamic for me personally.
|
||||||
|
|
||||||
|
Instead, I'd recommend donating to something else that is doing work that you
|
||||||
|
find meaningful. If you would like suggestions, then my favorites are:
|
||||||
|
|
||||||
|
* [The Internet Archive](https://archive.org/donate/)
|
||||||
|
* [Rails Girls](https://railsgirlssummerofcode.org/campaign/)
|
||||||
|
* [Wikipedia](https://wikimediafoundation.org/support/)
|
||||||
|
19
GUIDE.md
19
GUIDE.md
@@ -411,6 +411,21 @@ alias rg="rg --type-add 'web:*.{html,css,js}'"
|
|||||||
or add `--type-add=web:*.{html,css,js}` to your ripgrep configuration file.
|
or add `--type-add=web:*.{html,css,js}` to your ripgrep configuration file.
|
||||||
([Configuration files](#configuration-file) are covered in more detail later.)
|
([Configuration files](#configuration-file) are covered in more detail later.)
|
||||||
|
|
||||||
|
#### The special `all` file type
|
||||||
|
|
||||||
|
A special option supported by the `--type` flag is `all`. `--type all` looks
|
||||||
|
for a match in any of the supported file types listed by `--type-list`,
|
||||||
|
including those added on the command line using `--type-add`. It's equivalent
|
||||||
|
to the command `rg --type agda --type asciidoc --type asm ...`, where `...`
|
||||||
|
stands for a list of `--type` flags for the rest of the types in `--type-list`.
|
||||||
|
|
||||||
|
As an example, let's suppose you have a shell script in your current directory,
|
||||||
|
`my-shell-script`, which includes a shell library, `my-shell-library.bash`.
|
||||||
|
Both `rg --type sh` and `rg --type all` would only search for matches in
|
||||||
|
`my-shell-library.bash`, not `my-shell-script`, because the globs matched
|
||||||
|
by the `sh` file type don't include files without an extension. On the
|
||||||
|
other hand, `rg --type-not all` would search `my-shell-script` but not
|
||||||
|
`my-shell-library.bash`.
|
||||||
|
|
||||||
### Replacements
|
### Replacements
|
||||||
|
|
||||||
@@ -716,8 +731,8 @@ binary files:
|
|||||||
**only applies to files searched by ripgrep as a result of recursive
|
**only applies to files searched by ripgrep as a result of recursive
|
||||||
directory traversal**, which is consistent with ripgrep's other automatic
|
directory traversal**, which is consistent with ripgrep's other automatic
|
||||||
filtering. For example, `rg foo .file` will search `.file` even though it
|
filtering. For example, `rg foo .file` will search `.file` even though it
|
||||||
is hidden. Similarly, `rg foo binary-file` search `binary-file` in "binary"
|
is hidden. Similarly, `rg foo binary-file` will search `binary-file` in
|
||||||
mode automatically.
|
"binary" mode automatically.
|
||||||
2. Binary mode is similar to the default mode, except it will not always
|
2. Binary mode is similar to the default mode, except it will not always
|
||||||
stop searching after it sees a `NUL` byte. Namely, in this mode, ripgrep
|
stop searching after it sees a `NUL` byte. Namely, in this mode, ripgrep
|
||||||
will continue searching a file that is known to be binary until the first
|
will continue searching a file that is known to be binary until the first
|
||||||
|
105
README.md
105
README.md
@@ -8,12 +8,11 @@ available for [every release](https://github.com/BurntSushi/ripgrep/releases).
|
|||||||
ripgrep is similar to other popular search tools like The Silver Searcher, ack
|
ripgrep is similar to other popular search tools like The Silver Searcher, ack
|
||||||
and grep.
|
and grep.
|
||||||
|
|
||||||
[](https://travis-ci.org/BurntSushi/ripgrep)
|
[](https://github.com/BurntSushi/ripgrep/actions)
|
||||||
[](https://ci.appveyor.com/project/BurntSushi/ripgrep)
|
|
||||||
[](https://crates.io/crates/ripgrep)
|
[](https://crates.io/crates/ripgrep)
|
||||||
[](https://repology.org/project/ripgrep/badges)
|
[](https://repology.org/project/ripgrep/badges)
|
||||||
|
|
||||||
Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
|
Dual-licensed under MIT or the [UNLICENSE](https://unlicense.org).
|
||||||
|
|
||||||
|
|
||||||
### CHANGELOG
|
### CHANGELOG
|
||||||
@@ -34,56 +33,55 @@ Please see the [CHANGELOG](CHANGELOG.md) for a release history.
|
|||||||
|
|
||||||
### Screenshot of search results
|
### Screenshot of search results
|
||||||
|
|
||||||
[](http://burntsushi.net/stuff/ripgrep1.png)
|
[](https://burntsushi.net/stuff/ripgrep1.png)
|
||||||
|
|
||||||
|
|
||||||
### Quick examples comparing tools
|
### Quick examples comparing tools
|
||||||
|
|
||||||
This example searches the entire Linux kernel source tree (after running
|
This example searches the entire
|
||||||
`make defconfig && make -j8`) for `[A-Z]+_SUSPEND`, where all matches must be
|
[Linux kernel source tree](https://github.com/BurntSushi/linux)
|
||||||
words. Timings were collected on a system with an Intel i7-6900K 3.2 GHz, and
|
(after running `make defconfig && make -j8`) for `[A-Z]+_SUSPEND`, where
|
||||||
ripgrep was compiled with SIMD enabled.
|
all matches must be words. Timings were collected on a system with an Intel
|
||||||
|
i7-6900K 3.2 GHz.
|
||||||
|
|
||||||
Please remember that a single benchmark is never enough! See my
|
Please remember that a single benchmark is never enough! See my
|
||||||
[blog post on ripgrep](http://blog.burntsushi.net/ripgrep/)
|
[blog post on ripgrep](https://blog.burntsushi.net/ripgrep/)
|
||||||
for a very detailed comparison with more benchmarks and analysis.
|
for a very detailed comparison with more benchmarks and analysis.
|
||||||
|
|
||||||
| Tool | Command | Line count | Time |
|
| Tool | Command | Line count | Time |
|
||||||
| ---- | ------- | ---------- | ---- |
|
| ---- | ------- | ---------- | ---- |
|
||||||
| ripgrep (Unicode) | `rg -n -w '[A-Z]+_SUSPEND'` | 450 | **0.106s** |
|
| ripgrep (Unicode) | `rg -n -w '[A-Z]+_SUSPEND'` | 452 | **0.136s** |
|
||||||
| [git grep](https://www.kernel.org/pub/software/scm/git/docs/git-grep.html) | `LC_ALL=C git grep -E -n -w '[A-Z]+_SUSPEND'` | 450 | 0.553s |
|
| [git grep](https://www.kernel.org/pub/software/scm/git/docs/git-grep.html) | `git grep -P -n -w '[A-Z]+_SUSPEND'` | 452 | 0.348s |
|
||||||
| [The Silver Searcher](https://github.com/ggreer/the_silver_searcher) | `ag -w '[A-Z]+_SUSPEND'` | 450 | 0.589s |
|
| [ugrep (Unicode)](https://github.com/Genivia/ugrep) | `ugrep -r --ignore-files --no-hidden -I -w '[A-Z]+_SUSPEND'` | 452 | 0.506s |
|
||||||
| [git grep (Unicode)](https://www.kernel.org/pub/software/scm/git/docs/git-grep.html) | `LC_ALL=en_US.UTF-8 git grep -E -n -w '[A-Z]+_SUSPEND'` | 450 | 2.266s |
|
| [git grep](https://www.kernel.org/pub/software/scm/git/docs/git-grep.html) | `LC_ALL=C git grep -E -n -w '[A-Z]+_SUSPEND'` | 452 | 1.150s |
|
||||||
| [sift](https://github.com/svent/sift) | `sift --git -n -w '[A-Z]+_SUSPEND'` | 450 | 3.505s |
|
| [The Silver Searcher](https://github.com/ggreer/the_silver_searcher) | `ag -w '[A-Z]+_SUSPEND'` | 452 | 0.654s |
|
||||||
| [ack](https://github.com/petdance/ack2) | `ack -w '[A-Z]+_SUSPEND'` | 1878 | 6.823s |
|
| [ack](https://github.com/beyondgrep/ack3) | `ack -w '[A-Z]+_SUSPEND'` | 452 | 4.054s |
|
||||||
| [The Platinum Searcher](https://github.com/monochromegane/the_platinum_searcher) | `pt -w -e '[A-Z]+_SUSPEND'` | 450 | 14.208s |
|
| [git grep (Unicode)](https://www.kernel.org/pub/software/scm/git/docs/git-grep.html) | `LC_ALL=en_US.UTF-8 git grep -E -n -w '[A-Z]+_SUSPEND'` | 452 | 4.205s |
|
||||||
|
|
||||||
(Yes, `ack` [has](https://github.com/petdance/ack2/issues/445) a
|
Here's another benchmark on the same corpus as above that disregards gitignore
|
||||||
[bug](https://github.com/petdance/ack2/issues/14).)
|
files and searches with a whitelist instead. The corpus is the same as in the
|
||||||
|
previous benchmark, and the flags passed to each command ensure that they are
|
||||||
Here's another benchmark that disregards gitignore files and searches with a
|
doing equivalent work:
|
||||||
whitelist instead. The corpus is the same as in the previous benchmark, and the
|
|
||||||
flags passed to each command ensure that they are doing equivalent work:
|
|
||||||
|
|
||||||
| Tool | Command | Line count | Time |
|
| Tool | Command | Line count | Time |
|
||||||
| ---- | ------- | ---------- | ---- |
|
| ---- | ------- | ---------- | ---- |
|
||||||
| ripgrep | `rg -L -u -tc -n -w '[A-Z]+_SUSPEND'` | 404 | **0.079s** |
|
| ripgrep | `rg -uuu -tc -n -w '[A-Z]+_SUSPEND'` | 388 | **0.096s** |
|
||||||
| [ucg](https://github.com/gvansickle/ucg) | `ucg --type=cc -w '[A-Z]+_SUSPEND'` | 390 | 0.163s |
|
| [ugrep](https://github.com/Genivia/ugrep) | `ugrep -r -n --include='*.c' --include='*.h' -w '[A-Z]+_SUSPEND'` | 388 | 0.493s |
|
||||||
| [GNU grep](https://www.gnu.org/software/grep/) | `egrep -R -n --include='*.c' --include='*.h' -w '[A-Z]+_SUSPEND'` | 404 | 0.611s |
|
| [GNU grep](https://www.gnu.org/software/grep/) | `egrep -r -n --include='*.c' --include='*.h' -w '[A-Z]+_SUSPEND'` | 388 | 0.806s |
|
||||||
|
|
||||||
(`ucg` [has slightly different behavior in the presence of symbolic links](https://github.com/gvansickle/ucg/issues/106).)
|
And finally, a straight-up comparison between ripgrep, ugrep and GNU grep on a
|
||||||
|
single large file cached in memory
|
||||||
And finally, a straight-up comparison between ripgrep and GNU grep on a single
|
(~13GB, [`OpenSubtitles.raw.en.gz`](http://opus.nlpl.eu/download.php?f=OpenSubtitles/v2018/mono/OpenSubtitles.raw.en.gz)):
|
||||||
large file (~9.3GB,
|
|
||||||
[`OpenSubtitles2016.raw.en.gz`](http://opus.lingfil.uu.se/OpenSubtitles2016/mono/OpenSubtitles2016.raw.en.gz)):
|
|
||||||
|
|
||||||
| Tool | Command | Line count | Time |
|
| Tool | Command | Line count | Time |
|
||||||
| ---- | ------- | ---------- | ---- |
|
| ---- | ------- | ---------- | ---- |
|
||||||
| ripgrep | `rg -w 'Sherlock [A-Z]\w+'` | 5268 | **2.108s** |
|
| ripgrep | `rg -w 'Sherlock [A-Z]\w+'` | 7882 | **2.769s** |
|
||||||
| [GNU grep](https://www.gnu.org/software/grep/) | `LC_ALL=C egrep -w 'Sherlock [A-Z]\w+'` | 5268 | 7.014s |
|
| [ugrep](https://github.com/Genivia/ugrep) | `ugrep -w 'Sherlock [A-Z]\w+'` | 7882 | 6.802s |
|
||||||
|
| [GNU grep](https://www.gnu.org/software/grep/) | `LC_ALL=en_US.UTF-8 egrep -w 'Sherlock [A-Z]\w+'` | 7882 | 9.027s |
|
||||||
|
|
||||||
In the above benchmark, passing the `-n` flag (for showing line numbers)
|
In the above benchmark, passing the `-n` flag (for showing line numbers)
|
||||||
increases the times to `2.640s` for ripgrep and `10.277s` for GNU grep.
|
increases the times to `3.423s` for ripgrep and `13.031s` for GNU grep. ugrep
|
||||||
|
times are unaffected by the presence or absence of `-n`.
|
||||||
|
|
||||||
|
|
||||||
### Why should I use ripgrep?
|
### Why should I use ripgrep?
|
||||||
@@ -110,7 +108,8 @@ increases the times to `2.640s` for ripgrep and `10.277s` for GNU grep.
|
|||||||
Among other things, this makes it possible to use look-around and
|
Among other things, this makes it possible to use look-around and
|
||||||
backreferences in your patterns, which are not supported in ripgrep's default
|
backreferences in your patterns, which are not supported in ripgrep's default
|
||||||
regex engine. PCRE2 support can be enabled with `-P/--pcre2` (use PCRE2
|
regex engine. PCRE2 support can be enabled with `-P/--pcre2` (use PCRE2
|
||||||
always) or `--auto-hybrid-regex` (use PCRE2 only if needed).
|
always) or `--auto-hybrid-regex` (use PCRE2 only if needed). An alternative
|
||||||
|
syntax is provided via the `--engine (default|pcre2|auto-hybrid)` option.
|
||||||
* ripgrep supports searching files in text encodings other than UTF-8, such
|
* ripgrep supports searching files in text encodings other than UTF-8, such
|
||||||
as UTF-16, latin-1, GBK, EUC-JP, Shift_JIS and more. (Some support for
|
as UTF-16, latin-1, GBK, EUC-JP, Shift_JIS and more. (Some support for
|
||||||
automatically detecting UTF-16 is provided. Other text encodings must be
|
automatically detecting UTF-16 is provided. Other text encodings must be
|
||||||
@@ -150,12 +149,12 @@ or more of the following:
|
|||||||
### Is it really faster than everything else?
|
### Is it really faster than everything else?
|
||||||
|
|
||||||
Generally, yes. A large number of benchmarks with detailed analysis for each is
|
Generally, yes. A large number of benchmarks with detailed analysis for each is
|
||||||
[available on my blog](http://blog.burntsushi.net/ripgrep/).
|
[available on my blog](https://blog.burntsushi.net/ripgrep/).
|
||||||
|
|
||||||
Summarizing, ripgrep is fast because:
|
Summarizing, ripgrep is fast because:
|
||||||
|
|
||||||
* It is built on top of
|
* It is built on top of
|
||||||
[Rust's regex engine](https://github.com/rust-lang-nursery/regex).
|
[Rust's regex engine](https://github.com/rust-lang/regex).
|
||||||
Rust's regex engine uses finite automata, SIMD and aggressive literal
|
Rust's regex engine uses finite automata, SIMD and aggressive literal
|
||||||
optimizations to make searching very fast. (PCRE2 support can be opted into
|
optimizations to make searching very fast. (PCRE2 support can be opted into
|
||||||
with the `-P/--pcre2` flag.)
|
with the `-P/--pcre2` flag.)
|
||||||
@@ -202,9 +201,8 @@ prefer MSVC over GNU, but you'll need to have the [Microsoft VC++ 2015
|
|||||||
redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=48145)
|
redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=48145)
|
||||||
installed.
|
installed.
|
||||||
|
|
||||||
If you're a **macOS Homebrew** or a **Linuxbrew** user,
|
If you're a **macOS Homebrew** or a **Linuxbrew** user, then you can install
|
||||||
then you can install ripgrep either
|
ripgrep from homebrew-core:
|
||||||
from homebrew-core, (compiled with rust stable, no SIMD):
|
|
||||||
|
|
||||||
```
|
```
|
||||||
$ brew install ripgrep
|
$ brew install ripgrep
|
||||||
@@ -251,23 +249,14 @@ repositories.
|
|||||||
$ sudo dnf install ripgrep
|
$ sudo dnf install ripgrep
|
||||||
```
|
```
|
||||||
|
|
||||||
If you're an **openSUSE Leap 15.0** user, you can install ripgrep from the
|
If you're an **openSUSE** user, ripgrep is included in **openSUSE Tumbleweed**
|
||||||
[utilities repo](https://build.opensuse.org/package/show/utilities/ripgrep):
|
and **openSUSE Leap** since 15.1.
|
||||||
|
|
||||||
```
|
|
||||||
$ sudo zypper ar https://download.opensuse.org/repositories/utilities/openSUSE_Leap_15.0/utilities.repo
|
|
||||||
$ sudo zypper install ripgrep
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
If you're an **openSUSE Tumbleweed** user, you can install ripgrep from the
|
|
||||||
[official repo](http://software.opensuse.org/package/ripgrep):
|
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo zypper install ripgrep
|
$ sudo zypper install ripgrep
|
||||||
```
|
```
|
||||||
|
|
||||||
If you're a **RHEL/CentOS 7** user, you can install ripgrep from
|
If you're a **RHEL/CentOS 7/8** user, you can install ripgrep from
|
||||||
[copr](https://copr.fedorainfracloud.org/coprs/carlwgeorge/ripgrep/):
|
[copr](https://copr.fedorainfracloud.org/coprs/carlwgeorge/ripgrep/):
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -332,6 +321,20 @@ If you're a **NetBSD** user, then you can install ripgrep from
|
|||||||
# pkgin install ripgrep
|
# pkgin install ripgrep
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you're a **Haiku x86_64** user, then you can install ripgrep from the
|
||||||
|
[official ports](https://github.com/haikuports/haikuports/tree/master/sys-apps/ripgrep):
|
||||||
|
|
||||||
|
```
|
||||||
|
$ pkgman install ripgrep
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're a **Haiku x86_gcc2** user, then you can install ripgrep from the
|
||||||
|
same port as Haiku x86_64 using the x86 secondary architecture build:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ pkgman install ripgrep_x86
|
||||||
|
```
|
||||||
|
|
||||||
If you're a **Rust programmer**, ripgrep can be installed with `cargo`.
|
If you're a **Rust programmer**, ripgrep can be installed with `cargo`.
|
||||||
|
|
||||||
* Note that the minimum supported version of Rust for ripgrep is **1.34.0**,
|
* Note that the minimum supported version of Rust for ripgrep is **1.34.0**,
|
||||||
|
81
appveyor.yml
81
appveyor.yml
@@ -1,81 +0,0 @@
|
|||||||
cache:
|
|
||||||
- c:\cargo\registry
|
|
||||||
- c:\cargo\git
|
|
||||||
|
|
||||||
init:
|
|
||||||
- mkdir c:\cargo
|
|
||||||
- mkdir c:\rustup
|
|
||||||
- SET PATH=c:\cargo\bin;%PATH%
|
|
||||||
|
|
||||||
clone_folder: c:\projects\ripgrep
|
|
||||||
|
|
||||||
environment:
|
|
||||||
CARGO_HOME: "c:\\cargo"
|
|
||||||
RUSTUP_HOME: "c:\\rustup"
|
|
||||||
CARGO_TARGET_DIR: "c:\\projects\\ripgrep\\target"
|
|
||||||
global:
|
|
||||||
PROJECT_NAME: ripgrep
|
|
||||||
RUST_BACKTRACE: full
|
|
||||||
matrix:
|
|
||||||
- TARGET: x86_64-pc-windows-gnu
|
|
||||||
CHANNEL: stable
|
|
||||||
BITS: 64
|
|
||||||
MSYS2: 1
|
|
||||||
- TARGET: x86_64-pc-windows-msvc
|
|
||||||
CHANNEL: stable
|
|
||||||
BITS: 64
|
|
||||||
- TARGET: i686-pc-windows-gnu
|
|
||||||
CHANNEL: stable
|
|
||||||
BITS: 32
|
|
||||||
MSYS2: 1
|
|
||||||
- TARGET: i686-pc-windows-msvc
|
|
||||||
CHANNEL: stable
|
|
||||||
BITS: 32
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
|
|
||||||
# Install Rust and Cargo
|
|
||||||
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)
|
|
||||||
install:
|
|
||||||
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
|
|
||||||
- rustup-init.exe -y --default-host %TARGET%
|
|
||||||
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
|
|
||||||
- if defined MSYS2 set PATH=C:\msys64\mingw%BITS%\bin;%PATH%
|
|
||||||
- rustc -V
|
|
||||||
- cargo -V
|
|
||||||
|
|
||||||
# Hack to work around a harmless warning in Appveyor builds?
|
|
||||||
build: false
|
|
||||||
|
|
||||||
# Equivalent to Travis' `script` phase
|
|
||||||
test_script:
|
|
||||||
- cargo test --verbose --all --features pcre2
|
|
||||||
|
|
||||||
before_deploy:
|
|
||||||
# Generate artifacts for release
|
|
||||||
- cargo build --release --features pcre2
|
|
||||||
- mkdir staging
|
|
||||||
- copy target\release\rg.exe staging
|
|
||||||
- ps: copy target\release\build\ripgrep-*\out\_rg.ps1 staging
|
|
||||||
- cd staging
|
|
||||||
# release zipfile will look like 'ripgrep-1.2.3-x86_64-pc-windows-msvc'
|
|
||||||
- 7z a ../%PROJECT_NAME%-%APPVEYOR_REPO_TAG_NAME%-%TARGET%.zip *
|
|
||||||
- appveyor PushArtifact ../%PROJECT_NAME%-%APPVEYOR_REPO_TAG_NAME%-%TARGET%.zip
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
description: 'Automatically deployed release'
|
|
||||||
# All the zipped artifacts will be deployed
|
|
||||||
artifact: /.*\.zip/
|
|
||||||
auth_token:
|
|
||||||
secure: vv4vBCEosGlyQjaEC1+kraP2P6O4CQSa+Tw50oHWFTGcmuXxaWS0/yEXbxsIRLpw
|
|
||||||
provider: GitHub
|
|
||||||
# deploy when a new tag is pushed and only on the stable channel
|
|
||||||
on:
|
|
||||||
CHANNEL: stable
|
|
||||||
appveyor_repo_tag: true
|
|
||||||
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- /^\d+\.\d+\.\d+$/
|
|
||||||
- master
|
|
22
build.rs
22
build.rs
@@ -9,7 +9,7 @@ use clap::Shell;
|
|||||||
use app::{RGArg, RGArgKind};
|
use app::{RGArg, RGArgKind};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[path = "src/app.rs"]
|
#[path = "crates/core/app.rs"]
|
||||||
mod app;
|
mod app;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -21,7 +21,8 @@ fn main() {
|
|||||||
eprintln!(
|
eprintln!(
|
||||||
"OUT_DIR environment variable not defined. \
|
"OUT_DIR environment variable not defined. \
|
||||||
Please file a bug: \
|
Please file a bug: \
|
||||||
https://github.com/BurntSushi/ripgrep/issues/new");
|
https://github.com/BurntSushi/ripgrep/issues/new"
|
||||||
|
);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -85,13 +86,15 @@ fn generate_man_page<P: AsRef<Path>>(outdir: P) -> io::Result<()> {
|
|||||||
|
|
||||||
let githash = git_revision_hash();
|
let githash = git_revision_hash();
|
||||||
let githash = githash.as_ref().map(|x| &**x);
|
let githash = githash.as_ref().map(|x| &**x);
|
||||||
tpl = tpl.replace("{VERSION}", &app::long_version(githash));
|
tpl = tpl.replace("{VERSION}", &app::long_version(githash, false));
|
||||||
|
|
||||||
File::create(&txt_path)?.write_all(tpl.as_bytes())?;
|
File::create(&txt_path)?.write_all(tpl.as_bytes())?;
|
||||||
let result = process::Command::new("a2x")
|
let result = process::Command::new("a2x")
|
||||||
.arg("--no-xmllint")
|
.arg("--no-xmllint")
|
||||||
.arg("--doctype").arg("manpage")
|
.arg("--doctype")
|
||||||
.arg("--format").arg("manpage")
|
.arg("manpage")
|
||||||
|
.arg("--format")
|
||||||
|
.arg("manpage")
|
||||||
.arg(&txt_path)
|
.arg(&txt_path)
|
||||||
.spawn()?
|
.spawn()?
|
||||||
.wait()?;
|
.wait()?;
|
||||||
@@ -114,7 +117,7 @@ fn formatted_options() -> io::Result<String> {
|
|||||||
// ripgrep only has two positional arguments, and probably will only
|
// ripgrep only has two positional arguments, and probably will only
|
||||||
// ever have two positional arguments, so we just hardcode them into
|
// ever have two positional arguments, so we just hardcode them into
|
||||||
// the template.
|
// the template.
|
||||||
if let app::RGArgKind::Positional{..} = arg.kind {
|
if let app::RGArgKind::Positional { .. } = arg.kind {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
formatted.push(formatted_arg(&arg)?);
|
formatted.push(formatted_arg(&arg)?);
|
||||||
@@ -124,7 +127,9 @@ fn formatted_options() -> io::Result<String> {
|
|||||||
|
|
||||||
fn formatted_arg(arg: &RGArg) -> io::Result<String> {
|
fn formatted_arg(arg: &RGArg) -> io::Result<String> {
|
||||||
match arg.kind {
|
match arg.kind {
|
||||||
RGArgKind::Positional{..} => panic!("unexpected positional argument"),
|
RGArgKind::Positional { .. } => {
|
||||||
|
panic!("unexpected positional argument")
|
||||||
|
}
|
||||||
RGArgKind::Switch { long, short, multiple } => {
|
RGArgKind::Switch { long, short, multiple } => {
|
||||||
let mut out = vec![];
|
let mut out = vec![];
|
||||||
|
|
||||||
@@ -163,7 +168,8 @@ fn formatted_arg(arg: &RGArg) -> io::Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn formatted_doc_txt(arg: &RGArg) -> io::Result<String> {
|
fn formatted_doc_txt(arg: &RGArg) -> io::Result<String> {
|
||||||
let paragraphs: Vec<String> = arg.doc_long
|
let paragraphs: Vec<String> = arg
|
||||||
|
.doc_long
|
||||||
.replace("{", "{")
|
.replace("{", "{")
|
||||||
.replace("}", r"}")
|
.replace("}", r"}")
|
||||||
.split("\n\n")
|
.split("\n\n")
|
||||||
|
@@ -1,62 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# package the build artifacts
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
. "$(dirname $0)/utils.sh"
|
|
||||||
|
|
||||||
# Generate artifacts for release
|
|
||||||
mk_artifacts() {
|
|
||||||
CARGO="$(builder)"
|
|
||||||
if is_arm; then
|
|
||||||
"$CARGO" build --target "$TARGET" --release
|
|
||||||
else
|
|
||||||
# Technically, MUSL builds will force PCRE2 to get statically compiled,
|
|
||||||
# but we also want PCRE2 statically build for macOS binaries.
|
|
||||||
PCRE2_SYS_STATIC=1 "$CARGO" build --target "$TARGET" --release --features 'pcre2'
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
mk_tarball() {
|
|
||||||
# When cross-compiling, use the right `strip` tool on the binary.
|
|
||||||
local gcc_prefix="$(gcc_prefix)"
|
|
||||||
# Create a temporary dir that contains our staging area.
|
|
||||||
# $tmpdir/$name is what eventually ends up as the deployed archive.
|
|
||||||
local tmpdir="$(mktemp -d)"
|
|
||||||
local name="${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}"
|
|
||||||
local staging="$tmpdir/$name"
|
|
||||||
mkdir -p "$staging"/{complete,doc}
|
|
||||||
# The deployment directory is where the final archive will reside.
|
|
||||||
# This path is known by the .travis.yml configuration.
|
|
||||||
local out_dir="$(pwd)/deployment"
|
|
||||||
mkdir -p "$out_dir"
|
|
||||||
# Find the correct (most recent) Cargo "out" directory. The out directory
|
|
||||||
# contains shell completion files and the man page.
|
|
||||||
local cargo_out_dir="$(cargo_out_dir "target/$TARGET")"
|
|
||||||
|
|
||||||
# Copy the ripgrep binary and strip it.
|
|
||||||
cp "target/$TARGET/release/rg" "$staging/rg"
|
|
||||||
"${gcc_prefix}strip" "$staging/rg"
|
|
||||||
# Copy the licenses and README.
|
|
||||||
cp {README.md,UNLICENSE,COPYING,LICENSE-MIT} "$staging/"
|
|
||||||
# Copy documentation and man page.
|
|
||||||
cp {CHANGELOG.md,FAQ.md,GUIDE.md} "$staging/doc/"
|
|
||||||
if command -V a2x 2>&1 > /dev/null; then
|
|
||||||
# The man page should only exist if we have asciidoc installed.
|
|
||||||
cp "$cargo_out_dir/rg.1" "$staging/doc/"
|
|
||||||
fi
|
|
||||||
# Copy shell completion files.
|
|
||||||
cp "$cargo_out_dir"/{rg.bash,rg.fish,_rg.ps1} "$staging/complete/"
|
|
||||||
cp complete/_rg "$staging/complete/"
|
|
||||||
|
|
||||||
(cd "$tmpdir" && tar czf "$out_dir/$name.tar.gz" "$name")
|
|
||||||
rm -rf "$tmpdir"
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
mk_artifacts
|
|
||||||
mk_tarball
|
|
||||||
}
|
|
||||||
|
|
||||||
main
|
|
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
D="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
||||||
|
|
||||||
# This script builds a binary dpkg for Debian based distros. It does not
|
# This script builds a binary dpkg for Debian based distros. It does not
|
||||||
# currently run in CI, and is instead run manually and the resulting dpkg is
|
# currently run in CI, and is instead run manually and the resulting dpkg is
|
||||||
@@ -23,20 +24,12 @@ fi
|
|||||||
# the deb, which knows where to look.
|
# the deb, which knows where to look.
|
||||||
|
|
||||||
DEPLOY_DIR=deployment/deb
|
DEPLOY_DIR=deployment/deb
|
||||||
|
OUT_DIR="$("$D"/cargo-out-dir target/debug/)"
|
||||||
mkdir -p "$DEPLOY_DIR"
|
mkdir -p "$DEPLOY_DIR"
|
||||||
cargo build
|
cargo build
|
||||||
|
|
||||||
# Find and copy man page.
|
# Copy man page and shell completions.
|
||||||
manpage="$(find ./target/debug -name rg.1 -print0 | xargs -0 ls -t | head -n1)"
|
cp "$OUT_DIR"/{rg.1,rg.bash,rg.fish,_rg} "$DEPLOY_DIR/"
|
||||||
cp "$manpage" "$DEPLOY_DIR/"
|
|
||||||
|
|
||||||
# Do the same for shell completions.
|
|
||||||
compbash="$(find ./target/debug -name rg.bash -print0 | xargs -0 ls -t | head -n1)"
|
|
||||||
cp "$compbash" "$DEPLOY_DIR/"
|
|
||||||
compfish="$(find ./target/debug -name rg.fish -print0 | xargs -0 ls -t | head -n1)"
|
|
||||||
cp "$compfish" "$DEPLOY_DIR/"
|
|
||||||
compzsh="complete/_rg"
|
|
||||||
cp "$compzsh" "$DEPLOY_DIR/"
|
|
||||||
|
|
||||||
# Since we're distributing the dpkg, we don't know whether the user will have
|
# Since we're distributing the dpkg, we don't know whether the user will have
|
||||||
# PCRE2 installed, so just do a static build.
|
# PCRE2 installed, so just do a static build.
|
19
ci/cargo-out-dir
Executable file
19
ci/cargo-out-dir
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Finds Cargo's `OUT_DIR` directory from the most recent build.
|
||||||
|
#
|
||||||
|
# This requires one parameter corresponding to the target directory
|
||||||
|
# to search for the build output.
|
||||||
|
|
||||||
|
if [ $# != 1 ]; then
|
||||||
|
echo "Usage: $(basename "$0") <target-dir>" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# This works by finding the most recent stamp file, which is produced by
|
||||||
|
# every ripgrep build.
|
||||||
|
target_dir="$1"
|
||||||
|
find "$target_dir" -name ripgrep-stamp -print0 \
|
||||||
|
| xargs -0 ls -t \
|
||||||
|
| head -n1 \
|
||||||
|
| xargs dirname
|
24
ci/docker/README.md
Normal file
24
ci/docker/README.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
These are Docker images used for cross compilation in CI builds (or locally)
|
||||||
|
via the [Cross](https://github.com/rust-embedded/cross) tool.
|
||||||
|
|
||||||
|
The Cross tool actually provides its own Docker images, and all Docker images
|
||||||
|
in this directory are derived from one of them. We provide our own in order
|
||||||
|
to customize the environment. For example, we need to install some things like
|
||||||
|
`asciidoc` in order to generate man pages. We also install compression tools
|
||||||
|
like `xz` so that tests for the `-z/--search-zip` flag are run.
|
||||||
|
|
||||||
|
If you make a change to a Docker image, then you can re-build it. `cd` into the
|
||||||
|
directory containing the `Dockerfile` and run:
|
||||||
|
|
||||||
|
$ cd x86_64-unknown-linux-musl
|
||||||
|
$ ./build
|
||||||
|
|
||||||
|
At this point, subsequent uses of `cross` will now use your built image since
|
||||||
|
Docker prefers local images over remote images. In order to make these changes
|
||||||
|
stick, they need to be pushed to Docker Hub:
|
||||||
|
|
||||||
|
$ docker push burntsushi/cross:x86_64-unknown-linux-musl
|
||||||
|
|
||||||
|
Of course, only I (BurntSushi) can push to that location. To make `cross` use
|
||||||
|
a different location, then edit `Cross.toml` in the root of this repo to use
|
||||||
|
a different image name for the desired target.
|
4
ci/docker/arm-unknown-linux-gnueabihf/Dockerfile
Normal file
4
ci/docker/arm-unknown-linux-gnueabihf/Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FROM rustembedded/cross:arm-unknown-linux-gnueabihf
|
||||||
|
|
||||||
|
COPY stage/ubuntu-install-packages /
|
||||||
|
RUN /ubuntu-install-packages
|
5
ci/docker/arm-unknown-linux-gnueabihf/build
Executable file
5
ci/docker/arm-unknown-linux-gnueabihf/build
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
mkdir -p stage
|
||||||
|
cp ../../ubuntu-install-packages ./stage/
|
||||||
|
docker build -t burntsushi/cross:arm-unknown-linux-gnueabihf .
|
4
ci/docker/i686-unknown-linux-gnu/Dockerfile
Normal file
4
ci/docker/i686-unknown-linux-gnu/Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FROM rustembedded/cross:i686-unknown-linux-gnu
|
||||||
|
|
||||||
|
COPY stage/ubuntu-install-packages /
|
||||||
|
RUN /ubuntu-install-packages
|
5
ci/docker/i686-unknown-linux-gnu/build
Executable file
5
ci/docker/i686-unknown-linux-gnu/build
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
mkdir -p stage
|
||||||
|
cp ../../ubuntu-install-packages ./stage/
|
||||||
|
docker build -t burntsushi/cross:i686-unknown-linux-gnu .
|
4
ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile
Normal file
4
ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FROM rustembedded/cross:mips64-unknown-linux-gnuabi64
|
||||||
|
|
||||||
|
COPY stage/ubuntu-install-packages /
|
||||||
|
RUN /ubuntu-install-packages
|
5
ci/docker/mips64-unknown-linux-gnuabi64/build
Executable file
5
ci/docker/mips64-unknown-linux-gnuabi64/build
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
mkdir -p stage
|
||||||
|
cp ../../ubuntu-install-packages ./stage/
|
||||||
|
docker build -t burntsushi/cross:mips64-unknown-linux-gnuabi64 .
|
@@ -1,5 +1,4 @@
|
|||||||
FROM japaric/x86_64-unknown-linux-musl:v0.1.14
|
FROM rustembedded/cross:x86_64-unknown-linux-musl
|
||||||
|
|
||||||
RUN apt-get update \
|
COPY stage/ubuntu-install-packages /
|
||||||
&& apt-get install -y --no-install-recommends \
|
RUN /ubuntu-install-packages
|
||||||
libxslt1-dev asciidoc docbook-xsl xsltproc libxml2-utils
|
|
||||||
|
5
ci/docker/x86_64-unknown-linux-musl/build
Executable file
5
ci/docker/x86_64-unknown-linux-musl/build
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
mkdir -p stage
|
||||||
|
cp ../../ubuntu-install-packages ./stage/
|
||||||
|
docker build -t burntsushi/cross:x86_64-unknown-linux-musl .
|
@@ -1,61 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# install stuff needed for the `script` phase
|
|
||||||
|
|
||||||
# Where rustup gets installed.
|
|
||||||
export PATH="$PATH:$HOME/.cargo/bin"
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
. "$(dirname $0)/utils.sh"
|
|
||||||
|
|
||||||
install_rustup() {
|
|
||||||
curl https://sh.rustup.rs -sSf \
|
|
||||||
| sh -s -- -y --default-toolchain="$TRAVIS_RUST_VERSION"
|
|
||||||
rustc -V
|
|
||||||
cargo -V
|
|
||||||
}
|
|
||||||
|
|
||||||
install_targets() {
|
|
||||||
if [ $(host) != "$TARGET" ]; then
|
|
||||||
rustup target add $TARGET
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
install_osx_dependencies() {
|
|
||||||
if ! is_osx; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
brew install asciidoc docbook-xsl
|
|
||||||
}
|
|
||||||
|
|
||||||
configure_cargo() {
|
|
||||||
local prefix=$(gcc_prefix)
|
|
||||||
if [ -n "${prefix}" ]; then
|
|
||||||
local gcc_suffix=
|
|
||||||
if [ -n "$GCC_VERSION" ]; then
|
|
||||||
gcc_suffix="-$GCC_VERSION"
|
|
||||||
fi
|
|
||||||
local gcc="${prefix}gcc${gcc_suffix}"
|
|
||||||
|
|
||||||
# information about the cross compiler
|
|
||||||
"${gcc}" -v
|
|
||||||
|
|
||||||
# tell cargo which linker to use for cross compilation
|
|
||||||
mkdir -p .cargo
|
|
||||||
cat >>.cargo/config <<EOF
|
|
||||||
[target.$TARGET]
|
|
||||||
linker = "${gcc}"
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
install_osx_dependencies
|
|
||||||
install_rustup
|
|
||||||
install_targets
|
|
||||||
configure_cargo
|
|
||||||
}
|
|
||||||
|
|
||||||
main
|
|
3
ci/macos-install-packages
Executable file
3
ci/macos-install-packages
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
brew install asciidoc docbook-xsl
|
52
ci/script.sh
52
ci/script.sh
@@ -1,52 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# build, test and generate docs in this phase
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
. "$(dirname $0)/utils.sh"
|
|
||||||
|
|
||||||
main() {
|
|
||||||
CARGO="$(builder)"
|
|
||||||
|
|
||||||
# Test a normal debug build.
|
|
||||||
if is_arm; then
|
|
||||||
"$CARGO" build --target "$TARGET" --verbose
|
|
||||||
else
|
|
||||||
"$CARGO" build --target "$TARGET" --verbose --all --features 'pcre2'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Show the output of the most recent build.rs stderr.
|
|
||||||
set +x
|
|
||||||
stderr="$(find "target/$TARGET/debug" -name stderr -print0 | xargs -0 ls -t | head -n1)"
|
|
||||||
if [ -s "$stderr" ]; then
|
|
||||||
echo "===== $stderr ====="
|
|
||||||
cat "$stderr"
|
|
||||||
echo "====="
|
|
||||||
fi
|
|
||||||
set -x
|
|
||||||
|
|
||||||
# sanity check the file type
|
|
||||||
file target/"$TARGET"/debug/rg
|
|
||||||
|
|
||||||
# Check that we've generated man page and other shell completions.
|
|
||||||
outdir="$(cargo_out_dir "target/$TARGET/debug")"
|
|
||||||
file "$outdir/rg.bash"
|
|
||||||
file "$outdir/rg.fish"
|
|
||||||
file "$outdir/_rg.ps1"
|
|
||||||
file "$outdir/rg.1"
|
|
||||||
|
|
||||||
# Apparently tests don't work on arm, so just bail now. I guess we provide
|
|
||||||
# ARM releases on a best effort basis?
|
|
||||||
if is_arm; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Test that zsh completions are in sync with ripgrep's actual args.
|
|
||||||
"$(dirname "${0}")/test_complete.sh"
|
|
||||||
|
|
||||||
# Run tests for ripgrep and all sub-crates.
|
|
||||||
"$CARGO" test --target "$TARGET" --verbose --all --features 'pcre2'
|
|
||||||
}
|
|
||||||
|
|
||||||
main
|
|
@@ -18,7 +18,7 @@ get_comp_args() {
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
local diff
|
local diff
|
||||||
local rg="${0:a:h}/../target/${TARGET:-}/release/rg"
|
local rg="${0:a:h}/../${TARGET_DIR:-target}/release/rg"
|
||||||
local _rg="${0:a:h}/../complete/_rg"
|
local _rg="${0:a:h}/../complete/_rg"
|
||||||
local -a help_args comp_args
|
local -a help_args comp_args
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ main() {
|
|||||||
# Occasionally we may have to handle some manually, however
|
# Occasionally we may have to handle some manually, however
|
||||||
help_args=( ${(f)"$(
|
help_args=( ${(f)"$(
|
||||||
$rg --help |
|
$rg --help |
|
||||||
$rg -i -- '^\s+--?[a-z0-9]|--[imnp]' |
|
$rg -i -- '^\s+--?[a-z0-9]|--[a-z]' |
|
||||||
$rg -ior '$1' -- $'[\t /\"\'`.,](-[a-z0-9]|--[a-z0-9-]+)\\b' |
|
$rg -ior '$1' -- $'[\t /\"\'`.,](-[a-z0-9]|--[a-z0-9-]+)\\b' |
|
||||||
$rg -v -- --print0 | # False positives
|
$rg -v -- --print0 | # False positives
|
||||||
sort -u
|
sort -u
|
6
ci/ubuntu-install-packages
Executable file
6
ci/ubuntu-install-packages
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y --no-install-recommends \
|
||||||
|
libxslt1-dev asciidoc docbook-xsl xsltproc libxml2-utils \
|
||||||
|
zsh xz-utils liblz4-tool musl-tools
|
@@ -99,7 +99,9 @@ is_osx() {
|
|||||||
|
|
||||||
builder() {
|
builder() {
|
||||||
if is_musl && is_x86_64; then
|
if is_musl && is_x86_64; then
|
||||||
cargo install cross
|
# cargo install cross
|
||||||
|
# To work around https://github.com/rust-embedded/cross/issues/357
|
||||||
|
cargo install --git https://github.com/rust-embedded/cross --force
|
||||||
echo "cross"
|
echo "cross"
|
||||||
else
|
else
|
||||||
echo "cargo"
|
echo "cargo"
|
||||||
|
32
complete/_rg
32
complete/_rg
@@ -3,7 +3,7 @@
|
|||||||
##
|
##
|
||||||
# zsh completion function for ripgrep
|
# zsh completion function for ripgrep
|
||||||
#
|
#
|
||||||
# Run ci/test_complete.sh after building to ensure that the options supported by
|
# Run ci/test-complete after building to ensure that the options supported by
|
||||||
# this function stay in synch with the `rg` binary.
|
# this function stay in synch with the `rg` binary.
|
||||||
#
|
#
|
||||||
# For convenience, a completion reference guide is included at the bottom of
|
# For convenience, a completion reference guide is included at the bottom of
|
||||||
@@ -72,11 +72,19 @@ _rg() {
|
|||||||
+ '(count)' # Counting options
|
+ '(count)' # Counting options
|
||||||
{-c,--count}'[only show count of matching lines for each file]'
|
{-c,--count}'[only show count of matching lines for each file]'
|
||||||
'--count-matches[only show count of individual matches for each file]'
|
'--count-matches[only show count of individual matches for each file]'
|
||||||
|
'--include-zero[include files with zero matches in summary]'
|
||||||
|
|
||||||
+ '(encoding)' # Encoding options
|
+ '(encoding)' # Encoding options
|
||||||
{-E+,--encoding=}'[specify text encoding of files to search]: :_rg_encodings'
|
{-E+,--encoding=}'[specify text encoding of files to search]: :_rg_encodings'
|
||||||
$no'--no-encoding[use default text encoding]'
|
$no'--no-encoding[use default text encoding]'
|
||||||
|
|
||||||
|
+ '(engine)' # Engine choice options
|
||||||
|
'--engine=[select which regex engine to use]:when:((
|
||||||
|
default\:"use default engine"
|
||||||
|
pcre2\:"identical to --pcre2"
|
||||||
|
auto\:"identical to --auto-hybrid-regex"
|
||||||
|
))'
|
||||||
|
|
||||||
+ file # File-input options
|
+ file # File-input options
|
||||||
'(1)*'{-f+,--file=}'[specify file containing patterns to search for]: :_files'
|
'(1)*'{-f+,--file=}'[specify file containing patterns to search for]: :_files'
|
||||||
|
|
||||||
@@ -128,6 +136,10 @@ _rg() {
|
|||||||
'--ignore-file-case-insensitive[process ignore files case insensitively]'
|
'--ignore-file-case-insensitive[process ignore files case insensitively]'
|
||||||
$no'--no-ignore-file-case-insensitive[process ignore files case sensitively]'
|
$no'--no-ignore-file-case-insensitive[process ignore files case sensitively]'
|
||||||
|
|
||||||
|
+ '(ignore-exclude)' # Local exclude (ignore)-file options
|
||||||
|
"--no-ignore-exclude[don't respect local exclude (ignore) files]"
|
||||||
|
$no'--ignore-exclude[respect local exclude (ignore) files]'
|
||||||
|
|
||||||
+ '(ignore-global)' # Global ignore-file options
|
+ '(ignore-global)' # Global ignore-file options
|
||||||
"--no-ignore-global[don't respect global ignore files]"
|
"--no-ignore-global[don't respect global ignore files]"
|
||||||
$no'--ignore-global[respect global ignore files]'
|
$no'--ignore-global[respect global ignore files]'
|
||||||
@@ -140,10 +152,18 @@ _rg() {
|
|||||||
"--no-ignore-vcs[don't respect version control ignore files]"
|
"--no-ignore-vcs[don't respect version control ignore files]"
|
||||||
$no'--ignore-vcs[respect version control ignore files]'
|
$no'--ignore-vcs[respect version control ignore files]'
|
||||||
|
|
||||||
+ '(ignore-dot)' # .ignore-file options
|
+ '(require-git)' # git specific settings
|
||||||
|
"--no-require-git[don't require git repository to respect gitignore rules]"
|
||||||
|
$no'--require-git[require git repository to respect gitignore rules]'
|
||||||
|
|
||||||
|
+ '(ignore-dot)' # .ignore options
|
||||||
"--no-ignore-dot[don't respect .ignore files]"
|
"--no-ignore-dot[don't respect .ignore files]"
|
||||||
$no'--ignore-dot[respect .ignore files]'
|
$no'--ignore-dot[respect .ignore files]'
|
||||||
|
|
||||||
|
+ '(ignore-files)' # custom global ignore file options
|
||||||
|
"--no-ignore-files[don't respect --ignore-file flags]"
|
||||||
|
$no'--ignore-files[respect --ignore-file files]'
|
||||||
|
|
||||||
+ '(json)' # JSON options
|
+ '(json)' # JSON options
|
||||||
'--json[output results in JSON Lines format]'
|
'--json[output results in JSON Lines format]'
|
||||||
$no"--no-json[don't output results in JSON Lines format]"
|
$no"--no-json[don't output results in JSON Lines format]"
|
||||||
@@ -263,6 +283,10 @@ _rg() {
|
|||||||
{-w,--word-regexp}'[only show matches surrounded by word boundaries]'
|
{-w,--word-regexp}'[only show matches surrounded by word boundaries]'
|
||||||
{-x,--line-regexp}'[only show matches surrounded by line boundaries]'
|
{-x,--line-regexp}'[only show matches surrounded by line boundaries]'
|
||||||
|
|
||||||
|
+ '(unicode)' # Unicode options
|
||||||
|
$no'--unicode[enable Unicode mode]'
|
||||||
|
'--no-unicode[disable Unicode mode]'
|
||||||
|
|
||||||
+ '(zip)' # Compression options
|
+ '(zip)' # Compression options
|
||||||
'(--pre)'{-z,--search-zip}'[search in compressed files]'
|
'(--pre)'{-z,--search-zip}'[search in compressed files]'
|
||||||
$no"--no-search-zip[don't search in compressed files]"
|
$no"--no-search-zip[don't search in compressed files]"
|
||||||
@@ -277,7 +301,9 @@ _rg() {
|
|||||||
))'
|
))'
|
||||||
'*--colors=[specify color and style settings]: :->colorspec'
|
'*--colors=[specify color and style settings]: :->colorspec'
|
||||||
'--context-separator=[specify string used to separate non-continuous context lines in output]:separator'
|
'--context-separator=[specify string used to separate non-continuous context lines in output]:separator'
|
||||||
|
$no"--no-context-separator[don't print context separators]"
|
||||||
'--debug[show debug messages]'
|
'--debug[show debug messages]'
|
||||||
|
'--trace[show more verbose debug messages]'
|
||||||
'--dfa-size-limit=[specify upper size limit of generated DFA]:DFA size (bytes)'
|
'--dfa-size-limit=[specify upper size limit of generated DFA]:DFA size (bytes)'
|
||||||
"(1 stats)--files[show each file that would be searched (but don't search)]"
|
"(1 stats)--files[show each file that would be searched (but don't search)]"
|
||||||
'*--ignore-file=[specify additional ignore file]:ignore file:_files'
|
'*--ignore-file=[specify additional ignore file]:ignore file:_files'
|
||||||
@@ -297,7 +323,7 @@ _rg() {
|
|||||||
'(--type-list)*: :_files'
|
'(--type-list)*: :_files'
|
||||||
)
|
)
|
||||||
|
|
||||||
# This is used with test_complete.sh to verify that there are no options
|
# This is used with test-complete to verify that there are no options
|
||||||
# listed in the help output that aren't also defined here
|
# listed in the help output that aren't also defined here
|
||||||
[[ $_RG_COMPLETE_LIST_ARGS == (1|t*|y*) ]] && {
|
[[ $_RG_COMPLETE_LIST_ARGS == (1|t*|y*) ]] && {
|
||||||
print -rl - $args
|
print -rl - $args
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "grep-cli"
|
name = "grep-cli"
|
||||||
version = "0.1.3" #:version
|
version = "0.1.4" #:version
|
||||||
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
Utilities for search oriented command line applications.
|
Utilities for search oriented command line applications.
|
||||||
"""
|
"""
|
||||||
documentation = "https://docs.rs/grep-cli"
|
documentation = "https://docs.rs/grep-cli"
|
||||||
homepage = "https://github.com/BurntSushi/ripgrep"
|
homepage = "https://github.com/BurntSushi/ripgrep/tree/master/crates/cli"
|
||||||
repository = "https://github.com/BurntSushi/ripgrep"
|
repository = "https://github.com/BurntSushi/ripgrep/tree/master/crates/cli"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["regex", "grep", "cli", "utility", "util"]
|
keywords = ["regex", "grep", "cli", "utility", "util"]
|
||||||
license = "Unlicense/MIT"
|
license = "Unlicense/MIT"
|
@@ -38,10 +38,7 @@ impl Default for DecompressionMatcherBuilder {
|
|||||||
impl DecompressionMatcherBuilder {
|
impl DecompressionMatcherBuilder {
|
||||||
/// Create a new builder for configuring a decompression matcher.
|
/// Create a new builder for configuring a decompression matcher.
|
||||||
pub fn new() -> DecompressionMatcherBuilder {
|
pub fn new() -> DecompressionMatcherBuilder {
|
||||||
DecompressionMatcherBuilder {
|
DecompressionMatcherBuilder { commands: vec![], defaults: true }
|
||||||
commands: vec![],
|
|
||||||
defaults: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a matcher for determining how to decompress files.
|
/// Build a matcher for determining how to decompress files.
|
||||||
@@ -49,12 +46,11 @@ impl DecompressionMatcherBuilder {
|
|||||||
/// If there was a problem compiling the matcher, then an error is
|
/// If there was a problem compiling the matcher, then an error is
|
||||||
/// returned.
|
/// returned.
|
||||||
pub fn build(&self) -> Result<DecompressionMatcher, CommandError> {
|
pub fn build(&self) -> Result<DecompressionMatcher, CommandError> {
|
||||||
let defaults =
|
let defaults = if !self.defaults {
|
||||||
if !self.defaults {
|
vec![]
|
||||||
vec![]
|
} else {
|
||||||
} else {
|
default_decompression_commands()
|
||||||
default_decompression_commands()
|
};
|
||||||
};
|
|
||||||
let mut glob_builder = GlobSetBuilder::new();
|
let mut glob_builder = GlobSetBuilder::new();
|
||||||
let mut commands = vec![];
|
let mut commands = vec![];
|
||||||
for decomp_cmd in defaults.iter().chain(&self.commands) {
|
for decomp_cmd in defaults.iter().chain(&self.commands) {
|
||||||
@@ -93,17 +89,15 @@ impl DecompressionMatcherBuilder {
|
|||||||
program: P,
|
program: P,
|
||||||
args: I,
|
args: I,
|
||||||
) -> &mut DecompressionMatcherBuilder
|
) -> &mut DecompressionMatcherBuilder
|
||||||
where P: AsRef<OsStr>,
|
where
|
||||||
I: IntoIterator<Item=A>,
|
P: AsRef<OsStr>,
|
||||||
A: AsRef<OsStr>,
|
I: IntoIterator<Item = A>,
|
||||||
|
A: AsRef<OsStr>,
|
||||||
{
|
{
|
||||||
|
|
||||||
let glob = glob.to_string();
|
let glob = glob.to_string();
|
||||||
let bin = program.as_ref().to_os_string();
|
let bin = program.as_ref().to_os_string();
|
||||||
let args = args
|
let args =
|
||||||
.into_iter()
|
args.into_iter().map(|a| a.as_ref().to_os_string()).collect();
|
||||||
.map(|a| a.as_ref().to_os_string())
|
|
||||||
.collect();
|
|
||||||
self.commands.push(DecompressionCommand { glob, bin, args });
|
self.commands.push(DecompressionCommand { glob, bin, args });
|
||||||
self
|
self
|
||||||
}
|
}
|
@@ -95,51 +95,61 @@ pub fn unescape(s: &str) -> Vec<u8> {
|
|||||||
let mut state = Literal;
|
let mut state = Literal;
|
||||||
for c in s.chars() {
|
for c in s.chars() {
|
||||||
match state {
|
match state {
|
||||||
Escape => {
|
Escape => match c {
|
||||||
match c {
|
'\\' => {
|
||||||
'\\' => { bytes.push(b'\\'); state = Literal; }
|
bytes.push(b'\\');
|
||||||
'n' => { bytes.push(b'\n'); state = Literal; }
|
state = Literal;
|
||||||
'r' => { bytes.push(b'\r'); state = Literal; }
|
|
||||||
't' => { bytes.push(b'\t'); state = Literal; }
|
|
||||||
'x' => { state = HexFirst; }
|
|
||||||
c => {
|
|
||||||
bytes.extend(format!(r"\{}", c).into_bytes());
|
|
||||||
state = Literal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
'n' => {
|
||||||
HexFirst => {
|
bytes.push(b'\n');
|
||||||
match c {
|
state = Literal;
|
||||||
'0'..='9' | 'A'..='F' | 'a'..='f' => {
|
|
||||||
state = HexSecond(c);
|
|
||||||
}
|
|
||||||
c => {
|
|
||||||
bytes.extend(format!(r"\x{}", c).into_bytes());
|
|
||||||
state = Literal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
'r' => {
|
||||||
HexSecond(first) => {
|
bytes.push(b'\r');
|
||||||
match c {
|
state = Literal;
|
||||||
'0'..='9' | 'A'..='F' | 'a'..='f' => {
|
|
||||||
let ordinal = format!("{}{}", first, c);
|
|
||||||
let byte = u8::from_str_radix(&ordinal, 16).unwrap();
|
|
||||||
bytes.push(byte);
|
|
||||||
state = Literal;
|
|
||||||
}
|
|
||||||
c => {
|
|
||||||
let original = format!(r"\x{}{}", first, c);
|
|
||||||
bytes.extend(original.into_bytes());
|
|
||||||
state = Literal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
't' => {
|
||||||
Literal => {
|
bytes.push(b'\t');
|
||||||
match c {
|
state = Literal;
|
||||||
'\\' => { state = Escape; }
|
|
||||||
c => { bytes.extend(c.to_string().as_bytes()); }
|
|
||||||
}
|
}
|
||||||
}
|
'x' => {
|
||||||
|
state = HexFirst;
|
||||||
|
}
|
||||||
|
c => {
|
||||||
|
bytes.extend(format!(r"\{}", c).into_bytes());
|
||||||
|
state = Literal;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
HexFirst => match c {
|
||||||
|
'0'..='9' | 'A'..='F' | 'a'..='f' => {
|
||||||
|
state = HexSecond(c);
|
||||||
|
}
|
||||||
|
c => {
|
||||||
|
bytes.extend(format!(r"\x{}", c).into_bytes());
|
||||||
|
state = Literal;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
HexSecond(first) => match c {
|
||||||
|
'0'..='9' | 'A'..='F' | 'a'..='f' => {
|
||||||
|
let ordinal = format!("{}{}", first, c);
|
||||||
|
let byte = u8::from_str_radix(&ordinal, 16).unwrap();
|
||||||
|
bytes.push(byte);
|
||||||
|
state = Literal;
|
||||||
|
}
|
||||||
|
c => {
|
||||||
|
let original = format!(r"\x{}{}", first, c);
|
||||||
|
bytes.extend(original.into_bytes());
|
||||||
|
state = Literal;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Literal => match c {
|
||||||
|
'\\' => {
|
||||||
|
state = Escape;
|
||||||
|
}
|
||||||
|
c => {
|
||||||
|
bytes.extend(c.to_string().as_bytes());
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match state {
|
match state {
|
@@ -46,7 +46,9 @@ impl ParseSizeError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for ParseSizeError {
|
impl error::Error for ParseSizeError {
|
||||||
fn description(&self) -> &str { "invalid size" }
|
fn description(&self) -> &str {
|
||||||
|
"invalid size"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ParseSizeError {
|
impl fmt::Display for ParseSizeError {
|
||||||
@@ -54,26 +56,19 @@ impl fmt::Display for ParseSizeError {
|
|||||||
use self::ParseSizeErrorKind::*;
|
use self::ParseSizeErrorKind::*;
|
||||||
|
|
||||||
match self.kind {
|
match self.kind {
|
||||||
InvalidFormat => {
|
InvalidFormat => write!(
|
||||||
write!(
|
f,
|
||||||
f,
|
"invalid format for size '{}', which should be a sequence \
|
||||||
"invalid format for size '{}', which should be a sequence \
|
|
||||||
of digits followed by an optional 'K', 'M' or 'G' \
|
of digits followed by an optional 'K', 'M' or 'G' \
|
||||||
suffix",
|
suffix",
|
||||||
self.original
|
self.original
|
||||||
)
|
),
|
||||||
}
|
InvalidInt(ref err) => write!(
|
||||||
InvalidInt(ref err) => {
|
f,
|
||||||
write!(
|
"invalid integer found in size '{}': {}",
|
||||||
f,
|
self.original, err
|
||||||
"invalid integer found in size '{}': {}",
|
),
|
||||||
self.original,
|
Overflow => write!(f, "size too big in '{}'", self.original),
|
||||||
err
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Overflow => {
|
|
||||||
write!(f, "size too big in '{}'", self.original)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,17 +99,16 @@ pub fn parse_human_readable_size(size: &str) -> Result<u64, ParseSizeError> {
|
|||||||
Some(caps) => caps,
|
Some(caps) => caps,
|
||||||
None => return Err(ParseSizeError::format(size)),
|
None => return Err(ParseSizeError::format(size)),
|
||||||
};
|
};
|
||||||
let value: u64 = caps[1].parse().map_err(|err| {
|
let value: u64 =
|
||||||
ParseSizeError::int(size, err)
|
caps[1].parse().map_err(|err| ParseSizeError::int(size, err))?;
|
||||||
})?;
|
|
||||||
let suffix = match caps.get(2) {
|
let suffix = match caps.get(2) {
|
||||||
None => return Ok(value),
|
None => return Ok(value),
|
||||||
Some(cap) => cap.as_str(),
|
Some(cap) => cap.as_str(),
|
||||||
};
|
};
|
||||||
let bytes = match suffix {
|
let bytes = match suffix {
|
||||||
"K" => value.checked_mul(1<<10),
|
"K" => value.checked_mul(1 << 10),
|
||||||
"M" => value.checked_mul(1<<20),
|
"M" => value.checked_mul(1 << 20),
|
||||||
"G" => value.checked_mul(1<<30),
|
"G" => value.checked_mul(1 << 30),
|
||||||
// Because if the regex matches this group, it must be [KMG].
|
// Because if the regex matches this group, it must be [KMG].
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
@@ -134,19 +128,19 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn suffix_k() {
|
fn suffix_k() {
|
||||||
let x = parse_human_readable_size("123K").unwrap();
|
let x = parse_human_readable_size("123K").unwrap();
|
||||||
assert_eq!(123 * (1<<10), x);
|
assert_eq!(123 * (1 << 10), x);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn suffix_m() {
|
fn suffix_m() {
|
||||||
let x = parse_human_readable_size("123M").unwrap();
|
let x = parse_human_readable_size("123M").unwrap();
|
||||||
assert_eq!(123 * (1<<20), x);
|
assert_eq!(123 * (1 << 20), x);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn suffix_g() {
|
fn suffix_g() {
|
||||||
let x = parse_human_readable_size("123G").unwrap();
|
let x = parse_human_readable_size("123G").unwrap();
|
||||||
assert_eq!(123 * (1<<30), x);
|
assert_eq!(123 * (1 << 30), x);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
@@ -179,20 +179,18 @@ mod process;
|
|||||||
mod wtr;
|
mod wtr;
|
||||||
|
|
||||||
pub use decompress::{
|
pub use decompress::{
|
||||||
DecompressionMatcher, DecompressionMatcherBuilder,
|
DecompressionMatcher, DecompressionMatcherBuilder, DecompressionReader,
|
||||||
DecompressionReader, DecompressionReaderBuilder,
|
DecompressionReaderBuilder,
|
||||||
};
|
};
|
||||||
pub use escape::{escape, escape_os, unescape, unescape_os};
|
pub use escape::{escape, escape_os, unescape, unescape_os};
|
||||||
pub use human::{ParseSizeError, parse_human_readable_size};
|
pub use human::{parse_human_readable_size, ParseSizeError};
|
||||||
pub use pattern::{
|
pub use pattern::{
|
||||||
InvalidPatternError,
|
pattern_from_bytes, pattern_from_os, patterns_from_path,
|
||||||
pattern_from_os, pattern_from_bytes,
|
patterns_from_reader, patterns_from_stdin, InvalidPatternError,
|
||||||
patterns_from_path, patterns_from_reader, patterns_from_stdin,
|
|
||||||
};
|
};
|
||||||
pub use process::{CommandError, CommandReader, CommandReaderBuilder};
|
pub use process::{CommandError, CommandReader, CommandReaderBuilder};
|
||||||
pub use wtr::{
|
pub use wtr::{
|
||||||
StandardStream,
|
stdout, stdout_buffered_block, stdout_buffered_line, StandardStream,
|
||||||
stdout, stdout_buffered_line, stdout_buffered_block,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Returns true if and only if stdin is believed to be readable.
|
/// Returns true if and only if stdin is believed to be readable.
|
||||||
@@ -205,8 +203,8 @@ pub use wtr::{
|
|||||||
pub fn is_readable_stdin() -> bool {
|
pub fn is_readable_stdin() -> bool {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn imp() -> bool {
|
fn imp() -> bool {
|
||||||
use std::os::unix::fs::FileTypeExt;
|
|
||||||
use same_file::Handle;
|
use same_file::Handle;
|
||||||
|
use std::os::unix::fs::FileTypeExt;
|
||||||
|
|
||||||
let ft = match Handle::stdin().and_then(|h| h.as_file().metadata()) {
|
let ft = match Handle::stdin().and_then(|h| h.as_file().metadata()) {
|
||||||
Err(_) => return false,
|
Err(_) => return false,
|
@@ -29,7 +29,9 @@ impl InvalidPatternError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for InvalidPatternError {
|
impl error::Error for InvalidPatternError {
|
||||||
fn description(&self) -> &str { "invalid pattern" }
|
fn description(&self) -> &str {
|
||||||
|
"invalid pattern"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for InvalidPatternError {
|
impl fmt::Display for InvalidPatternError {
|
||||||
@@ -39,8 +41,7 @@ impl fmt::Display for InvalidPatternError {
|
|||||||
"found invalid UTF-8 in pattern at byte offset {} \
|
"found invalid UTF-8 in pattern at byte offset {} \
|
||||||
(use hex escape sequences to match arbitrary bytes \
|
(use hex escape sequences to match arbitrary bytes \
|
||||||
in a pattern, e.g., \\xFF): '{}'",
|
in a pattern, e.g., \\xFF): '{}'",
|
||||||
self.valid_up_to,
|
self.valid_up_to, self.original,
|
||||||
self.original,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,11 +80,9 @@ pub fn pattern_from_os(pattern: &OsStr) -> Result<&str, InvalidPatternError> {
|
|||||||
pub fn pattern_from_bytes(
|
pub fn pattern_from_bytes(
|
||||||
pattern: &[u8],
|
pattern: &[u8],
|
||||||
) -> Result<&str, InvalidPatternError> {
|
) -> Result<&str, InvalidPatternError> {
|
||||||
str::from_utf8(pattern).map_err(|err| {
|
str::from_utf8(pattern).map_err(|err| InvalidPatternError {
|
||||||
InvalidPatternError {
|
original: escape(pattern),
|
||||||
original: escape(pattern),
|
valid_up_to: err.valid_up_to(),
|
||||||
valid_up_to: err.valid_up_to(),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,10 +118,7 @@ pub fn patterns_from_stdin() -> io::Result<Vec<String>> {
|
|||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
let locked = stdin.lock();
|
let locked = stdin.lock();
|
||||||
patterns_from_reader(locked).map_err(|err| {
|
patterns_from_reader(locked).map_err(|err| {
|
||||||
io::Error::new(
|
io::Error::new(io::ErrorKind::Other, format!("<stdin>:{}", err))
|
||||||
io::ErrorKind::Other,
|
|
||||||
format!("<stdin>:{}", err),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,12 +162,10 @@ pub fn patterns_from_reader<R: io::Read>(rdr: R) -> io::Result<Vec<String>> {
|
|||||||
patterns.push(pattern.to_string());
|
patterns.push(pattern.to_string());
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => Err(io::Error::new(
|
||||||
Err(io::Error::new(
|
io::ErrorKind::Other,
|
||||||
io::ErrorKind::Other,
|
format!("{}: {}", line_number, err),
|
||||||
format!("{}: {}", line_number, err),
|
)),
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
Ok(patterns)
|
Ok(patterns)
|
||||||
@@ -191,8 +185,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn os() {
|
fn os() {
|
||||||
use std::os::unix::ffi::OsStrExt;
|
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
|
||||||
let pat = OsStr::from_bytes(b"abc\xFFxyz");
|
let pat = OsStr::from_bytes(b"abc\xFFxyz");
|
||||||
let err = pattern_from_os(pat).unwrap_err();
|
let err = pattern_from_os(pat).unwrap_err();
|
@@ -33,7 +33,9 @@ impl CommandError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for CommandError {
|
impl error::Error for CommandError {
|
||||||
fn description(&self) -> &str { "command error" }
|
fn description(&self) -> &str {
|
||||||
|
"command error"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for CommandError {
|
impl fmt::Display for CommandError {
|
||||||
@@ -46,7 +48,12 @@ impl fmt::Display for CommandError {
|
|||||||
write!(f, "<stderr is empty>")
|
write!(f, "<stderr is empty>")
|
||||||
} else {
|
} else {
|
||||||
let div = iter::repeat('-').take(79).collect::<String>();
|
let div = iter::repeat('-').take(79).collect::<String>();
|
||||||
write!(f, "\n{div}\n{msg}\n{div}", div=div, msg=msg.trim())
|
write!(
|
||||||
|
f,
|
||||||
|
"\n{div}\n{msg}\n{div}",
|
||||||
|
div = div,
|
||||||
|
msg = msg.trim()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,12 +108,11 @@ impl CommandReaderBuilder {
|
|||||||
.stderr(process::Stdio::piped())
|
.stderr(process::Stdio::piped())
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
let stdout = child.stdout.take().unwrap();
|
let stdout = child.stdout.take().unwrap();
|
||||||
let stderr =
|
let stderr = if self.async_stderr {
|
||||||
if self.async_stderr {
|
StderrReader::async(child.stderr.take().unwrap())
|
||||||
StderrReader::async(child.stderr.take().unwrap())
|
} else {
|
||||||
} else {
|
StderrReader::sync(child.stderr.take().unwrap())
|
||||||
StderrReader::sync(child.stderr.take().unwrap())
|
};
|
||||||
};
|
|
||||||
Ok(CommandReader {
|
Ok(CommandReader {
|
||||||
child: child,
|
child: child,
|
||||||
stdout: stdout,
|
stdout: stdout,
|
||||||
@@ -226,9 +232,8 @@ enum StderrReader {
|
|||||||
impl StderrReader {
|
impl StderrReader {
|
||||||
/// Create a reader for stderr that reads contents asynchronously.
|
/// Create a reader for stderr that reads contents asynchronously.
|
||||||
fn async(mut stderr: process::ChildStderr) -> StderrReader {
|
fn async(mut stderr: process::ChildStderr) -> StderrReader {
|
||||||
let handle = thread::spawn(move || {
|
let handle =
|
||||||
stderr_to_command_error(&mut stderr)
|
thread::spawn(move || stderr_to_command_error(&mut stderr));
|
||||||
});
|
|
||||||
StderrReader::Async(Some(handle))
|
StderrReader::Async(Some(handle))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,9 +252,7 @@ impl StderrReader {
|
|||||||
let handle = handle
|
let handle = handle
|
||||||
.take()
|
.take()
|
||||||
.expect("read_to_end cannot be called more than once");
|
.expect("read_to_end cannot be called more than once");
|
||||||
handle
|
handle.join().expect("stderr reading thread does not panic")
|
||||||
.join()
|
|
||||||
.expect("stderr reading thread does not panic")
|
|
||||||
}
|
}
|
||||||
StderrReader::Sync(ref mut stderr) => {
|
StderrReader::Sync(ref mut stderr) => {
|
||||||
stderr_to_command_error(stderr)
|
stderr_to_command_error(stderr)
|
15
crates/core/README.md
Normal file
15
crates/core/README.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
ripgrep core
|
||||||
|
------------
|
||||||
|
This is the core ripgrep crate. In particular, `main.rs` is where the `main`
|
||||||
|
function lives.
|
||||||
|
|
||||||
|
Most of ripgrep core consists of two things:
|
||||||
|
|
||||||
|
* The definition of the CLI interface, including docs for every flag.
|
||||||
|
* Glue code that brings the `grep-matcher`, `grep-regex`, `grep-searcher` and
|
||||||
|
`grep-printer` crates together to actually execute the search.
|
||||||
|
|
||||||
|
Currently, there are no plans to make ripgrep core available as an independent
|
||||||
|
library. However, much of the heavy lifting of ripgrep is done via its
|
||||||
|
constituent crates, which can be reused independent of ripgrep. Unfortunately,
|
||||||
|
there is no guide or tutorial to teach folks how to do this yet.
|
File diff suppressed because it is too large
Load Diff
@@ -17,11 +17,8 @@ use grep::pcre2::{
|
|||||||
RegexMatcherBuilder as PCRE2RegexMatcherBuilder,
|
RegexMatcherBuilder as PCRE2RegexMatcherBuilder,
|
||||||
};
|
};
|
||||||
use grep::printer::{
|
use grep::printer::{
|
||||||
ColorSpecs, Stats,
|
default_color_specs, ColorSpecs, JSONBuilder, Standard, StandardBuilder,
|
||||||
JSON, JSONBuilder,
|
Stats, Summary, SummaryBuilder, SummaryKind, JSON,
|
||||||
Standard, StandardBuilder,
|
|
||||||
Summary, SummaryBuilder, SummaryKind,
|
|
||||||
default_color_specs,
|
|
||||||
};
|
};
|
||||||
use grep::regex::{
|
use grep::regex::{
|
||||||
RegexMatcher as RustRegexMatcher,
|
RegexMatcher as RustRegexMatcher,
|
||||||
@@ -36,15 +33,12 @@ use ignore::{Walk, WalkBuilder, WalkParallel};
|
|||||||
use log;
|
use log;
|
||||||
use num_cpus;
|
use num_cpus;
|
||||||
use regex;
|
use regex;
|
||||||
use termcolor::{
|
use termcolor::{BufferWriter, ColorChoice, WriteColor};
|
||||||
WriteColor,
|
|
||||||
BufferWriter, ColorChoice,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::app;
|
use crate::app;
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::logger::Logger;
|
use crate::logger::Logger;
|
||||||
use crate::messages::{set_messages, set_ignore_messages};
|
use crate::messages::{set_ignore_messages, set_messages};
|
||||||
use crate::path_printer::{PathPrinter, PathPrinterBuilder};
|
use crate::path_printer::{PathPrinter, PathPrinterBuilder};
|
||||||
use crate::search::{
|
use crate::search::{
|
||||||
PatternMatcher, Printer, SearchWorker, SearchWorkerBuilder,
|
PatternMatcher, Printer, SearchWorker, SearchWorkerBuilder,
|
||||||
@@ -84,11 +78,9 @@ impl Command {
|
|||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Search | SearchParallel => true,
|
Search | SearchParallel => true,
|
||||||
| SearchNever
|
SearchNever | Files | FilesParallel | Types | PCRE2Version => {
|
||||||
| Files
|
false
|
||||||
| FilesParallel
|
}
|
||||||
| Types
|
|
||||||
| PCRE2Version => false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,15 +202,12 @@ impl Args {
|
|||||||
.printer_standard(self.paths(), wtr, separator_search)
|
.printer_standard(self.paths(), wtr, separator_search)
|
||||||
.map(Printer::Standard)
|
.map(Printer::Standard)
|
||||||
}
|
}
|
||||||
OutputKind::Summary => {
|
OutputKind::Summary => self
|
||||||
self.matches()
|
.matches()
|
||||||
.printer_summary(self.paths(), wtr)
|
.printer_summary(self.paths(), wtr)
|
||||||
.map(Printer::Summary)
|
.map(Printer::Summary),
|
||||||
}
|
|
||||||
OutputKind::JSON => {
|
OutputKind::JSON => {
|
||||||
self.matches()
|
self.matches().printer_json(wtr).map(Printer::JSON)
|
||||||
.printer_json(wtr)
|
|
||||||
.map(Printer::JSON)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,11 +394,11 @@ enum SortByKind {
|
|||||||
|
|
||||||
impl SortBy {
|
impl SortBy {
|
||||||
fn asc(kind: SortByKind) -> SortBy {
|
fn asc(kind: SortByKind) -> SortBy {
|
||||||
SortBy { reverse: false, kind: kind }
|
SortBy { reverse: false, kind }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn desc(kind: SortByKind) -> SortBy {
|
fn desc(kind: SortByKind) -> SortBy {
|
||||||
SortBy { reverse: true, kind: kind }
|
SortBy { reverse: true, kind }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn none() -> SortBy {
|
fn none() -> SortBy {
|
||||||
@@ -452,29 +441,23 @@ impl SortBy {
|
|||||||
}
|
}
|
||||||
SortByKind::LastModified => {
|
SortByKind::LastModified => {
|
||||||
builder.sort_by_file_path(move |a, b| {
|
builder.sort_by_file_path(move |a, b| {
|
||||||
sort_by_metadata_time(
|
sort_by_metadata_time(a, b, self.reverse, |md| {
|
||||||
a, b,
|
md.modified()
|
||||||
self.reverse,
|
})
|
||||||
|md| md.modified(),
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
SortByKind::LastAccessed => {
|
SortByKind::LastAccessed => {
|
||||||
builder.sort_by_file_path(move |a, b| {
|
builder.sort_by_file_path(move |a, b| {
|
||||||
sort_by_metadata_time(
|
sort_by_metadata_time(a, b, self.reverse, |md| {
|
||||||
a, b,
|
md.accessed()
|
||||||
self.reverse,
|
})
|
||||||
|md| md.accessed(),
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
SortByKind::Created => {
|
SortByKind::Created => {
|
||||||
builder.sort_by_file_path(move |a, b| {
|
builder.sort_by_file_path(move |a, b| {
|
||||||
sort_by_metadata_time(
|
sort_by_metadata_time(a, b, self.reverse, |md| {
|
||||||
a, b,
|
md.created()
|
||||||
self.reverse,
|
})
|
||||||
|md| md.created(),
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -520,7 +503,7 @@ impl EncodingMode {
|
|||||||
fn has_explicit_encoding(&self) -> bool {
|
fn has_explicit_encoding(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
EncodingMode::Some(_) => true,
|
EncodingMode::Some(_) => true,
|
||||||
_ => false
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -568,19 +551,18 @@ impl ArgMatches {
|
|||||||
let patterns = self.patterns()?;
|
let patterns = self.patterns()?;
|
||||||
let matcher = self.matcher(&patterns)?;
|
let matcher = self.matcher(&patterns)?;
|
||||||
let mut paths = self.paths();
|
let mut paths = self.paths();
|
||||||
let using_default_path =
|
let using_default_path = if paths.is_empty() {
|
||||||
if paths.is_empty() {
|
paths.push(self.path_default());
|
||||||
paths.push(self.path_default());
|
true
|
||||||
true
|
} else {
|
||||||
} else {
|
false
|
||||||
false
|
};
|
||||||
};
|
|
||||||
Ok(Args(Arc::new(ArgsImp {
|
Ok(Args(Arc::new(ArgsImp {
|
||||||
matches: self,
|
matches: self,
|
||||||
patterns: patterns,
|
patterns,
|
||||||
matcher: matcher,
|
matcher,
|
||||||
paths: paths,
|
paths,
|
||||||
using_default_path: using_default_path,
|
using_default_path,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -594,54 +576,78 @@ impl ArgMatches {
|
|||||||
///
|
///
|
||||||
/// If there was a problem building the matcher (e.g., a syntax error),
|
/// If there was a problem building the matcher (e.g., a syntax error),
|
||||||
/// then this returns an error.
|
/// then this returns an error.
|
||||||
#[cfg(feature = "pcre2")]
|
|
||||||
fn matcher(&self, patterns: &[String]) -> Result<PatternMatcher> {
|
fn matcher(&self, patterns: &[String]) -> Result<PatternMatcher> {
|
||||||
if self.is_present("pcre2") {
|
if self.is_present("pcre2") {
|
||||||
let matcher = self.matcher_pcre2(patterns)?;
|
self.matcher_engine("pcre2", patterns)
|
||||||
Ok(PatternMatcher::PCRE2(matcher))
|
|
||||||
} else if self.is_present("auto-hybrid-regex") {
|
} else if self.is_present("auto-hybrid-regex") {
|
||||||
let rust_err = match self.matcher_rust(patterns) {
|
self.matcher_engine("auto", patterns)
|
||||||
Ok(matcher) => return Ok(PatternMatcher::RustRegex(matcher)),
|
|
||||||
Err(err) => err,
|
|
||||||
};
|
|
||||||
log::debug!(
|
|
||||||
"error building Rust regex in hybrid mode:\n{}", rust_err,
|
|
||||||
);
|
|
||||||
let pcre_err = match self.matcher_pcre2(patterns) {
|
|
||||||
Ok(matcher) => return Ok(PatternMatcher::PCRE2(matcher)),
|
|
||||||
Err(err) => err,
|
|
||||||
};
|
|
||||||
Err(From::from(format!(
|
|
||||||
"regex could not be compiled with either the default regex \
|
|
||||||
engine or with PCRE2.\n\n\
|
|
||||||
default regex engine error:\n{}\n{}\n{}\n\n\
|
|
||||||
PCRE2 regex engine error:\n{}",
|
|
||||||
"~".repeat(79), rust_err, "~".repeat(79), pcre_err,
|
|
||||||
)))
|
|
||||||
} else {
|
} else {
|
||||||
let matcher = match self.matcher_rust(patterns) {
|
let engine = self.value_of_lossy("engine").unwrap();
|
||||||
Ok(matcher) => matcher,
|
self.matcher_engine(&engine, patterns)
|
||||||
Err(err) => {
|
|
||||||
return Err(From::from(suggest_pcre2(err.to_string())));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(PatternMatcher::RustRegex(matcher))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the matcher that should be used for searching.
|
/// Return the matcher that should be used for searching using engine
|
||||||
|
/// as the engine for the patterns.
|
||||||
///
|
///
|
||||||
/// If there was a problem building the matcher (e.g., a syntax error),
|
/// If there was a problem building the matcher (e.g., a syntax error),
|
||||||
/// then this returns an error.
|
/// then this returns an error.
|
||||||
#[cfg(not(feature = "pcre2"))]
|
fn matcher_engine(
|
||||||
fn matcher(&self, patterns: &[String]) -> Result<PatternMatcher> {
|
&self,
|
||||||
if self.is_present("pcre2") {
|
engine: &str,
|
||||||
return Err(From::from(
|
patterns: &[String],
|
||||||
|
) -> Result<PatternMatcher> {
|
||||||
|
match engine {
|
||||||
|
"default" => {
|
||||||
|
let matcher = match self.matcher_rust(patterns) {
|
||||||
|
Ok(matcher) => matcher,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(From::from(suggest(err.to_string())));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(PatternMatcher::RustRegex(matcher))
|
||||||
|
}
|
||||||
|
#[cfg(feature = "pcre2")]
|
||||||
|
"pcre2" => {
|
||||||
|
let matcher = self.matcher_pcre2(patterns)?;
|
||||||
|
Ok(PatternMatcher::PCRE2(matcher))
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "pcre2"))]
|
||||||
|
"pcre2" => Err(From::from(
|
||||||
"PCRE2 is not available in this build of ripgrep",
|
"PCRE2 is not available in this build of ripgrep",
|
||||||
));
|
)),
|
||||||
|
"auto" => {
|
||||||
|
let rust_err = match self.matcher_rust(patterns) {
|
||||||
|
Ok(matcher) => {
|
||||||
|
return Ok(PatternMatcher::RustRegex(matcher));
|
||||||
|
}
|
||||||
|
Err(err) => err,
|
||||||
|
};
|
||||||
|
log::debug!(
|
||||||
|
"error building Rust regex in hybrid mode:\n{}",
|
||||||
|
rust_err,
|
||||||
|
);
|
||||||
|
|
||||||
|
let pcre_err = match self.matcher_engine("pcre2", patterns) {
|
||||||
|
Ok(matcher) => return Ok(matcher),
|
||||||
|
Err(err) => err,
|
||||||
|
};
|
||||||
|
Err(From::from(format!(
|
||||||
|
"regex could not be compiled with either the default \
|
||||||
|
regex engine or with PCRE2.\n\n\
|
||||||
|
default regex engine error:\n{}\n{}\n{}\n\n\
|
||||||
|
PCRE2 regex engine error:\n{}",
|
||||||
|
"~".repeat(79),
|
||||||
|
rust_err,
|
||||||
|
"~".repeat(79),
|
||||||
|
pcre_err,
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
_ => Err(From::from(format!(
|
||||||
|
"unrecognized regex engine '{}'",
|
||||||
|
engine
|
||||||
|
))),
|
||||||
}
|
}
|
||||||
let matcher = self.matcher_rust(patterns)?;
|
|
||||||
Ok(PatternMatcher::RustRegex(matcher))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a matcher using Rust's regex engine.
|
/// Build a matcher using Rust's regex engine.
|
||||||
@@ -654,20 +660,16 @@ impl ArgMatches {
|
|||||||
.case_smart(self.case_smart())
|
.case_smart(self.case_smart())
|
||||||
.case_insensitive(self.case_insensitive())
|
.case_insensitive(self.case_insensitive())
|
||||||
.multi_line(true)
|
.multi_line(true)
|
||||||
.unicode(true)
|
.unicode(self.unicode())
|
||||||
.octal(false)
|
.octal(false)
|
||||||
.word(self.is_present("word-regexp"));
|
.word(self.is_present("word-regexp"));
|
||||||
if self.is_present("multiline") {
|
if self.is_present("multiline") {
|
||||||
builder.dot_matches_new_line(self.is_present("multiline-dotall"));
|
builder.dot_matches_new_line(self.is_present("multiline-dotall"));
|
||||||
if self.is_present("crlf") {
|
if self.is_present("crlf") {
|
||||||
builder
|
builder.crlf(true).line_terminator(None);
|
||||||
.crlf(true)
|
|
||||||
.line_terminator(None);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
builder
|
builder.line_terminator(Some(b'\n')).dot_matches_new_line(false);
|
||||||
.line_terminator(Some(b'\n'))
|
|
||||||
.dot_matches_new_line(false);
|
|
||||||
if self.is_present("crlf") {
|
if self.is_present("crlf") {
|
||||||
builder.crlf(true);
|
builder.crlf(true);
|
||||||
}
|
}
|
||||||
@@ -686,12 +688,11 @@ impl ArgMatches {
|
|||||||
if let Some(limit) = self.dfa_size_limit()? {
|
if let Some(limit) = self.dfa_size_limit()? {
|
||||||
builder.dfa_size_limit(limit);
|
builder.dfa_size_limit(limit);
|
||||||
}
|
}
|
||||||
let res =
|
let res = if self.is_present("fixed-strings") {
|
||||||
if self.is_present("fixed-strings") {
|
builder.build_literals(patterns)
|
||||||
builder.build_literals(patterns)
|
} else {
|
||||||
} else {
|
builder.build(&patterns.join("|"))
|
||||||
builder.build(&patterns.join("|"))
|
};
|
||||||
};
|
|
||||||
match res {
|
match res {
|
||||||
Ok(m) => Ok(m),
|
Ok(m) => Ok(m),
|
||||||
Err(err) => Err(From::from(suggest_multiline(err.to_string()))),
|
Err(err) => Err(From::from(suggest_multiline(err.to_string()))),
|
||||||
@@ -718,9 +719,9 @@ impl ArgMatches {
|
|||||||
// The PCRE2 docs say that 32KB is the default, and that 1MB
|
// The PCRE2 docs say that 32KB is the default, and that 1MB
|
||||||
// should be big enough for anything. But let's crank it to
|
// should be big enough for anything. But let's crank it to
|
||||||
// 10MB.
|
// 10MB.
|
||||||
.max_jit_stack_size(Some(10 * (1<<20)));
|
.max_jit_stack_size(Some(10 * (1 << 20)));
|
||||||
}
|
}
|
||||||
if self.pcre2_unicode() {
|
if self.unicode() {
|
||||||
builder.utf(true).ucp(true);
|
builder.utf(true).ucp(true);
|
||||||
if self.encoding()?.has_explicit_encoding() {
|
if self.encoding()?.has_explicit_encoding() {
|
||||||
// SAFETY: If an encoding was specified, then we're guaranteed
|
// SAFETY: If an encoding was specified, then we're guaranteed
|
||||||
@@ -784,7 +785,7 @@ impl ArgMatches {
|
|||||||
.byte_offset(self.is_present("byte-offset"))
|
.byte_offset(self.is_present("byte-offset"))
|
||||||
.trim_ascii(self.is_present("trim"))
|
.trim_ascii(self.is_present("trim"))
|
||||||
.separator_search(None)
|
.separator_search(None)
|
||||||
.separator_context(Some(self.context_separator()))
|
.separator_context(self.context_separator())
|
||||||
.separator_field_match(b":".to_vec())
|
.separator_field_match(b":".to_vec())
|
||||||
.separator_field_context(b"-".to_vec())
|
.separator_field_context(b"-".to_vec())
|
||||||
.separator_path(self.path_separator()?)
|
.separator_path(self.path_separator()?)
|
||||||
@@ -812,6 +813,7 @@ impl ArgMatches {
|
|||||||
.stats(self.stats())
|
.stats(self.stats())
|
||||||
.path(self.with_filename(paths))
|
.path(self.with_filename(paths))
|
||||||
.max_matches(self.max_count()?)
|
.max_matches(self.max_count()?)
|
||||||
|
.exclude_zero(!self.is_present("include-zero"))
|
||||||
.separator_field(b":".to_vec())
|
.separator_field(b":".to_vec())
|
||||||
.separator_path(self.path_separator()?)
|
.separator_path(self.path_separator()?)
|
||||||
.path_terminator(self.path_terminator());
|
.path_terminator(self.path_terminator());
|
||||||
@@ -821,14 +823,13 @@ impl ArgMatches {
|
|||||||
/// Build a searcher from the command line parameters.
|
/// Build a searcher from the command line parameters.
|
||||||
fn searcher(&self, paths: &[PathBuf]) -> Result<Searcher> {
|
fn searcher(&self, paths: &[PathBuf]) -> Result<Searcher> {
|
||||||
let (ctx_before, ctx_after) = self.contexts()?;
|
let (ctx_before, ctx_after) = self.contexts()?;
|
||||||
let line_term =
|
let line_term = if self.is_present("crlf") {
|
||||||
if self.is_present("crlf") {
|
LineTerminator::crlf()
|
||||||
LineTerminator::crlf()
|
} else if self.is_present("null-data") {
|
||||||
} else if self.is_present("null-data") {
|
LineTerminator::byte(b'\x00')
|
||||||
LineTerminator::byte(b'\x00')
|
} else {
|
||||||
} else {
|
LineTerminator::byte(b'\n')
|
||||||
LineTerminator::byte(b'\n')
|
};
|
||||||
};
|
|
||||||
let mut builder = SearcherBuilder::new();
|
let mut builder = SearcherBuilder::new();
|
||||||
builder
|
builder
|
||||||
.line_terminator(line_term)
|
.line_terminator(line_term)
|
||||||
@@ -861,9 +862,11 @@ impl ArgMatches {
|
|||||||
for path in &paths[1..] {
|
for path in &paths[1..] {
|
||||||
builder.add(path);
|
builder.add(path);
|
||||||
}
|
}
|
||||||
for path in self.ignore_paths() {
|
if !self.no_ignore_files() {
|
||||||
if let Some(err) = builder.add_ignore(path) {
|
for path in self.ignore_paths() {
|
||||||
ignore_message!("{}", err);
|
if let Some(err) = builder.add_ignore(path) {
|
||||||
|
ignore_message!("{}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder
|
builder
|
||||||
@@ -880,7 +883,8 @@ impl ArgMatches {
|
|||||||
.ignore(!self.no_ignore_dot())
|
.ignore(!self.no_ignore_dot())
|
||||||
.git_global(!self.no_ignore_vcs() && !self.no_ignore_global())
|
.git_global(!self.no_ignore_vcs() && !self.no_ignore_global())
|
||||||
.git_ignore(!self.no_ignore_vcs())
|
.git_ignore(!self.no_ignore_vcs())
|
||||||
.git_exclude(!self.no_ignore_vcs())
|
.git_exclude(!self.no_ignore_vcs() && !self.no_ignore_exclude())
|
||||||
|
.require_git(!self.is_present("no-require-git"))
|
||||||
.ignore_case_insensitive(self.ignore_file_case_insensitive());
|
.ignore_case_insensitive(self.ignore_file_case_insensitive());
|
||||||
if !self.no_ignore() {
|
if !self.no_ignore() {
|
||||||
builder.add_custom_ignore_filename(".rgignore");
|
builder.add_custom_ignore_filename(".rgignore");
|
||||||
@@ -900,12 +904,9 @@ impl ArgMatches {
|
|||||||
/// Returns the form of binary detection to perform on files that are
|
/// Returns the form of binary detection to perform on files that are
|
||||||
/// implicitly searched via recursive directory traversal.
|
/// implicitly searched via recursive directory traversal.
|
||||||
fn binary_detection_implicit(&self) -> BinaryDetection {
|
fn binary_detection_implicit(&self) -> BinaryDetection {
|
||||||
let none =
|
let none = self.is_present("text") || self.is_present("null-data");
|
||||||
self.is_present("text")
|
|
||||||
|| self.is_present("null-data");
|
|
||||||
let convert =
|
let convert =
|
||||||
self.is_present("binary")
|
self.is_present("binary") || self.unrestricted_count() >= 3;
|
||||||
|| self.unrestricted_count() >= 3;
|
|
||||||
if none {
|
if none {
|
||||||
BinaryDetection::none()
|
BinaryDetection::none()
|
||||||
} else if convert {
|
} else if convert {
|
||||||
@@ -923,9 +924,7 @@ impl ArgMatches {
|
|||||||
/// as a filter (but quitting immediately once a NUL byte is seen), and we
|
/// as a filter (but quitting immediately once a NUL byte is seen), and we
|
||||||
/// should never filter out files that the user wants to explicitly search.
|
/// should never filter out files that the user wants to explicitly search.
|
||||||
fn binary_detection_explicit(&self) -> BinaryDetection {
|
fn binary_detection_explicit(&self) -> BinaryDetection {
|
||||||
let none =
|
let none = self.is_present("text") || self.is_present("null-data");
|
||||||
self.is_present("text")
|
|
||||||
|| self.is_present("null-data");
|
|
||||||
if none {
|
if none {
|
||||||
BinaryDetection::none()
|
BinaryDetection::none()
|
||||||
} else {
|
} else {
|
||||||
@@ -953,8 +952,8 @@ impl ArgMatches {
|
|||||||
/// case is disabled.
|
/// case is disabled.
|
||||||
fn case_smart(&self) -> bool {
|
fn case_smart(&self) -> bool {
|
||||||
self.is_present("smart-case")
|
self.is_present("smart-case")
|
||||||
&& !self.is_present("ignore-case")
|
&& !self.is_present("ignore-case")
|
||||||
&& !self.is_present("case-sensitive")
|
&& !self.is_present("case-sensitive")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the user's color choice based on command line parameters and
|
/// Returns the user's color choice based on command line parameters and
|
||||||
@@ -1010,20 +1009,20 @@ impl ArgMatches {
|
|||||||
let after = self.usize_of("after-context")?.unwrap_or(0);
|
let after = self.usize_of("after-context")?.unwrap_or(0);
|
||||||
let before = self.usize_of("before-context")?.unwrap_or(0);
|
let before = self.usize_of("before-context")?.unwrap_or(0);
|
||||||
let both = self.usize_of("context")?.unwrap_or(0);
|
let both = self.usize_of("context")?.unwrap_or(0);
|
||||||
Ok(if both > 0 {
|
Ok(if both > 0 { (both, both) } else { (before, after) })
|
||||||
(both, both)
|
|
||||||
} else {
|
|
||||||
(before, after)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the unescaped context separator in UTF-8 bytes.
|
/// Returns the unescaped context separator in UTF-8 bytes.
|
||||||
///
|
///
|
||||||
/// If one was not provided, the default `--` is returned.
|
/// If one was not provided, the default `--` is returned.
|
||||||
fn context_separator(&self) -> Vec<u8> {
|
/// If --no-context-separator is passed, None is returned.
|
||||||
match self.value_of_os("context-separator") {
|
fn context_separator(&self) -> Option<Vec<u8>> {
|
||||||
None => b"--".to_vec(),
|
let nosep = self.is_present("no-context-separator");
|
||||||
Some(sep) => cli::unescape_os(&sep),
|
let sep = self.value_of_os("context-separator");
|
||||||
|
match (nosep, sep) {
|
||||||
|
(true, _) => None,
|
||||||
|
(false, None) => Some(b"--".to_vec()),
|
||||||
|
(false, Some(sep)) => Some(cli::unescape_os(&sep)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1092,7 +1091,7 @@ impl ArgMatches {
|
|||||||
Ok(if self.heading() {
|
Ok(if self.heading() {
|
||||||
Some(b"".to_vec())
|
Some(b"".to_vec())
|
||||||
} else if ctx_before > 0 || ctx_after > 0 {
|
} else if ctx_before > 0 || ctx_after > 0 {
|
||||||
Some(self.context_separator().clone())
|
self.context_separator()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
@@ -1105,8 +1104,8 @@ impl ArgMatches {
|
|||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
cli::is_tty_stdout()
|
cli::is_tty_stdout()
|
||||||
|| self.is_present("heading")
|
|| self.is_present("heading")
|
||||||
|| self.is_present("pretty")
|
|| self.is_present("pretty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1162,10 +1161,10 @@ impl ArgMatches {
|
|||||||
// tty for human consumption, except for one interesting case: when
|
// tty for human consumption, except for one interesting case: when
|
||||||
// we're only searching stdin. This makes pipelines work as expected.
|
// we're only searching stdin. This makes pipelines work as expected.
|
||||||
(cli::is_tty_stdout() && !self.is_only_stdin(paths))
|
(cli::is_tty_stdout() && !self.is_only_stdin(paths))
|
||||||
|| self.is_present("line-number")
|
|| self.is_present("line-number")
|
||||||
|| self.is_present("column")
|
|| self.is_present("column")
|
||||||
|| self.is_present("pretty")
|
|| self.is_present("pretty")
|
||||||
|| self.is_present("vimgrep")
|
|| self.is_present("vimgrep")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The maximum number of columns allowed on each line.
|
/// The maximum number of columns allowed on each line.
|
||||||
@@ -1226,6 +1225,19 @@ impl ArgMatches {
|
|||||||
self.is_present("no-ignore-dot") || self.no_ignore()
|
self.is_present("no-ignore-dot") || self.no_ignore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if local exclude (ignore) files should be ignored.
|
||||||
|
fn no_ignore_exclude(&self) -> bool {
|
||||||
|
self.is_present("no-ignore-exclude") || self.no_ignore()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if explicitly given ignore files should be ignored.
|
||||||
|
fn no_ignore_files(&self) -> bool {
|
||||||
|
// We don't look at no-ignore here because --no-ignore is explicitly
|
||||||
|
// documented to not override --ignore-file. We could change this, but
|
||||||
|
// it would be a fairly severe breaking change.
|
||||||
|
self.is_present("no-ignore-files")
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if global ignore files should be ignored.
|
/// Returns true if global ignore files should be ignored.
|
||||||
fn no_ignore_global(&self) -> bool {
|
fn no_ignore_global(&self) -> bool {
|
||||||
self.is_present("no-ignore-global") || self.no_ignore()
|
self.is_present("no-ignore-global") || self.no_ignore()
|
||||||
@@ -1253,8 +1265,7 @@ impl ArgMatches {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let (count, count_matches) = self.counts();
|
let (count, count_matches) = self.counts();
|
||||||
let summary =
|
let summary = count
|
||||||
count
|
|
||||||
|| count_matches
|
|| count_matches
|
||||||
|| self.is_present("files-with-matches")
|
|| self.is_present("files-with-matches")
|
||||||
|| self.is_present("files-without-match");
|
|| self.is_present("files-without-match");
|
||||||
@@ -1267,17 +1278,23 @@ impl ArgMatches {
|
|||||||
|
|
||||||
/// Builds the set of glob overrides from the command line flags.
|
/// Builds the set of glob overrides from the command line flags.
|
||||||
fn overrides(&self) -> Result<Override> {
|
fn overrides(&self) -> Result<Override> {
|
||||||
let mut builder = OverrideBuilder::new(env::current_dir()?);
|
let globs = self.values_of_lossy_vec("glob");
|
||||||
|
let iglobs = self.values_of_lossy_vec("iglob");
|
||||||
|
if globs.is_empty() && iglobs.is_empty() {
|
||||||
|
return Ok(Override::empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut builder = OverrideBuilder::new(current_dir()?);
|
||||||
// Make all globs case insensitive with --glob-case-insensitive.
|
// Make all globs case insensitive with --glob-case-insensitive.
|
||||||
if self.is_present("glob-case-insensitive") {
|
if self.is_present("glob-case-insensitive") {
|
||||||
builder.case_insensitive(true).unwrap();
|
builder.case_insensitive(true).unwrap();
|
||||||
}
|
}
|
||||||
for glob in self.values_of_lossy_vec("glob") {
|
for glob in globs {
|
||||||
builder.add(&glob)?;
|
builder.add(&glob)?;
|
||||||
}
|
}
|
||||||
// This only enables case insensitivity for subsequent globs.
|
// This only enables case insensitivity for subsequent globs.
|
||||||
builder.case_insensitive(true).unwrap();
|
builder.case_insensitive(true).unwrap();
|
||||||
for glob in self.values_of_lossy_vec("iglob") {
|
for glob in iglobs {
|
||||||
builder.add(&glob)?;
|
builder.add(&glob)?;
|
||||||
}
|
}
|
||||||
Ok(builder.build()?)
|
Ok(builder.build()?)
|
||||||
@@ -1308,10 +1325,10 @@ impl ArgMatches {
|
|||||||
/// be used when ripgrep is not otherwise given at least one file path
|
/// be used when ripgrep is not otherwise given at least one file path
|
||||||
/// as a positional argument.
|
/// as a positional argument.
|
||||||
fn path_default(&self) -> PathBuf {
|
fn path_default(&self) -> PathBuf {
|
||||||
let file_is_stdin = self.values_of_os("file")
|
let file_is_stdin = self
|
||||||
|
.values_of_os("file")
|
||||||
.map_or(false, |mut files| files.any(|f| f == "-"));
|
.map_or(false, |mut files| files.any(|f| f == "-"));
|
||||||
let search_cwd =
|
let search_cwd = !cli::is_readable_stdin()
|
||||||
!cli::is_readable_stdin()
|
|
||||||
|| (self.is_present("file") && file_is_stdin)
|
|| (self.is_present("file") && file_is_stdin)
|
||||||
|| self.is_present("files")
|
|| self.is_present("files")
|
||||||
|| self.is_present("type-list")
|
|| self.is_present("type-list")
|
||||||
@@ -1340,8 +1357,8 @@ impl ArgMatches {
|
|||||||
the given separator is {} bytes: {}\n\
|
the given separator is {} bytes: {}\n\
|
||||||
In some shells on Windows '/' is automatically \
|
In some shells on Windows '/' is automatically \
|
||||||
expanded. Use '//' instead.",
|
expanded. Use '//' instead.",
|
||||||
sep.len(),
|
sep.len(),
|
||||||
cli::escape(&sep),
|
cli::escape(&sep),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
Ok(Some(sep[0]))
|
Ok(Some(sep[0]))
|
||||||
@@ -1391,14 +1408,16 @@ impl ArgMatches {
|
|||||||
if let Some(paths) = self.values_of_os("file") {
|
if let Some(paths) = self.values_of_os("file") {
|
||||||
for path in paths {
|
for path in paths {
|
||||||
if path == "-" {
|
if path == "-" {
|
||||||
pats.extend(cli::patterns_from_stdin()?
|
pats.extend(
|
||||||
.into_iter()
|
cli::patterns_from_stdin()?
|
||||||
.map(|p| self.pattern_from_string(p))
|
.into_iter()
|
||||||
|
.map(|p| self.pattern_from_string(p)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
pats.extend(cli::patterns_from_path(path)?
|
pats.extend(
|
||||||
.into_iter()
|
cli::patterns_from_path(path)?
|
||||||
.map(|p| self.pattern_from_string(p))
|
.into_iter()
|
||||||
|
.map(|p| self.pattern_from_string(p)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1479,8 +1498,12 @@ impl ArgMatches {
|
|||||||
/// flag. If no --pre-globs are available, then this always returns an
|
/// flag. If no --pre-globs are available, then this always returns an
|
||||||
/// empty set of globs.
|
/// empty set of globs.
|
||||||
fn preprocessor_globs(&self) -> Result<Override> {
|
fn preprocessor_globs(&self) -> Result<Override> {
|
||||||
let mut builder = OverrideBuilder::new(env::current_dir()?);
|
let globs = self.values_of_lossy_vec("pre-glob");
|
||||||
for glob in self.values_of_lossy_vec("pre-glob") {
|
if globs.is_empty() {
|
||||||
|
return Ok(Override::empty());
|
||||||
|
}
|
||||||
|
let mut builder = OverrideBuilder::new(current_dir()?);
|
||||||
|
for glob in globs {
|
||||||
builder.add(&glob)?;
|
builder.add(&glob)?;
|
||||||
}
|
}
|
||||||
Ok(builder.build()?)
|
Ok(builder.build()?)
|
||||||
@@ -1507,7 +1530,7 @@ impl ArgMatches {
|
|||||||
None => match self.value_of_lossy("sortr") {
|
None => match self.value_of_lossy("sortr") {
|
||||||
None => return Ok(SortBy::none()),
|
None => return Ok(SortBy::none()),
|
||||||
Some(choice) => SortBy::desc(SortByKind::new(&choice)),
|
Some(choice) => SortBy::desc(SortByKind::new(&choice)),
|
||||||
}
|
},
|
||||||
Some(choice) => SortBy::asc(SortByKind::new(&choice)),
|
Some(choice) => SortBy::asc(SortByKind::new(&choice)),
|
||||||
};
|
};
|
||||||
Ok(sortby)
|
Ok(sortby)
|
||||||
@@ -1550,11 +1573,7 @@ impl ArgMatches {
|
|||||||
return Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
let threads = self.usize_of("threads")?.unwrap_or(0);
|
let threads = self.usize_of("threads")?.unwrap_or(0);
|
||||||
Ok(if threads == 0 {
|
Ok(if threads == 0 { cmp::min(12, num_cpus::get()) } else { threads })
|
||||||
cmp::min(12, num_cpus::get())
|
|
||||||
} else {
|
|
||||||
threads
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a file type matcher from the command line flags.
|
/// Builds a file type matcher from the command line flags.
|
||||||
@@ -1581,11 +1600,17 @@ impl ArgMatches {
|
|||||||
self.occurrences_of("unrestricted")
|
self.occurrences_of("unrestricted")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if and only if PCRE2's Unicode mode should be enabled.
|
/// Returns true if and only if Unicode mode should be enabled.
|
||||||
|
fn unicode(&self) -> bool {
|
||||||
|
// Unicode mode is enabled by default, so only disable it when
|
||||||
|
// --no-unicode is given explicitly.
|
||||||
|
!(self.is_present("no-unicode") || self.is_present("no-pcre2-unicode"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if and only if PCRE2 is enabled and its Unicode mode is
|
||||||
|
/// enabled.
|
||||||
fn pcre2_unicode(&self) -> bool {
|
fn pcre2_unicode(&self) -> bool {
|
||||||
// PCRE2 Unicode is enabled by default, so only disable it when told
|
self.is_present("pcre2") && self.unicode()
|
||||||
// to do so explicitly.
|
|
||||||
self.is_present("pcre2") && !self.is_present("no-pcre2-unicode")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if and only if file names containing each match should
|
/// Returns true if and only if file names containing each match should
|
||||||
@@ -1596,9 +1621,11 @@ impl ArgMatches {
|
|||||||
} else {
|
} else {
|
||||||
let path_stdin = Path::new("-");
|
let path_stdin = Path::new("-");
|
||||||
self.is_present("with-filename")
|
self.is_present("with-filename")
|
||||||
|| self.is_present("vimgrep")
|
|| self.is_present("vimgrep")
|
||||||
|| paths.len() > 1
|
|| paths.len() > 1
|
||||||
|| paths.get(0).map_or(false, |p| p != path_stdin && p.is_dir())
|
|| paths
|
||||||
|
.get(0)
|
||||||
|
.map_or(false, |p| p != path_stdin && p.is_dir())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1621,11 +1648,7 @@ impl ArgMatches {
|
|||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
Some(n) => n,
|
Some(n) => n,
|
||||||
};
|
};
|
||||||
Ok(if n == 0 {
|
Ok(if n == 0 { None } else { Some(n) })
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(n)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Safely reads an arg value with the given name, and if it's present,
|
/// Safely reads an arg value with the given name, and if it's present,
|
||||||
@@ -1683,27 +1706,52 @@ impl ArgMatches {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Inspect an error resulting from building a Rust regex matcher, and if it's
|
||||||
|
/// believed to correspond to a syntax error that another engine could handle,
|
||||||
|
/// then add a message to suggest the use of the engine flag.
|
||||||
|
fn suggest(msg: String) -> String {
|
||||||
|
if let Some(pcre_msg) = suggest_pcre2(&msg) {
|
||||||
|
return pcre_msg;
|
||||||
|
}
|
||||||
|
msg
|
||||||
|
}
|
||||||
|
|
||||||
/// Inspect an error resulting from building a Rust regex matcher, and if it's
|
/// Inspect an error resulting from building a Rust regex matcher, and if it's
|
||||||
/// believed to correspond to a syntax error that PCRE2 could handle, then
|
/// believed to correspond to a syntax error that PCRE2 could handle, then
|
||||||
/// add a message to suggest the use of -P/--pcre2.
|
/// add a message to suggest the use of -P/--pcre2.
|
||||||
#[cfg(feature = "pcre2")]
|
fn suggest_pcre2(msg: &str) -> Option<String> {
|
||||||
fn suggest_pcre2(msg: String) -> String {
|
#[cfg(feature = "pcre2")]
|
||||||
if !msg.contains("backreferences") && !msg.contains("look-around") {
|
fn suggest(msg: &str) -> Option<String> {
|
||||||
msg
|
if !msg.contains("backreferences") && !msg.contains("look-around") {
|
||||||
} else {
|
None
|
||||||
format!("{}
|
} else {
|
||||||
|
Some(format!(
|
||||||
|
"{}
|
||||||
|
|
||||||
Consider enabling PCRE2 with the --pcre2 flag, which can handle backreferences
|
Consider enabling PCRE2 with the --pcre2 flag, which can handle backreferences
|
||||||
and look-around.", msg)
|
and look-around.",
|
||||||
|
msg
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "pcre2"))]
|
||||||
|
fn suggest(_: &str) -> Option<String> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
suggest(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_multiline(msg: String) -> String {
|
fn suggest_multiline(msg: String) -> String {
|
||||||
if msg.contains("the literal") && msg.contains("not allowed") {
|
if msg.contains("the literal") && msg.contains("not allowed") {
|
||||||
format!("{}
|
format!(
|
||||||
|
"{}
|
||||||
|
|
||||||
Consider enabling multiline mode with the --multiline flag (or -U for short).
|
Consider enabling multiline mode with the --multiline flag (or -U for short).
|
||||||
When multiline mode is enabled, new line characters can be matched.", msg)
|
When multiline mode is enabled, new line characters can be matched.",
|
||||||
|
msg
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
msg
|
msg
|
||||||
}
|
}
|
||||||
@@ -1711,10 +1759,7 @@ When multiline mode is enabled, new line characters can be matched.", msg)
|
|||||||
|
|
||||||
/// Convert the result of parsing a human readable file size to a `usize`,
|
/// Convert the result of parsing a human readable file size to a `usize`,
|
||||||
/// failing if the type does not fit.
|
/// failing if the type does not fit.
|
||||||
fn u64_to_usize(
|
fn u64_to_usize(arg_name: &str, value: Option<u64>) -> Result<Option<usize>> {
|
||||||
arg_name: &str,
|
|
||||||
value: Option<u64>,
|
|
||||||
) -> Result<Option<usize>> {
|
|
||||||
use std::usize;
|
use std::usize;
|
||||||
|
|
||||||
let value = match value {
|
let value = match value {
|
||||||
@@ -1739,7 +1784,8 @@ fn sort_by_metadata_time<G>(
|
|||||||
reverse: bool,
|
reverse: bool,
|
||||||
get_time: G,
|
get_time: G,
|
||||||
) -> cmp::Ordering
|
) -> cmp::Ordering
|
||||||
where G: Fn(&fs::Metadata) -> io::Result<SystemTime>
|
where
|
||||||
|
G: Fn(&fs::Metadata) -> io::Result<SystemTime>,
|
||||||
{
|
{
|
||||||
let t1 = match p1.metadata().and_then(|md| get_time(&md)) {
|
let t1 = match p1.metadata().and_then(|md| get_time(&md)) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
@@ -1762,11 +1808,10 @@ where G: Fn(&fs::Metadata) -> io::Result<SystemTime>
|
|||||||
/// corresponds to a `--help` or `--version` request. In which case, the
|
/// corresponds to a `--help` or `--version` request. In which case, the
|
||||||
/// corresponding output is printed and the current process is exited
|
/// corresponding output is printed and the current process is exited
|
||||||
/// successfully.
|
/// successfully.
|
||||||
fn clap_matches<I, T>(
|
fn clap_matches<I, T>(args: I) -> Result<clap::ArgMatches<'static>>
|
||||||
args: I,
|
where
|
||||||
) -> Result<clap::ArgMatches<'static>>
|
I: IntoIterator<Item = T>,
|
||||||
where I: IntoIterator<Item=T>,
|
T: Into<OsString> + Clone,
|
||||||
T: Into<OsString> + Clone
|
|
||||||
{
|
{
|
||||||
let err = match app::app().get_matches_from_safe(args) {
|
let err = match app::app().get_matches_from_safe(args) {
|
||||||
Ok(matches) => return Ok(matches),
|
Ok(matches) => return Ok(matches),
|
||||||
@@ -1784,3 +1829,26 @@ where I: IntoIterator<Item=T>,
|
|||||||
let _ = write!(io::stdout(), "{}", err);
|
let _ = write!(io::stdout(), "{}", err);
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Attempts to discover the current working directory. This mostly just defers
|
||||||
|
/// to the standard library, however, such things will fail if ripgrep is in
|
||||||
|
/// a directory that no longer exists. We attempt some fallback mechanisms,
|
||||||
|
/// such as querying the PWD environment variable, but otherwise return an
|
||||||
|
/// error.
|
||||||
|
fn current_dir() -> Result<PathBuf> {
|
||||||
|
let err = match env::current_dir() {
|
||||||
|
Err(err) => err,
|
||||||
|
Ok(cwd) => return Ok(cwd),
|
||||||
|
};
|
||||||
|
if let Some(cwd) = env::var_os("PWD") {
|
||||||
|
if !cwd.is_empty() {
|
||||||
|
return Ok(PathBuf::from(cwd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(format!(
|
||||||
|
"failed to get current working directory: {} \
|
||||||
|
--- did your CWD get deleted?",
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
.into())
|
||||||
|
}
|
@@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::ffi::OsString;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::ffi::OsString;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use bstr::{io::BufReadExt, ByteSlice};
|
use bstr::{io::BufReadExt, ByteSlice};
|
||||||
@@ -102,12 +102,13 @@ fn parse_reader<R: io::Read>(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::ffi::OsString;
|
|
||||||
use super::parse_reader;
|
use super::parse_reader;
|
||||||
|
use std::ffi::OsString;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic() {
|
fn basic() {
|
||||||
let (args, errs) = parse_reader(&b"\
|
let (args, errs) = parse_reader(
|
||||||
|
&b"\
|
||||||
# Test
|
# Test
|
||||||
--context=0
|
--context=0
|
||||||
--smart-case
|
--smart-case
|
||||||
@@ -116,13 +117,13 @@ mod tests {
|
|||||||
|
|
||||||
# --bar
|
# --bar
|
||||||
--foo
|
--foo
|
||||||
"[..]).unwrap();
|
"[..],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
assert!(errs.is_empty());
|
assert!(errs.is_empty());
|
||||||
let args: Vec<String> =
|
let args: Vec<String> =
|
||||||
args.into_iter().map(|s| s.into_string().unwrap()).collect();
|
args.into_iter().map(|s| s.into_string().unwrap()).collect();
|
||||||
assert_eq!(args, vec![
|
assert_eq!(args, vec!["--context=0", "--smart-case", "-u", "--foo",]);
|
||||||
"--context=0", "--smart-case", "-u", "--foo",
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We test that we can handle invalid UTF-8 on Unix-like systems.
|
// We test that we can handle invalid UTF-8 on Unix-like systems.
|
||||||
@@ -131,32 +132,38 @@ mod tests {
|
|||||||
fn error() {
|
fn error() {
|
||||||
use std::os::unix::ffi::OsStringExt;
|
use std::os::unix::ffi::OsStringExt;
|
||||||
|
|
||||||
let (args, errs) = parse_reader(&b"\
|
let (args, errs) = parse_reader(
|
||||||
|
&b"\
|
||||||
quux
|
quux
|
||||||
foo\xFFbar
|
foo\xFFbar
|
||||||
baz
|
baz
|
||||||
"[..]).unwrap();
|
"[..],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
assert!(errs.is_empty());
|
assert!(errs.is_empty());
|
||||||
assert_eq!(args, vec![
|
assert_eq!(
|
||||||
OsString::from("quux"),
|
args,
|
||||||
OsString::from_vec(b"foo\xFFbar".to_vec()),
|
vec![
|
||||||
OsString::from("baz"),
|
OsString::from("quux"),
|
||||||
]);
|
OsString::from_vec(b"foo\xFFbar".to_vec()),
|
||||||
|
OsString::from("baz"),
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... but test that invalid UTF-8 fails on Windows.
|
// ... but test that invalid UTF-8 fails on Windows.
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
fn error() {
|
fn error() {
|
||||||
let (args, errs) = parse_reader(&b"\
|
let (args, errs) = parse_reader(
|
||||||
|
&b"\
|
||||||
quux
|
quux
|
||||||
foo\xFFbar
|
foo\xFFbar
|
||||||
baz
|
baz
|
||||||
"[..]).unwrap();
|
"[..],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
assert_eq!(errs.len(), 1);
|
assert_eq!(errs.len(), 1);
|
||||||
assert_eq!(args, vec![
|
assert_eq!(args, vec![OsString::from("quux"), OsString::from("baz"),]);
|
||||||
OsString::from("quux"),
|
|
||||||
OsString::from("baz"),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
use std::error;
|
use std::error;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Mutex;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use ignore::WalkState;
|
use ignore::WalkState;
|
||||||
@@ -55,16 +55,15 @@ fn main() {
|
|||||||
fn try_main(args: Args) -> Result<()> {
|
fn try_main(args: Args) -> Result<()> {
|
||||||
use args::Command::*;
|
use args::Command::*;
|
||||||
|
|
||||||
let matched =
|
let matched = match args.command()? {
|
||||||
match args.command()? {
|
Search => search(&args),
|
||||||
Search => search(&args),
|
SearchParallel => search_parallel(&args),
|
||||||
SearchParallel => search_parallel(&args),
|
SearchNever => Ok(false),
|
||||||
SearchNever => Ok(false),
|
Files => files(&args),
|
||||||
Files => files(&args),
|
FilesParallel => files_parallel(&args),
|
||||||
FilesParallel => files_parallel(&args),
|
Types => types(&args),
|
||||||
Types => types(&args),
|
PCRE2Version => pcre2_version(&args),
|
||||||
PCRE2Version => pcre2_version(&args),
|
}?;
|
||||||
}?;
|
|
||||||
if matched && (args.quiet() || !messages::errored()) {
|
if matched && (args.quiet() || !messages::errored()) {
|
||||||
process::exit(0)
|
process::exit(0)
|
||||||
} else if messages::errored() {
|
} else if messages::errored() {
|
||||||
@@ -126,24 +125,21 @@ fn search_parallel(args: &Args) -> Result<bool> {
|
|||||||
|
|
||||||
let quit_after_match = args.quit_after_match()?;
|
let quit_after_match = args.quit_after_match()?;
|
||||||
let started_at = Instant::now();
|
let started_at = Instant::now();
|
||||||
let subject_builder = Arc::new(args.subject_builder());
|
let subject_builder = args.subject_builder();
|
||||||
let bufwtr = Arc::new(args.buffer_writer()?);
|
let bufwtr = args.buffer_writer()?;
|
||||||
let stats = Arc::new(args.stats()?.map(Mutex::new));
|
let stats = args.stats()?.map(Mutex::new);
|
||||||
let matched = Arc::new(AtomicBool::new(false));
|
let matched = AtomicBool::new(false);
|
||||||
let mut searcher_err = None;
|
let mut searcher_err = None;
|
||||||
args.walker_parallel()?.run(|| {
|
args.walker_parallel()?.run(|| {
|
||||||
let args = args.clone();
|
let bufwtr = &bufwtr;
|
||||||
let bufwtr = Arc::clone(&bufwtr);
|
let stats = &stats;
|
||||||
let stats = Arc::clone(&stats);
|
let matched = &matched;
|
||||||
let matched = Arc::clone(&matched);
|
let subject_builder = &subject_builder;
|
||||||
let subject_builder = Arc::clone(&subject_builder);
|
|
||||||
let mut searcher = match args.search_worker(bufwtr.buffer()) {
|
let mut searcher = match args.search_worker(bufwtr.buffer()) {
|
||||||
Ok(searcher) => searcher,
|
Ok(searcher) => searcher,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
searcher_err = Some(err);
|
searcher_err = Some(err);
|
||||||
return Box::new(move |_| {
|
return Box::new(move |_| WalkState::Quit);
|
||||||
WalkState::Quit
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -185,7 +181,7 @@ fn search_parallel(args: &Args) -> Result<bool> {
|
|||||||
if let Some(err) = searcher_err.take() {
|
if let Some(err) = searcher_err.take() {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
if let Some(ref locked_stats) = *stats {
|
if let Some(ref locked_stats) = stats {
|
||||||
let elapsed = Instant::now().duration_since(started_at);
|
let elapsed = Instant::now().duration_since(started_at);
|
||||||
let stats = locked_stats.lock().unwrap();
|
let stats = locked_stats.lock().unwrap();
|
||||||
let mut searcher = args.search_worker(args.stdout())?;
|
let mut searcher = args.search_worker(args.stdout())?;
|
||||||
@@ -235,9 +231,9 @@ fn files_parallel(args: &Args) -> Result<bool> {
|
|||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
let quit_after_match = args.quit_after_match()?;
|
let quit_after_match = args.quit_after_match()?;
|
||||||
let subject_builder = Arc::new(args.subject_builder());
|
let subject_builder = args.subject_builder();
|
||||||
let mut path_printer = args.path_printer(args.stdout())?;
|
let mut path_printer = args.path_printer(args.stdout())?;
|
||||||
let matched = Arc::new(AtomicBool::new(false));
|
let matched = AtomicBool::new(false);
|
||||||
let (tx, rx) = mpsc::channel::<Subject>();
|
let (tx, rx) = mpsc::channel::<Subject>();
|
||||||
|
|
||||||
let print_thread = thread::spawn(move || -> io::Result<()> {
|
let print_thread = thread::spawn(move || -> io::Result<()> {
|
||||||
@@ -247,8 +243,8 @@ fn files_parallel(args: &Args) -> Result<bool> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
args.walker_parallel()?.run(|| {
|
args.walker_parallel()?.run(|| {
|
||||||
let subject_builder = Arc::clone(&subject_builder);
|
let subject_builder = &subject_builder;
|
||||||
let matched = Arc::clone(&matched);
|
let matched = &matched;
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
|
|
||||||
Box::new(move |result| {
|
Box::new(move |result| {
|
@@ -37,10 +37,7 @@ impl PathPrinterBuilder {
|
|||||||
/// Create a new path printer with the current configuration that writes
|
/// Create a new path printer with the current configuration that writes
|
||||||
/// paths to the given writer.
|
/// paths to the given writer.
|
||||||
pub fn build<W: WriteColor>(&self, wtr: W) -> PathPrinter<W> {
|
pub fn build<W: WriteColor>(&self, wtr: W) -> PathPrinter<W> {
|
||||||
PathPrinter {
|
PathPrinter { config: self.config.clone(), wtr }
|
||||||
config: self.config.clone(),
|
|
||||||
wtr: wtr,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the color specification for this printer.
|
/// Set the color specification for this printer.
|
@@ -7,9 +7,9 @@ use std::time::Duration;
|
|||||||
use grep::cli;
|
use grep::cli;
|
||||||
use grep::matcher::Matcher;
|
use grep::matcher::Matcher;
|
||||||
#[cfg(feature = "pcre2")]
|
#[cfg(feature = "pcre2")]
|
||||||
use grep::pcre2::{RegexMatcher as PCRE2RegexMatcher};
|
use grep::pcre2::RegexMatcher as PCRE2RegexMatcher;
|
||||||
use grep::printer::{JSON, Standard, Summary, Stats};
|
use grep::printer::{Standard, Stats, Summary, JSON};
|
||||||
use grep::regex::{RegexMatcher as RustRegexMatcher};
|
use grep::regex::RegexMatcher as RustRegexMatcher;
|
||||||
use grep::searcher::{BinaryDetection, Searcher};
|
use grep::searcher::{BinaryDetection, Searcher};
|
||||||
use ignore::overrides::Override;
|
use ignore::overrides::Override;
|
||||||
use serde_json as json;
|
use serde_json as json;
|
||||||
@@ -70,7 +70,7 @@ impl SearchWorkerBuilder {
|
|||||||
SearchWorkerBuilder {
|
SearchWorkerBuilder {
|
||||||
config: Config::default(),
|
config: Config::default(),
|
||||||
command_builder: cmd_builder,
|
command_builder: cmd_builder,
|
||||||
decomp_builder: decomp_builder,
|
decomp_builder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,8 +86,12 @@ impl SearchWorkerBuilder {
|
|||||||
let command_builder = self.command_builder.clone();
|
let command_builder = self.command_builder.clone();
|
||||||
let decomp_builder = self.decomp_builder.clone();
|
let decomp_builder = self.decomp_builder.clone();
|
||||||
SearchWorker {
|
SearchWorker {
|
||||||
config, command_builder, decomp_builder,
|
config,
|
||||||
matcher, searcher, printer,
|
command_builder,
|
||||||
|
decomp_builder,
|
||||||
|
matcher,
|
||||||
|
searcher,
|
||||||
|
printer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,9 +231,7 @@ impl<W: WriteColor> Printer<W> {
|
|||||||
stats: &Stats,
|
stats: &Stats,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
match *self {
|
match *self {
|
||||||
Printer::JSON(_) => {
|
Printer::JSON(_) => self.print_stats_json(total_duration, stats),
|
||||||
self.print_stats_json(total_duration, stats)
|
|
||||||
}
|
|
||||||
Printer::Standard(_) | Printer::Summary(_) => {
|
Printer::Standard(_) | Printer::Summary(_) => {
|
||||||
self.print_stats_human(total_duration, stats)
|
self.print_stats_human(total_duration, stats)
|
||||||
}
|
}
|
||||||
@@ -273,17 +275,20 @@ impl<W: WriteColor> Printer<W> {
|
|||||||
// the grep-printer crate. We simply "extend" it with the 'summary'
|
// the grep-printer crate. We simply "extend" it with the 'summary'
|
||||||
// message type.
|
// message type.
|
||||||
let fractional = fractional_seconds(total_duration);
|
let fractional = fractional_seconds(total_duration);
|
||||||
json::to_writer(self.get_mut(), &json!({
|
json::to_writer(
|
||||||
"type": "summary",
|
self.get_mut(),
|
||||||
"data": {
|
&json!({
|
||||||
"stats": stats,
|
"type": "summary",
|
||||||
"elapsed_total": {
|
"data": {
|
||||||
"secs": total_duration.as_secs(),
|
"stats": stats,
|
||||||
"nanos": total_duration.subsec_nanos(),
|
"elapsed_total": {
|
||||||
"human": format!("{:0.6}s", fractional),
|
"secs": total_duration.as_secs(),
|
||||||
},
|
"nanos": total_duration.subsec_nanos(),
|
||||||
}
|
"human": format!("{:0.6}s", fractional),
|
||||||
}))?;
|
},
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)?;
|
||||||
write!(self.get_mut(), "\n")
|
write!(self.get_mut(), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,12 +320,11 @@ pub struct SearchWorker<W> {
|
|||||||
impl<W: WriteColor> SearchWorker<W> {
|
impl<W: WriteColor> SearchWorker<W> {
|
||||||
/// Execute a search over the given subject.
|
/// Execute a search over the given subject.
|
||||||
pub fn search(&mut self, subject: &Subject) -> io::Result<SearchResult> {
|
pub fn search(&mut self, subject: &Subject) -> io::Result<SearchResult> {
|
||||||
let bin =
|
let bin = if subject.is_explicit() {
|
||||||
if subject.is_explicit() {
|
self.config.binary_explicit.clone()
|
||||||
self.config.binary_explicit.clone()
|
} else {
|
||||||
} else {
|
self.config.binary_implicit.clone()
|
||||||
self.config.binary_implicit.clone()
|
};
|
||||||
};
|
|
||||||
self.searcher.set_binary_detection(bin);
|
self.searcher.set_binary_detection(bin);
|
||||||
|
|
||||||
let path = subject.path();
|
let path = subject.path();
|
||||||
@@ -389,19 +393,15 @@ impl<W: WriteColor> SearchWorker<W> {
|
|||||||
let mut cmd = Command::new(bin);
|
let mut cmd = Command::new(bin);
|
||||||
cmd.arg(path).stdin(Stdio::from(File::open(path)?));
|
cmd.arg(path).stdin(Stdio::from(File::open(path)?));
|
||||||
|
|
||||||
let rdr = self
|
let rdr = self.command_builder.build(&mut cmd).map_err(|err| {
|
||||||
.command_builder
|
io::Error::new(
|
||||||
.build(&mut cmd)
|
io::ErrorKind::Other,
|
||||||
.map_err(|err| {
|
format!(
|
||||||
io::Error::new(
|
"preprocessor command could not start: '{:?}': {}",
|
||||||
io::ErrorKind::Other,
|
cmd, err,
|
||||||
format!(
|
),
|
||||||
"preprocessor command could not start: '{:?}': {}",
|
)
|
||||||
cmd,
|
})?;
|
||||||
err,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
self.search_reader(path, rdr).map_err(|err| {
|
self.search_reader(path, rdr).map_err(|err| {
|
||||||
io::Error::new(
|
io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
@@ -413,10 +413,7 @@ impl<W: WriteColor> SearchWorker<W> {
|
|||||||
/// Attempt to decompress the data at the given file path and search the
|
/// Attempt to decompress the data at the given file path and search the
|
||||||
/// result. If the given file path isn't recognized as a compressed file,
|
/// result. If the given file path isn't recognized as a compressed file,
|
||||||
/// then search it without doing any decompression.
|
/// then search it without doing any decompression.
|
||||||
fn search_decompress(
|
fn search_decompress(&mut self, path: &Path) -> io::Result<SearchResult> {
|
||||||
&mut self,
|
|
||||||
path: &Path,
|
|
||||||
) -> io::Result<SearchResult> {
|
|
||||||
let rdr = self.decomp_builder.build(path)?;
|
let rdr = self.decomp_builder.build(path)?;
|
||||||
self.search_reader(path, rdr)
|
self.search_reader(path, rdr)
|
||||||
}
|
}
|
@@ -11,9 +11,7 @@ struct Config {
|
|||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Config {
|
fn default() -> Config {
|
||||||
Config {
|
Config { strip_dot_prefix: false }
|
||||||
strip_dot_prefix: false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,10 +50,8 @@ impl SubjectBuilder {
|
|||||||
/// If a subject could not be created or should otherwise not be searched,
|
/// If a subject could not be created or should otherwise not be searched,
|
||||||
/// then this returns `None` after emitting any relevant log messages.
|
/// then this returns `None` after emitting any relevant log messages.
|
||||||
pub fn build(&self, dent: DirEntry) -> Option<Subject> {
|
pub fn build(&self, dent: DirEntry) -> Option<Subject> {
|
||||||
let subj = Subject {
|
let subj =
|
||||||
dent: dent,
|
Subject { dent, strip_dot_prefix: self.config.strip_dot_prefix };
|
||||||
strip_dot_prefix: self.config.strip_dot_prefix,
|
|
||||||
};
|
|
||||||
if let Some(ignore_err) = subj.dent.error() {
|
if let Some(ignore_err) = subj.dent.error() {
|
||||||
ignore_message!("{}", ignore_err);
|
ignore_message!("{}", ignore_err);
|
||||||
}
|
}
|
||||||
@@ -78,9 +74,9 @@ impl SubjectBuilder {
|
|||||||
log::debug!(
|
log::debug!(
|
||||||
"ignoring {}: failed to pass subject filter: \
|
"ignoring {}: failed to pass subject filter: \
|
||||||
file type: {:?}, metadata: {:?}",
|
file type: {:?}, metadata: {:?}",
|
||||||
subj.dent.path().display(),
|
subj.dent.path().display(),
|
||||||
subj.dent.file_type(),
|
subj.dent.file_type(),
|
||||||
subj.dent.metadata()
|
subj.dent.metadata()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
None
|
None
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "globset"
|
name = "globset"
|
||||||
version = "0.4.4" #:version
|
version = "0.4.5" #:version
|
||||||
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
Cross platform single glob and glob set matching. Glob set matching is the
|
Cross platform single glob and glob set matching. Glob set matching is the
|
||||||
@@ -8,8 +8,8 @@ process of matching one or more glob patterns against a single candidate path
|
|||||||
simultaneously, and returning all of the globs that matched.
|
simultaneously, and returning all of the globs that matched.
|
||||||
"""
|
"""
|
||||||
documentation = "https://docs.rs/globset"
|
documentation = "https://docs.rs/globset"
|
||||||
homepage = "https://github.com/BurntSushi/ripgrep/tree/master/globset"
|
homepage = "https://github.com/BurntSushi/ripgrep/tree/master/crates/globset"
|
||||||
repository = "https://github.com/BurntSushi/ripgrep/tree/master/globset"
|
repository = "https://github.com/BurntSushi/ripgrep/tree/master/crates/globset"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["regex", "glob", "multiple", "set", "pattern"]
|
keywords = ["regex", "glob", "multiple", "set", "pattern"]
|
||||||
license = "Unlicense/MIT"
|
license = "Unlicense/MIT"
|
||||||
@@ -24,9 +24,13 @@ bstr = { version = "0.2.0", default-features = false, features = ["std"] }
|
|||||||
fnv = "1.0.6"
|
fnv = "1.0.6"
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
regex = "1.1.5"
|
regex = "1.1.5"
|
||||||
|
serde = { version = "1.0.104", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
glob = "0.3.0"
|
glob = "0.3.0"
|
||||||
|
lazy_static = "1"
|
||||||
|
serde_json = "1.0.45"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
simd-accel = []
|
simd-accel = []
|
||||||
|
serde1 = ["serde"]
|
@@ -29,6 +29,10 @@ and this to your crate root:
|
|||||||
extern crate globset;
|
extern crate globset;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* `serde1`: Enables implementing Serde traits on the `Glob` type.
|
||||||
|
|
||||||
### Example: one glob
|
### Example: one glob
|
||||||
|
|
||||||
This example shows how to match a single glob against a single file path.
|
This example shows how to match a single glob against a single file path.
|
@@ -6,14 +6,9 @@ tool itself, see the benchsuite directory.
|
|||||||
|
|
||||||
extern crate glob;
|
extern crate glob;
|
||||||
extern crate globset;
|
extern crate globset;
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
use std::ffi::OsStr;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use globset::{Candidate, Glob, GlobMatcher, GlobSet, GlobSetBuilder};
|
use globset::{Candidate, Glob, GlobMatcher, GlobSet, GlobSetBuilder};
|
||||||
|
|
||||||
const EXT: &'static str = "some/a/bigger/path/to/the/crazy/needle.txt";
|
const EXT: &'static str = "some/a/bigger/path/to/the/crazy/needle.txt";
|
@@ -2,13 +2,13 @@ use std::fmt;
|
|||||||
use std::hash;
|
use std::hash;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::path::{Path, is_separator};
|
use std::path::{is_separator, Path};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use regex;
|
use regex;
|
||||||
use regex::bytes::Regex;
|
use regex::bytes::Regex;
|
||||||
|
|
||||||
use {Candidate, Error, ErrorKind, new_regex};
|
use {new_regex, Candidate, Error, ErrorKind};
|
||||||
|
|
||||||
/// Describes a matching strategy for a particular pattern.
|
/// Describes a matching strategy for a particular pattern.
|
||||||
///
|
///
|
||||||
@@ -85,16 +85,16 @@ pub struct Glob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Glob {
|
impl PartialEq for Glob {
|
||||||
fn eq(&self, other: &Glob) -> bool {
|
fn eq(&self, other: &Glob) -> bool {
|
||||||
self.glob == other.glob && self.opts == other.opts
|
self.glob == other.glob && self.opts == other.opts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl hash::Hash for Glob {
|
impl hash::Hash for Glob {
|
||||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||||
self.glob.hash(state);
|
self.glob.hash(state);
|
||||||
self.opts.hash(state);
|
self.opts.hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Glob {
|
impl fmt::Display for Glob {
|
||||||
@@ -103,6 +103,14 @@ impl fmt::Display for Glob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl str::FromStr for Glob {
|
||||||
|
type Err = Error;
|
||||||
|
|
||||||
|
fn from_str(glob: &str) -> Result<Self, Self::Err> {
|
||||||
|
Self::new(glob)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A matcher for a single pattern.
|
/// A matcher for a single pattern.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct GlobMatcher {
|
pub struct GlobMatcher {
|
||||||
@@ -122,6 +130,11 @@ impl GlobMatcher {
|
|||||||
pub fn is_match_candidate(&self, path: &Candidate) -> bool {
|
pub fn is_match_candidate(&self, path: &Candidate) -> bool {
|
||||||
self.re.is_match(&path.path)
|
self.re.is_match(&path.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the `Glob` used to compile this matcher.
|
||||||
|
pub fn glob(&self) -> &Glob {
|
||||||
|
&self.pat
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A strategic matcher for a single pattern.
|
/// A strategic matcher for a single pattern.
|
||||||
@@ -214,11 +227,15 @@ struct Tokens(Vec<Token>);
|
|||||||
|
|
||||||
impl Deref for Tokens {
|
impl Deref for Tokens {
|
||||||
type Target = Vec<Token>;
|
type Target = Vec<Token>;
|
||||||
fn deref(&self) -> &Vec<Token> { &self.0 }
|
fn deref(&self) -> &Vec<Token> {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for Tokens {
|
impl DerefMut for Tokens {
|
||||||
fn deref_mut(&mut self) -> &mut Vec<Token> { &mut self.0 }
|
fn deref_mut(&mut self) -> &mut Vec<Token> {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
@@ -229,10 +246,7 @@ enum Token {
|
|||||||
RecursivePrefix,
|
RecursivePrefix,
|
||||||
RecursiveSuffix,
|
RecursiveSuffix,
|
||||||
RecursiveZeroOrMore,
|
RecursiveZeroOrMore,
|
||||||
Class {
|
Class { negated: bool, ranges: Vec<(char, char)> },
|
||||||
negated: bool,
|
|
||||||
ranges: Vec<(char, char)>,
|
|
||||||
},
|
|
||||||
Alternates(Vec<Tokens>),
|
Alternates(Vec<Tokens>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,12 +258,9 @@ impl Glob {
|
|||||||
|
|
||||||
/// Returns a matcher for this pattern.
|
/// Returns a matcher for this pattern.
|
||||||
pub fn compile_matcher(&self) -> GlobMatcher {
|
pub fn compile_matcher(&self) -> GlobMatcher {
|
||||||
let re = new_regex(&self.re)
|
let re =
|
||||||
.expect("regex compilation shouldn't fail");
|
new_regex(&self.re).expect("regex compilation shouldn't fail");
|
||||||
GlobMatcher {
|
GlobMatcher { pat: self.clone(), re: re }
|
||||||
pat: self.clone(),
|
|
||||||
re: re,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a strategic matcher.
|
/// Returns a strategic matcher.
|
||||||
@@ -260,13 +271,9 @@ impl Glob {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn compile_strategic_matcher(&self) -> GlobStrategic {
|
fn compile_strategic_matcher(&self) -> GlobStrategic {
|
||||||
let strategy = MatchStrategy::new(self);
|
let strategy = MatchStrategy::new(self);
|
||||||
let re = new_regex(&self.re)
|
let re =
|
||||||
.expect("regex compilation shouldn't fail");
|
new_regex(&self.re).expect("regex compilation shouldn't fail");
|
||||||
GlobStrategic {
|
GlobStrategic { strategy: strategy, pat: self.clone(), re: re }
|
||||||
strategy: strategy,
|
|
||||||
pat: self.clone(),
|
|
||||||
re: re,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the original glob pattern used to build this pattern.
|
/// Returns the original glob pattern used to build this pattern.
|
||||||
@@ -524,7 +531,7 @@ impl Glob {
|
|||||||
| Token::RecursiveZeroOrMore => {
|
| Token::RecursiveZeroOrMore => {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Token::Class{..} | Token::Alternates(..) => {
|
Token::Class { .. } | Token::Alternates(..) => {
|
||||||
// We *could* be a little smarter here, but either one
|
// We *could* be a little smarter here, but either one
|
||||||
// of these is going to prevent our literal optimizations
|
// of these is going to prevent our literal optimizations
|
||||||
// anyway, so give up.
|
// anyway, so give up.
|
||||||
@@ -561,10 +568,7 @@ impl<'a> GlobBuilder<'a> {
|
|||||||
///
|
///
|
||||||
/// The pattern is not compiled until `build` is called.
|
/// The pattern is not compiled until `build` is called.
|
||||||
pub fn new(glob: &'a str) -> GlobBuilder<'a> {
|
pub fn new(glob: &'a str) -> GlobBuilder<'a> {
|
||||||
GlobBuilder {
|
GlobBuilder { glob: glob, opts: GlobOptions::default() }
|
||||||
glob: glob,
|
|
||||||
opts: GlobOptions::default(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses and builds the pattern.
|
/// Parses and builds the pattern.
|
||||||
@@ -862,25 +866,22 @@ impl<'a> Parser<'a> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let is_suffix =
|
let is_suffix = match self.peek() {
|
||||||
match self.peek() {
|
None => {
|
||||||
None => {
|
assert!(self.bump().is_none());
|
||||||
assert!(self.bump().is_none());
|
true
|
||||||
true
|
}
|
||||||
}
|
Some(',') | Some('}') if self.stack.len() >= 2 => true,
|
||||||
Some(',') | Some('}') if self.stack.len() >= 2 => {
|
Some(c) if is_separator(c) => {
|
||||||
true
|
assert!(self.bump().map(is_separator).unwrap_or(false));
|
||||||
}
|
false
|
||||||
Some(c) if is_separator(c) => {
|
}
|
||||||
assert!(self.bump().map(is_separator).unwrap_or(false));
|
_ => {
|
||||||
false
|
self.push_token(Token::ZeroOrMore)?;
|
||||||
}
|
self.push_token(Token::ZeroOrMore)?;
|
||||||
_ => {
|
return Ok(());
|
||||||
self.push_token(Token::ZeroOrMore)?;
|
}
|
||||||
self.push_token(Token::ZeroOrMore)?;
|
};
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
match self.pop_token()? {
|
match self.pop_token()? {
|
||||||
Token::RecursivePrefix => {
|
Token::RecursivePrefix => {
|
||||||
self.push_token(Token::RecursivePrefix)?;
|
self.push_token(Token::RecursivePrefix)?;
|
||||||
@@ -960,7 +961,10 @@ impl<'a> Parser<'a> {
|
|||||||
// invariant: in_range is only set when there is
|
// invariant: in_range is only set when there is
|
||||||
// already at least one character seen.
|
// already at least one character seen.
|
||||||
add_to_last_range(
|
add_to_last_range(
|
||||||
&self.glob, ranges.last_mut().unwrap(), c)?;
|
&self.glob,
|
||||||
|
ranges.last_mut().unwrap(),
|
||||||
|
c,
|
||||||
|
)?;
|
||||||
} else {
|
} else {
|
||||||
ranges.push((c, c));
|
ranges.push((c, c));
|
||||||
}
|
}
|
||||||
@@ -974,10 +978,7 @@ impl<'a> Parser<'a> {
|
|||||||
// it as a literal.
|
// it as a literal.
|
||||||
ranges.push(('-', '-'));
|
ranges.push(('-', '-'));
|
||||||
}
|
}
|
||||||
self.push_token(Token::Class {
|
self.push_token(Token::Class { negated: negated, ranges: ranges })
|
||||||
negated: negated,
|
|
||||||
ranges: ranges,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bump(&mut self) -> Option<char> {
|
fn bump(&mut self) -> Option<char> {
|
||||||
@@ -1006,9 +1007,9 @@ fn ends_with(needle: &[u8], haystack: &[u8]) -> bool {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use {GlobSetBuilder, ErrorKind};
|
|
||||||
use super::{Glob, GlobBuilder, Token};
|
|
||||||
use super::Token::*;
|
use super::Token::*;
|
||||||
|
use super::{Glob, GlobBuilder, Token};
|
||||||
|
use {ErrorKind, GlobSetBuilder};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
struct Options {
|
struct Options {
|
||||||
@@ -1024,7 +1025,7 @@ mod tests {
|
|||||||
let pat = Glob::new($pat).unwrap();
|
let pat = Glob::new($pat).unwrap();
|
||||||
assert_eq!($tokens, pat.tokens.0);
|
assert_eq!($tokens, pat.tokens.0);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! syntaxerr {
|
macro_rules! syntaxerr {
|
||||||
@@ -1034,7 +1035,7 @@ mod tests {
|
|||||||
let err = Glob::new($pat).unwrap_err();
|
let err = Glob::new($pat).unwrap_err();
|
||||||
assert_eq!(&$err, err.kind());
|
assert_eq!(&$err, err.kind());
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! toregex {
|
macro_rules! toregex {
|
||||||
@@ -1116,7 +1117,9 @@ mod tests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn s(string: &str) -> String { string.to_string() }
|
fn s(string: &str) -> String {
|
||||||
|
string.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
fn class(s: char, e: char) -> Token {
|
fn class(s: char, e: char) -> Token {
|
||||||
Class { negated: false, ranges: vec![(s, e)] }
|
Class { negated: false, ranges: vec![(s, e)] }
|
||||||
@@ -1140,16 +1143,20 @@ mod tests {
|
|||||||
syntax!(any2, "a?b", vec![Literal('a'), Any, Literal('b')]);
|
syntax!(any2, "a?b", vec![Literal('a'), Any, Literal('b')]);
|
||||||
syntax!(seq1, "*", vec![ZeroOrMore]);
|
syntax!(seq1, "*", vec![ZeroOrMore]);
|
||||||
syntax!(seq2, "a*b", vec![Literal('a'), ZeroOrMore, Literal('b')]);
|
syntax!(seq2, "a*b", vec![Literal('a'), ZeroOrMore, Literal('b')]);
|
||||||
syntax!(seq3, "*a*b*", vec![
|
syntax!(
|
||||||
ZeroOrMore, Literal('a'), ZeroOrMore, Literal('b'), ZeroOrMore,
|
seq3,
|
||||||
]);
|
"*a*b*",
|
||||||
|
vec![ZeroOrMore, Literal('a'), ZeroOrMore, Literal('b'), ZeroOrMore,]
|
||||||
|
);
|
||||||
syntax!(rseq1, "**", vec![RecursivePrefix]);
|
syntax!(rseq1, "**", vec![RecursivePrefix]);
|
||||||
syntax!(rseq2, "**/", vec![RecursivePrefix]);
|
syntax!(rseq2, "**/", vec![RecursivePrefix]);
|
||||||
syntax!(rseq3, "/**", vec![RecursiveSuffix]);
|
syntax!(rseq3, "/**", vec![RecursiveSuffix]);
|
||||||
syntax!(rseq4, "/**/", vec![RecursiveZeroOrMore]);
|
syntax!(rseq4, "/**/", vec![RecursiveZeroOrMore]);
|
||||||
syntax!(rseq5, "a/**/b", vec![
|
syntax!(
|
||||||
Literal('a'), RecursiveZeroOrMore, Literal('b'),
|
rseq5,
|
||||||
]);
|
"a/**/b",
|
||||||
|
vec![Literal('a'), RecursiveZeroOrMore, Literal('b'),]
|
||||||
|
);
|
||||||
syntax!(cls1, "[a]", vec![class('a', 'a')]);
|
syntax!(cls1, "[a]", vec![class('a', 'a')]);
|
||||||
syntax!(cls2, "[!a]", vec![classn('a', 'a')]);
|
syntax!(cls2, "[!a]", vec![classn('a', 'a')]);
|
||||||
syntax!(cls3, "[a-z]", vec![class('a', 'z')]);
|
syntax!(cls3, "[a-z]", vec![class('a', 'z')]);
|
||||||
@@ -1161,9 +1168,11 @@ mod tests {
|
|||||||
syntax!(cls9, "[a-]", vec![rclass(&[('a', 'a'), ('-', '-')])]);
|
syntax!(cls9, "[a-]", vec![rclass(&[('a', 'a'), ('-', '-')])]);
|
||||||
syntax!(cls10, "[-a-z]", vec![rclass(&[('-', '-'), ('a', 'z')])]);
|
syntax!(cls10, "[-a-z]", vec![rclass(&[('-', '-'), ('a', 'z')])]);
|
||||||
syntax!(cls11, "[a-z-]", vec![rclass(&[('a', 'z'), ('-', '-')])]);
|
syntax!(cls11, "[a-z-]", vec![rclass(&[('a', 'z'), ('-', '-')])]);
|
||||||
syntax!(cls12, "[-a-z-]", vec![
|
syntax!(
|
||||||
rclass(&[('-', '-'), ('a', 'z'), ('-', '-')]),
|
cls12,
|
||||||
]);
|
"[-a-z-]",
|
||||||
|
vec![rclass(&[('-', '-'), ('a', 'z'), ('-', '-')]),]
|
||||||
|
);
|
||||||
syntax!(cls13, "[]-z]", vec![class(']', 'z')]);
|
syntax!(cls13, "[]-z]", vec![class(']', 'z')]);
|
||||||
syntax!(cls14, "[--z]", vec![class('-', 'z')]);
|
syntax!(cls14, "[--z]", vec![class('-', 'z')]);
|
||||||
syntax!(cls15, "[ --]", vec![class(' ', '-')]);
|
syntax!(cls15, "[ --]", vec![class(' ', '-')]);
|
||||||
@@ -1181,26 +1190,14 @@ mod tests {
|
|||||||
syntaxerr!(err_range1, "[z-a]", ErrorKind::InvalidRange('z', 'a'));
|
syntaxerr!(err_range1, "[z-a]", ErrorKind::InvalidRange('z', 'a'));
|
||||||
syntaxerr!(err_range2, "[z--]", ErrorKind::InvalidRange('z', '-'));
|
syntaxerr!(err_range2, "[z--]", ErrorKind::InvalidRange('z', '-'));
|
||||||
|
|
||||||
const CASEI: Options = Options {
|
const CASEI: Options =
|
||||||
casei: Some(true),
|
Options { casei: Some(true), litsep: None, bsesc: None };
|
||||||
litsep: None,
|
const SLASHLIT: Options =
|
||||||
bsesc: None,
|
Options { casei: None, litsep: Some(true), bsesc: None };
|
||||||
};
|
const NOBSESC: Options =
|
||||||
const SLASHLIT: Options = Options {
|
Options { casei: None, litsep: None, bsesc: Some(false) };
|
||||||
casei: None,
|
const BSESC: Options =
|
||||||
litsep: Some(true),
|
Options { casei: None, litsep: None, bsesc: Some(true) };
|
||||||
bsesc: None,
|
|
||||||
};
|
|
||||||
const NOBSESC: Options = Options {
|
|
||||||
casei: None,
|
|
||||||
litsep: None,
|
|
||||||
bsesc: Some(false),
|
|
||||||
};
|
|
||||||
const BSESC: Options = Options {
|
|
||||||
casei: None,
|
|
||||||
litsep: None,
|
|
||||||
bsesc: Some(true),
|
|
||||||
};
|
|
||||||
|
|
||||||
toregex!(re_casei, "a", "(?i)^a$", &CASEI);
|
toregex!(re_casei, "a", "(?i)^a$", &CASEI);
|
||||||
|
|
||||||
@@ -1298,8 +1295,11 @@ mod tests {
|
|||||||
matches!(matchpat4, "*hello.txt", "some\\path\\to\\hello.txt");
|
matches!(matchpat4, "*hello.txt", "some\\path\\to\\hello.txt");
|
||||||
matches!(matchpat5, "*hello.txt", "/an/absolute/path/to/hello.txt");
|
matches!(matchpat5, "*hello.txt", "/an/absolute/path/to/hello.txt");
|
||||||
matches!(matchpat6, "*some/path/to/hello.txt", "some/path/to/hello.txt");
|
matches!(matchpat6, "*some/path/to/hello.txt", "some/path/to/hello.txt");
|
||||||
matches!(matchpat7, "*some/path/to/hello.txt",
|
matches!(
|
||||||
"a/bigger/some/path/to/hello.txt");
|
matchpat7,
|
||||||
|
"*some/path/to/hello.txt",
|
||||||
|
"a/bigger/some/path/to/hello.txt"
|
||||||
|
);
|
||||||
|
|
||||||
matches!(matchescape, "_[[]_[]]_[?]_[*]_!_", "_[_]_?_*_!_");
|
matches!(matchescape, "_[[]_[]]_[?]_[*]_!_", "_[_]_?_*_!_");
|
||||||
|
|
||||||
@@ -1362,28 +1362,44 @@ mod tests {
|
|||||||
nmatches!(matchnot15, "[!-]", "-");
|
nmatches!(matchnot15, "[!-]", "-");
|
||||||
nmatches!(matchnot16, "*hello.txt", "hello.txt-and-then-some");
|
nmatches!(matchnot16, "*hello.txt", "hello.txt-and-then-some");
|
||||||
nmatches!(matchnot17, "*hello.txt", "goodbye.txt");
|
nmatches!(matchnot17, "*hello.txt", "goodbye.txt");
|
||||||
nmatches!(matchnot18, "*some/path/to/hello.txt",
|
nmatches!(
|
||||||
"some/path/to/hello.txt-and-then-some");
|
matchnot18,
|
||||||
nmatches!(matchnot19, "*some/path/to/hello.txt",
|
"*some/path/to/hello.txt",
|
||||||
"some/other/path/to/hello.txt");
|
"some/path/to/hello.txt-and-then-some"
|
||||||
|
);
|
||||||
|
nmatches!(
|
||||||
|
matchnot19,
|
||||||
|
"*some/path/to/hello.txt",
|
||||||
|
"some/other/path/to/hello.txt"
|
||||||
|
);
|
||||||
nmatches!(matchnot20, "a", "foo/a");
|
nmatches!(matchnot20, "a", "foo/a");
|
||||||
nmatches!(matchnot21, "./foo", "foo");
|
nmatches!(matchnot21, "./foo", "foo");
|
||||||
nmatches!(matchnot22, "**/foo", "foofoo");
|
nmatches!(matchnot22, "**/foo", "foofoo");
|
||||||
nmatches!(matchnot23, "**/foo/bar", "foofoo/bar");
|
nmatches!(matchnot23, "**/foo/bar", "foofoo/bar");
|
||||||
nmatches!(matchnot24, "/*.c", "mozilla-sha1/sha1.c");
|
nmatches!(matchnot24, "/*.c", "mozilla-sha1/sha1.c");
|
||||||
nmatches!(matchnot25, "*.c", "mozilla-sha1/sha1.c", SLASHLIT);
|
nmatches!(matchnot25, "*.c", "mozilla-sha1/sha1.c", SLASHLIT);
|
||||||
nmatches!(matchnot26, "**/m4/ltoptions.m4",
|
nmatches!(
|
||||||
"csharp/src/packages/repositories.config", SLASHLIT);
|
matchnot26,
|
||||||
|
"**/m4/ltoptions.m4",
|
||||||
|
"csharp/src/packages/repositories.config",
|
||||||
|
SLASHLIT
|
||||||
|
);
|
||||||
nmatches!(matchnot27, "a[^0-9]b", "a0b");
|
nmatches!(matchnot27, "a[^0-9]b", "a0b");
|
||||||
nmatches!(matchnot28, "a[^0-9]b", "a9b");
|
nmatches!(matchnot28, "a[^0-9]b", "a9b");
|
||||||
nmatches!(matchnot29, "[^-]", "-");
|
nmatches!(matchnot29, "[^-]", "-");
|
||||||
nmatches!(matchnot30, "some/*/needle.txt", "some/needle.txt");
|
nmatches!(matchnot30, "some/*/needle.txt", "some/needle.txt");
|
||||||
nmatches!(
|
nmatches!(
|
||||||
matchrec31,
|
matchrec31,
|
||||||
"some/*/needle.txt", "some/one/two/needle.txt", SLASHLIT);
|
"some/*/needle.txt",
|
||||||
|
"some/one/two/needle.txt",
|
||||||
|
SLASHLIT
|
||||||
|
);
|
||||||
nmatches!(
|
nmatches!(
|
||||||
matchrec32,
|
matchrec32,
|
||||||
"some/*/needle.txt", "some/one/two/three/needle.txt", SLASHLIT);
|
"some/*/needle.txt",
|
||||||
|
"some/one/two/three/needle.txt",
|
||||||
|
SLASHLIT
|
||||||
|
);
|
||||||
|
|
||||||
macro_rules! extract {
|
macro_rules! extract {
|
||||||
($which:ident, $name:ident, $pat:expr, $expect:expr) => {
|
($which:ident, $name:ident, $pat:expr, $expect:expr) => {
|
||||||
@@ -1445,19 +1461,27 @@ mod tests {
|
|||||||
literal!(extract_lit7, "foo/bar", Some(s("foo/bar")));
|
literal!(extract_lit7, "foo/bar", Some(s("foo/bar")));
|
||||||
literal!(extract_lit8, "**/foo/bar", None);
|
literal!(extract_lit8, "**/foo/bar", None);
|
||||||
|
|
||||||
basetokens!(extract_basetoks1, "**/foo", Some(&*vec![
|
basetokens!(
|
||||||
Literal('f'), Literal('o'), Literal('o'),
|
extract_basetoks1,
|
||||||
]));
|
"**/foo",
|
||||||
|
Some(&*vec![Literal('f'), Literal('o'), Literal('o'),])
|
||||||
|
);
|
||||||
basetokens!(extract_basetoks2, "**/foo", None, CASEI);
|
basetokens!(extract_basetoks2, "**/foo", None, CASEI);
|
||||||
basetokens!(extract_basetoks3, "**/foo", Some(&*vec![
|
basetokens!(
|
||||||
Literal('f'), Literal('o'), Literal('o'),
|
extract_basetoks3,
|
||||||
]), SLASHLIT);
|
"**/foo",
|
||||||
|
Some(&*vec![Literal('f'), Literal('o'), Literal('o'),]),
|
||||||
|
SLASHLIT
|
||||||
|
);
|
||||||
basetokens!(extract_basetoks4, "*foo", None, SLASHLIT);
|
basetokens!(extract_basetoks4, "*foo", None, SLASHLIT);
|
||||||
basetokens!(extract_basetoks5, "*foo", None);
|
basetokens!(extract_basetoks5, "*foo", None);
|
||||||
basetokens!(extract_basetoks6, "**/fo*o", None);
|
basetokens!(extract_basetoks6, "**/fo*o", None);
|
||||||
basetokens!(extract_basetoks7, "**/fo*o", Some(&*vec![
|
basetokens!(
|
||||||
Literal('f'), Literal('o'), ZeroOrMore, Literal('o'),
|
extract_basetoks7,
|
||||||
]), SLASHLIT);
|
"**/fo*o",
|
||||||
|
Some(&*vec![Literal('f'), Literal('o'), ZeroOrMore, Literal('o'),]),
|
||||||
|
SLASHLIT
|
||||||
|
);
|
||||||
|
|
||||||
ext!(extract_ext1, "**/*.rs", Some(s(".rs")));
|
ext!(extract_ext1, "**/*.rs", Some(s(".rs")));
|
||||||
ext!(extract_ext2, "**/*.rs.bak", None);
|
ext!(extract_ext2, "**/*.rs.bak", None);
|
@@ -110,6 +110,9 @@ extern crate fnv;
|
|||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
|
#[cfg(feature = "serde1")]
|
||||||
|
extern crate serde;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::error::Error as StdError;
|
use std::error::Error as StdError;
|
||||||
@@ -119,16 +122,19 @@ use std::path::Path;
|
|||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use aho_corasick::AhoCorasick;
|
use aho_corasick::AhoCorasick;
|
||||||
use bstr::{B, ByteSlice, ByteVec};
|
use bstr::{ByteSlice, ByteVec, B};
|
||||||
use regex::bytes::{Regex, RegexBuilder, RegexSet};
|
use regex::bytes::{Regex, RegexBuilder, RegexSet};
|
||||||
|
|
||||||
use pathutil::{file_name, file_name_ext, normalize_path};
|
|
||||||
use glob::MatchStrategy;
|
use glob::MatchStrategy;
|
||||||
pub use glob::{Glob, GlobBuilder, GlobMatcher};
|
pub use glob::{Glob, GlobBuilder, GlobMatcher};
|
||||||
|
use pathutil::{file_name, file_name_ext, normalize_path};
|
||||||
|
|
||||||
mod glob;
|
mod glob;
|
||||||
mod pathutil;
|
mod pathutil;
|
||||||
|
|
||||||
|
#[cfg(feature = "serde1")]
|
||||||
|
mod serde_impl;
|
||||||
|
|
||||||
/// Represents an error that can occur when parsing a glob pattern.
|
/// Represents an error that can occur when parsing a glob pattern.
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
@@ -202,9 +208,7 @@ impl ErrorKind {
|
|||||||
ErrorKind::UnclosedClass => {
|
ErrorKind::UnclosedClass => {
|
||||||
"unclosed character class; missing ']'"
|
"unclosed character class; missing ']'"
|
||||||
}
|
}
|
||||||
ErrorKind::InvalidRange(_, _) => {
|
ErrorKind::InvalidRange(_, _) => "invalid character range",
|
||||||
"invalid character range"
|
|
||||||
}
|
|
||||||
ErrorKind::UnopenedAlternates => {
|
ErrorKind::UnopenedAlternates => {
|
||||||
"unopened alternate group; missing '{' \
|
"unopened alternate group; missing '{' \
|
||||||
(maybe escape '}' with '[}]'?)"
|
(maybe escape '}' with '[}]'?)"
|
||||||
@@ -216,9 +220,7 @@ impl ErrorKind {
|
|||||||
ErrorKind::NestedAlternates => {
|
ErrorKind::NestedAlternates => {
|
||||||
"nested alternate groups are not allowed"
|
"nested alternate groups are not allowed"
|
||||||
}
|
}
|
||||||
ErrorKind::DanglingEscape => {
|
ErrorKind::DanglingEscape => "dangling '\\'",
|
||||||
"dangling '\\'"
|
|
||||||
}
|
|
||||||
ErrorKind::Regex(ref err) => err,
|
ErrorKind::Regex(ref err) => err,
|
||||||
ErrorKind::__Nonexhaustive => unreachable!(),
|
ErrorKind::__Nonexhaustive => unreachable!(),
|
||||||
}
|
}
|
||||||
@@ -245,9 +247,7 @@ impl fmt::Display for ErrorKind {
|
|||||||
| ErrorKind::UnclosedAlternates
|
| ErrorKind::UnclosedAlternates
|
||||||
| ErrorKind::NestedAlternates
|
| ErrorKind::NestedAlternates
|
||||||
| ErrorKind::DanglingEscape
|
| ErrorKind::DanglingEscape
|
||||||
| ErrorKind::Regex(_) => {
|
| ErrorKind::Regex(_) => write!(f, "{}", self.description()),
|
||||||
write!(f, "{}", self.description())
|
|
||||||
}
|
|
||||||
ErrorKind::InvalidRange(s, e) => {
|
ErrorKind::InvalidRange(s, e) => {
|
||||||
write!(f, "invalid range; '{}' > '{}'", s, e)
|
write!(f, "invalid range; '{}' > '{}'", s, e)
|
||||||
}
|
}
|
||||||
@@ -262,21 +262,20 @@ fn new_regex(pat: &str) -> Result<Regex, Error> {
|
|||||||
.size_limit(10 * (1 << 20))
|
.size_limit(10 * (1 << 20))
|
||||||
.dfa_size_limit(10 * (1 << 20))
|
.dfa_size_limit(10 * (1 << 20))
|
||||||
.build()
|
.build()
|
||||||
.map_err(|err| {
|
.map_err(|err| Error {
|
||||||
Error {
|
glob: Some(pat.to_string()),
|
||||||
glob: Some(pat.to_string()),
|
kind: ErrorKind::Regex(err.to_string()),
|
||||||
kind: ErrorKind::Regex(err.to_string()),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_regex_set<I, S>(pats: I) -> Result<RegexSet, Error>
|
fn new_regex_set<I, S>(pats: I) -> Result<RegexSet, Error>
|
||||||
where S: AsRef<str>, I: IntoIterator<Item=S> {
|
where
|
||||||
RegexSet::new(pats).map_err(|err| {
|
S: AsRef<str>,
|
||||||
Error {
|
I: IntoIterator<Item = S>,
|
||||||
glob: None,
|
{
|
||||||
kind: ErrorKind::Regex(err.to_string()),
|
RegexSet::new(pats).map_err(|err| Error {
|
||||||
}
|
glob: None,
|
||||||
|
kind: ErrorKind::Regex(err.to_string()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,10 +293,7 @@ impl GlobSet {
|
|||||||
/// Create an empty `GlobSet`. An empty set matches nothing.
|
/// Create an empty `GlobSet`. An empty set matches nothing.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn empty() -> GlobSet {
|
pub fn empty() -> GlobSet {
|
||||||
GlobSet {
|
GlobSet { len: 0, strats: vec![] }
|
||||||
len: 0,
|
|
||||||
strats: vec![],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this set is empty, and therefore matches nothing.
|
/// Returns true if this set is empty, and therefore matches nothing.
|
||||||
@@ -432,11 +428,17 @@ impl GlobSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug!("built glob set; {} literals, {} basenames, {} extensions, \
|
debug!(
|
||||||
|
"built glob set; {} literals, {} basenames, {} extensions, \
|
||||||
{} prefixes, {} suffixes, {} required extensions, {} regexes",
|
{} prefixes, {} suffixes, {} required extensions, {} regexes",
|
||||||
lits.0.len(), base_lits.0.len(), exts.0.len(),
|
lits.0.len(),
|
||||||
prefixes.literals.len(), suffixes.literals.len(),
|
base_lits.0.len(),
|
||||||
required_exts.0.len(), regexes.literals.len());
|
exts.0.len(),
|
||||||
|
prefixes.literals.len(),
|
||||||
|
suffixes.literals.len(),
|
||||||
|
required_exts.0.len(),
|
||||||
|
regexes.literals.len()
|
||||||
|
);
|
||||||
Ok(GlobSet {
|
Ok(GlobSet {
|
||||||
len: pats.len(),
|
len: pats.len(),
|
||||||
strats: vec![
|
strats: vec![
|
||||||
@@ -446,7 +448,8 @@ impl GlobSet {
|
|||||||
GlobSetMatchStrategy::Suffix(suffixes.suffix()),
|
GlobSetMatchStrategy::Suffix(suffixes.suffix()),
|
||||||
GlobSetMatchStrategy::Prefix(prefixes.prefix()),
|
GlobSetMatchStrategy::Prefix(prefixes.prefix()),
|
||||||
GlobSetMatchStrategy::RequiredExtension(
|
GlobSetMatchStrategy::RequiredExtension(
|
||||||
required_exts.build()?),
|
required_exts.build()?,
|
||||||
|
),
|
||||||
GlobSetMatchStrategy::Regex(regexes.regex_set()?),
|
GlobSetMatchStrategy::Regex(regexes.regex_set()?),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@@ -501,11 +504,7 @@ impl<'a> Candidate<'a> {
|
|||||||
let path = normalize_path(Vec::from_path_lossy(path.as_ref()));
|
let path = normalize_path(Vec::from_path_lossy(path.as_ref()));
|
||||||
let basename = file_name(&path).unwrap_or(Cow::Borrowed(B("")));
|
let basename = file_name(&path).unwrap_or(Cow::Borrowed(B("")));
|
||||||
let ext = file_name_ext(&basename).unwrap_or(Cow::Borrowed(B("")));
|
let ext = file_name_ext(&basename).unwrap_or(Cow::Borrowed(B("")));
|
||||||
Candidate {
|
Candidate { path: path, basename: basename, ext: ext }
|
||||||
path: path,
|
|
||||||
basename: basename,
|
|
||||||
ext: ext,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_prefix(&self, max: usize) -> &[u8] {
|
fn path_prefix(&self, max: usize) -> &[u8] {
|
||||||
@@ -767,11 +766,7 @@ struct MultiStrategyBuilder {
|
|||||||
|
|
||||||
impl MultiStrategyBuilder {
|
impl MultiStrategyBuilder {
|
||||||
fn new() -> MultiStrategyBuilder {
|
fn new() -> MultiStrategyBuilder {
|
||||||
MultiStrategyBuilder {
|
MultiStrategyBuilder { literals: vec![], map: vec![], longest: 0 }
|
||||||
literals: vec![],
|
|
||||||
map: vec![],
|
|
||||||
longest: 0,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add(&mut self, global_index: usize, literal: String) {
|
fn add(&mut self, global_index: usize, literal: String) {
|
@@ -84,7 +84,7 @@ pub fn normalize_path(mut path: Cow<[u8]>) -> Cow<[u8]> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use bstr::{B, ByteVec};
|
use bstr::{ByteVec, B};
|
||||||
|
|
||||||
use super::{file_name_ext, normalize_path};
|
use super::{file_name_ext, normalize_path};
|
||||||
|
|
38
crates/globset/src/serde_impl.rs
Normal file
38
crates/globset/src/serde_impl.rs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
use serde::de::Error;
|
||||||
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
|
use Glob;
|
||||||
|
|
||||||
|
impl Serialize for Glob {
|
||||||
|
fn serialize<S: Serializer>(
|
||||||
|
&self,
|
||||||
|
serializer: S,
|
||||||
|
) -> Result<S::Ok, S::Error> {
|
||||||
|
serializer.serialize_str(self.glob())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for Glob {
|
||||||
|
fn deserialize<D: Deserializer<'de>>(
|
||||||
|
deserializer: D,
|
||||||
|
) -> Result<Self, D::Error> {
|
||||||
|
let glob = <&str as Deserialize>::deserialize(deserializer)?;
|
||||||
|
Glob::new(glob).map_err(D::Error::custom)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use Glob;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn glob_json_works() {
|
||||||
|
let test_glob = Glob::new("src/**/*.rs").unwrap();
|
||||||
|
|
||||||
|
let ser = serde_json::to_string(&test_glob).unwrap();
|
||||||
|
assert_eq!(ser, "\"src/**/*.rs\"");
|
||||||
|
|
||||||
|
let de: Glob = serde_json::from_str(&ser).unwrap();
|
||||||
|
assert_eq!(test_glob, de);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,24 +1,24 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "grep"
|
name = "grep"
|
||||||
version = "0.2.4" #:version
|
version = "0.2.5" #:version
|
||||||
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
Fast line oriented regex searching as a library.
|
Fast line oriented regex searching as a library.
|
||||||
"""
|
"""
|
||||||
documentation = "http://burntsushi.net/rustdoc/grep/"
|
documentation = "http://burntsushi.net/rustdoc/grep/"
|
||||||
homepage = "https://github.com/BurntSushi/ripgrep"
|
homepage = "https://github.com/BurntSushi/ripgrep/tree/master/crates/grep"
|
||||||
repository = "https://github.com/BurntSushi/ripgrep"
|
repository = "https://github.com/BurntSushi/ripgrep/tree/master/crates/grep"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["regex", "grep", "egrep", "search", "pattern"]
|
keywords = ["regex", "grep", "egrep", "search", "pattern"]
|
||||||
license = "Unlicense/MIT"
|
license = "Unlicense/MIT"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
grep-cli = { version = "0.1.2", path = "../grep-cli" }
|
grep-cli = { version = "0.1.4", path = "../cli" }
|
||||||
grep-matcher = { version = "0.1.2", path = "../grep-matcher" }
|
grep-matcher = { version = "0.1.4", path = "../matcher" }
|
||||||
grep-pcre2 = { version = "0.1.3", path = "../grep-pcre2", optional = true }
|
grep-pcre2 = { version = "0.1.4", path = "../pcre2", optional = true }
|
||||||
grep-printer = { version = "0.1.2", path = "../grep-printer" }
|
grep-printer = { version = "0.1.4", path = "../printer" }
|
||||||
grep-regex = { version = "0.1.3", path = "../grep-regex" }
|
grep-regex = { version = "0.1.6", path = "../regex" }
|
||||||
grep-searcher = { version = "0.1.4", path = "../grep-searcher" }
|
grep-searcher = { version = "0.1.7", path = "../searcher" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
termcolor = "1.0.4"
|
termcolor = "1.0.4"
|
@@ -40,13 +40,11 @@ fn search(pattern: &str, paths: &[OsString]) -> Result<(), Box<dyn Error>> {
|
|||||||
.build();
|
.build();
|
||||||
let mut printer = StandardBuilder::new()
|
let mut printer = StandardBuilder::new()
|
||||||
.color_specs(ColorSpecs::default_with_color())
|
.color_specs(ColorSpecs::default_with_color())
|
||||||
.build(cli::stdout(
|
.build(cli::stdout(if cli::is_tty_stdout() {
|
||||||
if cli::is_tty_stdout() {
|
ColorChoice::Auto
|
||||||
ColorChoice::Auto
|
} else {
|
||||||
} else {
|
ColorChoice::Never
|
||||||
ColorChoice::Never
|
}));
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
for path in paths {
|
for path in paths {
|
||||||
for result in WalkDir::new(path) {
|
for result in WalkDir::new(path) {
|
@@ -1,14 +1,14 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ignore"
|
name = "ignore"
|
||||||
version = "0.4.10" #:version
|
version = "0.4.12" #:version
|
||||||
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
A fast library for efficiently matching ignore files such as `.gitignore`
|
A fast library for efficiently matching ignore files such as `.gitignore`
|
||||||
against file paths.
|
against file paths.
|
||||||
"""
|
"""
|
||||||
documentation = "https://docs.rs/ignore"
|
documentation = "https://docs.rs/ignore"
|
||||||
homepage = "https://github.com/BurntSushi/ripgrep/tree/master/ignore"
|
homepage = "https://github.com/BurntSushi/ripgrep/tree/master/crates/ignore"
|
||||||
repository = "https://github.com/BurntSushi/ripgrep/tree/master/ignore"
|
repository = "https://github.com/BurntSushi/ripgrep/tree/master/crates/ignore"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["glob", "ignore", "gitignore", "pattern", "file"]
|
keywords = ["glob", "ignore", "gitignore", "pattern", "file"]
|
||||||
license = "Unlicense/MIT"
|
license = "Unlicense/MIT"
|
||||||
@@ -18,14 +18,15 @@ name = "ignore"
|
|||||||
bench = false
|
bench = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crossbeam-channel = "0.3.6"
|
crossbeam-channel = "0.4.0"
|
||||||
|
crossbeam-utils = "0.7.0"
|
||||||
globset = { version = "0.4.3", path = "../globset" }
|
globset = { version = "0.4.3", path = "../globset" }
|
||||||
lazy_static = "1.1"
|
lazy_static = "1.1"
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
memchr = "2.1"
|
memchr = "2.1"
|
||||||
regex = "1.1"
|
regex = "1.1"
|
||||||
same-file = "1.0.4"
|
same-file = "1.0.4"
|
||||||
thread_local = "0.3.6"
|
thread_local = "1"
|
||||||
walkdir = "2.2.7"
|
walkdir = "2.2.7"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.winapi-util]
|
[target.'cfg(windows)'.dependencies.winapi-util]
|
246
crates/ignore/src/default_types.rs
Normal file
246
crates/ignore/src/default_types.rs
Normal file
@@ -0,0 +1,246 @@
|
|||||||
|
/// 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"]),
|
||||||
|
("coq", &["*.v"]),
|
||||||
|
("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"]),
|
||||||
|
("k", &["*.k"]),
|
||||||
|
("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"]),
|
||||||
|
];
|
@@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
|
use std::fs::{File, FileType};
|
||||||
|
use std::io::{self, BufRead};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
@@ -76,6 +78,9 @@ struct IgnoreOptions {
|
|||||||
git_exclude: bool,
|
git_exclude: bool,
|
||||||
/// Whether to ignore files case insensitively
|
/// Whether to ignore files case insensitively
|
||||||
ignore_case_insensitive: bool,
|
ignore_case_insensitive: bool,
|
||||||
|
/// Whether a git repository must be present in order to apply any
|
||||||
|
/// git-related ignore rules.
|
||||||
|
require_git: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignore is a matcher useful for recursively walking one or more directories.
|
/// Ignore is a matcher useful for recursively walking one or more directories.
|
||||||
@@ -152,7 +157,10 @@ impl Ignore {
|
|||||||
///
|
///
|
||||||
/// Note that this can only be called on an `Ignore` matcher with no
|
/// Note that this can only be called on an `Ignore` matcher with no
|
||||||
/// parents (i.e., `is_root` returns `true`). This will panic otherwise.
|
/// 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
|
if !self.0.opts.parents
|
||||||
&& !self.0.opts.git_ignore
|
&& !self.0.opts.git_ignore
|
||||||
&& !self.0.opts.git_exclude
|
&& !self.0.opts.git_exclude
|
||||||
@@ -213,18 +221,29 @@ impl Ignore {
|
|||||||
/// returned if it exists.
|
/// returned if it exists.
|
||||||
///
|
///
|
||||||
/// Note that all I/O errors are completely ignored.
|
/// 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());
|
let (ig, err) = self.add_child_path(dir.as_ref());
|
||||||
(Ignore(Arc::new(ig)), err)
|
(Ignore(Arc::new(ig)), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like add_child, but takes a full path and returns an IgnoreInner.
|
/// Like add_child, but takes a full path and returns an IgnoreInner.
|
||||||
fn add_child_path(&self, dir: &Path) -> (IgnoreInner, Option<Error>) {
|
fn add_child_path(&self, dir: &Path) -> (IgnoreInner, Option<Error>) {
|
||||||
|
let git_type = if self.0.opts.git_ignore || self.0.opts.git_exclude {
|
||||||
|
dir.join(".git").metadata().ok().map(|md| md.file_type())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let has_git = git_type.map(|_| true).unwrap_or(false);
|
||||||
|
|
||||||
let mut errs = PartialErrorBuilder::default();
|
let mut errs = PartialErrorBuilder::default();
|
||||||
let custom_ig_matcher = if self.0.custom_ignore_filenames.is_empty() {
|
let custom_ig_matcher = if self.0.custom_ignore_filenames.is_empty() {
|
||||||
Gitignore::empty()
|
Gitignore::empty()
|
||||||
} else {
|
} else {
|
||||||
let (m, err) = create_gitignore(
|
let (m, err) = create_gitignore(
|
||||||
|
&dir,
|
||||||
&dir,
|
&dir,
|
||||||
&self.0.custom_ignore_filenames,
|
&self.0.custom_ignore_filenames,
|
||||||
self.0.opts.ignore_case_insensitive,
|
self.0.opts.ignore_case_insensitive,
|
||||||
@@ -235,34 +254,46 @@ impl Ignore {
|
|||||||
let ig_matcher = if !self.0.opts.ignore {
|
let ig_matcher = if !self.0.opts.ignore {
|
||||||
Gitignore::empty()
|
Gitignore::empty()
|
||||||
} else {
|
} else {
|
||||||
let (m, err) =
|
let (m, err) = create_gitignore(
|
||||||
create_gitignore(&dir, &[".ignore"], self.0.opts.ignore_case_insensitive);
|
&dir,
|
||||||
|
&dir,
|
||||||
|
&[".ignore"],
|
||||||
|
self.0.opts.ignore_case_insensitive,
|
||||||
|
);
|
||||||
errs.maybe_push(err);
|
errs.maybe_push(err);
|
||||||
m
|
m
|
||||||
};
|
};
|
||||||
let gi_matcher = if !self.0.opts.git_ignore {
|
let gi_matcher = if !self.0.opts.git_ignore {
|
||||||
Gitignore::empty()
|
Gitignore::empty()
|
||||||
} else {
|
} else {
|
||||||
let (m, err) =
|
let (m, err) = create_gitignore(
|
||||||
create_gitignore(&dir, &[".gitignore"], self.0.opts.ignore_case_insensitive);
|
&dir,
|
||||||
|
&dir,
|
||||||
|
&[".gitignore"],
|
||||||
|
self.0.opts.ignore_case_insensitive,
|
||||||
|
);
|
||||||
errs.maybe_push(err);
|
errs.maybe_push(err);
|
||||||
m
|
m
|
||||||
};
|
};
|
||||||
let gi_exclude_matcher = if !self.0.opts.git_exclude {
|
let gi_exclude_matcher = if !self.0.opts.git_exclude {
|
||||||
Gitignore::empty()
|
Gitignore::empty()
|
||||||
} else {
|
} else {
|
||||||
let (m, err) = create_gitignore(
|
match resolve_git_commondir(dir, git_type) {
|
||||||
&dir,
|
Ok(git_dir) => {
|
||||||
&[".git/info/exclude"],
|
let (m, err) = create_gitignore(
|
||||||
self.0.opts.ignore_case_insensitive,
|
&dir,
|
||||||
);
|
&git_dir,
|
||||||
errs.maybe_push(err);
|
&["info/exclude"],
|
||||||
m
|
self.0.opts.ignore_case_insensitive,
|
||||||
};
|
);
|
||||||
let has_git = if self.0.opts.git_ignore {
|
errs.maybe_push(err);
|
||||||
dir.join(".git").exists()
|
m
|
||||||
} else {
|
}
|
||||||
false
|
Err(err) => {
|
||||||
|
errs.maybe_push(err);
|
||||||
|
Gitignore::empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let ig = IgnoreInner {
|
let ig = IgnoreInner {
|
||||||
compiled: self.0.compiled.clone(),
|
compiled: self.0.compiled.clone(),
|
||||||
@@ -288,7 +319,8 @@ impl Ignore {
|
|||||||
/// Returns true if at least one type of ignore rule should be matched.
|
/// Returns true if at least one type of ignore rule should be matched.
|
||||||
fn has_any_ignore_rules(&self) -> bool {
|
fn has_any_ignore_rules(&self) -> bool {
|
||||||
let opts = self.0.opts;
|
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();
|
let has_explicit_ignores = !self.0.explicit_ignores.is_empty();
|
||||||
|
|
||||||
opts.ignore
|
opts.ignore
|
||||||
@@ -300,7 +332,10 @@ impl Ignore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Like `matched`, but works with a directory entry instead.
|
/// 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());
|
let m = self.matched(dent.path(), dent.is_dir());
|
||||||
if m.is_none() && self.0.opts.hidden && is_hidden(dent) {
|
if m.is_none() && self.0.opts.hidden && is_hidden(dent) {
|
||||||
return Match::Ignore(IgnoreMatch::hidden());
|
return Match::Ignore(IgnoreMatch::hidden());
|
||||||
@@ -312,7 +347,11 @@ impl Ignore {
|
|||||||
/// ignored or not.
|
/// ignored or not.
|
||||||
///
|
///
|
||||||
/// The match contains information about its origin.
|
/// 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
|
// We need to be careful with our path. If it has a leading ./, then
|
||||||
// strip it because it causes nothing but trouble.
|
// strip it because it causes nothing but trouble.
|
||||||
let mut path = path.as_ref();
|
let mut path = path.as_ref();
|
||||||
@@ -343,7 +382,8 @@ impl Ignore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !self.0.types.is_empty() {
|
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() {
|
if mat.is_ignore() {
|
||||||
return mat;
|
return mat;
|
||||||
} else if mat.is_whitelist() {
|
} else if mat.is_whitelist() {
|
||||||
@@ -355,15 +395,20 @@ impl Ignore {
|
|||||||
|
|
||||||
/// Performs matching only on the ignore files for this directory and
|
/// Performs matching only on the ignore files for this directory and
|
||||||
/// all parent directories.
|
/// all parent directories.
|
||||||
fn matched_ignore<'a>(&'a self, path: &Path, is_dir: bool) -> Match<IgnoreMatch<'a>> {
|
fn matched_ignore<'a>(
|
||||||
let (mut m_custom_ignore, mut m_ignore, mut m_gi, mut m_gi_exclude, mut m_explicit) = (
|
&'a self,
|
||||||
Match::None,
|
path: &Path,
|
||||||
Match::None,
|
is_dir: bool,
|
||||||
Match::None,
|
) -> Match<IgnoreMatch<'a>> {
|
||||||
Match::None,
|
let (
|
||||||
Match::None,
|
mut m_custom_ignore,
|
||||||
);
|
mut m_ignore,
|
||||||
let any_git = self.parents().any(|ig| ig.0.has_git);
|
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);
|
||||||
let mut saw_git = false;
|
let mut saw_git = false;
|
||||||
for ig in self.parents().take_while(|ig| !ig.0.is_absolute_parent) {
|
for ig in self.parents().take_while(|ig| !ig.0.is_absolute_parent) {
|
||||||
if m_custom_ignore.is_none() {
|
if m_custom_ignore.is_none() {
|
||||||
@@ -395,7 +440,9 @@ impl Ignore {
|
|||||||
if self.0.opts.parents {
|
if self.0.opts.parents {
|
||||||
if let Some(abs_parent_path) = self.absolute_base() {
|
if let Some(abs_parent_path) = self.absolute_base() {
|
||||||
let path = abs_parent_path.join(path);
|
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() {
|
if m_custom_ignore.is_none() {
|
||||||
m_custom_ignore =
|
m_custom_ignore =
|
||||||
ig.0.custom_ignore_matcher
|
ig.0.custom_ignore_matcher
|
||||||
@@ -515,6 +562,7 @@ impl IgnoreBuilder {
|
|||||||
git_ignore: true,
|
git_ignore: true,
|
||||||
git_exclude: true,
|
git_exclude: true,
|
||||||
ignore_case_insensitive: false,
|
ignore_case_insensitive: false,
|
||||||
|
require_git: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,7 +595,9 @@ impl IgnoreBuilder {
|
|||||||
is_absolute_parent: true,
|
is_absolute_parent: true,
|
||||||
absolute_base: None,
|
absolute_base: None,
|
||||||
explicit_ignores: Arc::new(self.explicit_ignores.clone()),
|
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(),
|
custom_ignore_matcher: Gitignore::empty(),
|
||||||
ignore_matcher: Gitignore::empty(),
|
ignore_matcher: Gitignore::empty(),
|
||||||
git_global_matcher: Arc::new(git_global_matcher),
|
git_global_matcher: Arc::new(git_global_matcher),
|
||||||
@@ -594,8 +644,7 @@ impl IgnoreBuilder {
|
|||||||
&mut self,
|
&mut self,
|
||||||
file_name: S,
|
file_name: S,
|
||||||
) -> &mut IgnoreBuilder {
|
) -> &mut IgnoreBuilder {
|
||||||
self.custom_ignore_filenames
|
self.custom_ignore_filenames.push(file_name.as_ref().to_os_string());
|
||||||
.push(file_name.as_ref().to_os_string());
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -664,10 +713,23 @@ impl IgnoreBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether a git repository is required to apply git-related ignore
|
||||||
|
/// rules (global rules, .gitignore and local exclude rules).
|
||||||
|
///
|
||||||
|
/// When disabled, git-related ignore rules are applied even when searching
|
||||||
|
/// outside a git repository.
|
||||||
|
pub fn require_git(&mut self, yes: bool) -> &mut IgnoreBuilder {
|
||||||
|
self.opts.require_git = yes;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Process ignore files case insensitively
|
/// Process ignore files case insensitively
|
||||||
///
|
///
|
||||||
/// This is disabled by default.
|
/// 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.opts.ignore_case_insensitive = yes;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -675,12 +737,15 @@ impl IgnoreBuilder {
|
|||||||
|
|
||||||
/// Creates a new gitignore matcher for the directory given.
|
/// Creates a new gitignore matcher for the directory given.
|
||||||
///
|
///
|
||||||
/// Ignore globs are extracted from each of the file names in `dir` in the
|
/// The matcher is meant to match files below `dir`.
|
||||||
/// order given (earlier names have lower precedence than later names).
|
/// Ignore globs are extracted from each of the file names relative to
|
||||||
|
/// `dir_for_ignorefile` in the order given (earlier names have lower
|
||||||
|
/// precedence than later names).
|
||||||
///
|
///
|
||||||
/// I/O errors are ignored.
|
/// I/O errors are ignored.
|
||||||
pub fn create_gitignore<T: AsRef<OsStr>>(
|
pub fn create_gitignore<T: AsRef<OsStr>>(
|
||||||
dir: &Path,
|
dir: &Path,
|
||||||
|
dir_for_ignorefile: &Path,
|
||||||
names: &[T],
|
names: &[T],
|
||||||
case_insensitive: bool,
|
case_insensitive: bool,
|
||||||
) -> (Gitignore, Option<Error>) {
|
) -> (Gitignore, Option<Error>) {
|
||||||
@@ -688,8 +753,22 @@ pub fn create_gitignore<T: AsRef<OsStr>>(
|
|||||||
let mut errs = PartialErrorBuilder::default();
|
let mut errs = PartialErrorBuilder::default();
|
||||||
builder.case_insensitive(case_insensitive).unwrap();
|
builder.case_insensitive(case_insensitive).unwrap();
|
||||||
for name in names {
|
for name in names {
|
||||||
let gipath = dir.join(name.as_ref());
|
let gipath = dir_for_ignorefile.join(name.as_ref());
|
||||||
errs.maybe_push_ignore_io(builder.add(gipath));
|
// This check is not necessary, but is added for performance. Namely,
|
||||||
|
// a simple stat call checking for existence can often be just a bit
|
||||||
|
// quicker than actually trying to open a file. Since the number of
|
||||||
|
// directories without ignore files likely greatly exceeds the number
|
||||||
|
// with ignore files, this check generally makes sense.
|
||||||
|
//
|
||||||
|
// However, until demonstrated otherwise, we speculatively do not do
|
||||||
|
// this on Windows since Windows is notorious for having slow file
|
||||||
|
// system operations. Namely, it's not clear whether this analysis
|
||||||
|
// makes sense on Windows.
|
||||||
|
//
|
||||||
|
// For more details: https://github.com/BurntSushi/ripgrep/pull/1381
|
||||||
|
if cfg!(windows) || gipath.exists() {
|
||||||
|
errs.maybe_push_ignore_io(builder.add(gipath));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let gi = match builder.build() {
|
let gi = match builder.build() {
|
||||||
Ok(gi) => gi,
|
Ok(gi) => gi,
|
||||||
@@ -701,10 +780,66 @@ pub fn create_gitignore<T: AsRef<OsStr>>(
|
|||||||
(gi, errs.into_error_option())
|
(gi, errs.into_error_option())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Find the GIT_COMMON_DIR for the given git worktree.
|
||||||
|
///
|
||||||
|
/// This is the directory that may contain a private ignore file
|
||||||
|
/// "info/exclude". Unlike git, this function does *not* read environment
|
||||||
|
/// variables GIT_DIR and GIT_COMMON_DIR, because it is not clear how to use
|
||||||
|
/// them when multiple repositories are searched.
|
||||||
|
///
|
||||||
|
/// Some I/O errors are ignored.
|
||||||
|
fn resolve_git_commondir(
|
||||||
|
dir: &Path,
|
||||||
|
git_type: Option<FileType>,
|
||||||
|
) -> Result<PathBuf, Option<Error>> {
|
||||||
|
let git_dir_path = || dir.join(".git");
|
||||||
|
let git_dir = git_dir_path();
|
||||||
|
if !git_type.map_or(false, |ft| ft.is_file()) {
|
||||||
|
return Ok(git_dir);
|
||||||
|
}
|
||||||
|
let file = match File::open(git_dir) {
|
||||||
|
Ok(file) => io::BufReader::new(file),
|
||||||
|
Err(err) => {
|
||||||
|
return Err(Some(Error::Io(err).with_path(git_dir_path())));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let dot_git_line = match file.lines().next() {
|
||||||
|
Some(Ok(line)) => line,
|
||||||
|
Some(Err(err)) => {
|
||||||
|
return Err(Some(Error::Io(err).with_path(git_dir_path())));
|
||||||
|
}
|
||||||
|
None => return Err(None),
|
||||||
|
};
|
||||||
|
if !dot_git_line.starts_with("gitdir: ") {
|
||||||
|
return Err(None);
|
||||||
|
}
|
||||||
|
let real_git_dir = PathBuf::from(&dot_git_line["gitdir: ".len()..]);
|
||||||
|
let git_commondir_file = || real_git_dir.join("commondir");
|
||||||
|
let file = match File::open(git_commondir_file()) {
|
||||||
|
Ok(file) => io::BufReader::new(file),
|
||||||
|
Err(err) => {
|
||||||
|
return Err(Some(Error::Io(err).with_path(git_commondir_file())));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let commondir_line = match file.lines().next() {
|
||||||
|
Some(Ok(line)) => line,
|
||||||
|
Some(Err(err)) => {
|
||||||
|
return Err(Some(Error::Io(err).with_path(git_commondir_file())));
|
||||||
|
}
|
||||||
|
None => return Err(None),
|
||||||
|
};
|
||||||
|
let commondir_abs = if commondir_line.starts_with(".") {
|
||||||
|
real_git_dir.join(commondir_line) // relative commondir
|
||||||
|
} else {
|
||||||
|
PathBuf::from(commondir_line)
|
||||||
|
};
|
||||||
|
Ok(commondir_abs)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::{self, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use dir::IgnoreBuilder;
|
use dir::IgnoreBuilder;
|
||||||
@@ -739,10 +874,8 @@ mod tests {
|
|||||||
|
|
||||||
let (gi, err) = Gitignore::new(td.path().join("not-an-ignore"));
|
let (gi, err) = Gitignore::new(td.path().join("not-an-ignore"));
|
||||||
assert!(err.is_none());
|
assert!(err.is_none());
|
||||||
let (ig, err) = IgnoreBuilder::new()
|
let (ig, err) =
|
||||||
.add_ignore(gi)
|
IgnoreBuilder::new().add_ignore(gi).build().add_child(td.path());
|
||||||
.build()
|
|
||||||
.add_child(td.path());
|
|
||||||
assert!(err.is_none());
|
assert!(err.is_none());
|
||||||
assert!(ig.matched("foo", false).is_ignore());
|
assert!(ig.matched("foo", false).is_ignore());
|
||||||
assert!(ig.matched("bar", false).is_whitelist());
|
assert!(ig.matched("bar", false).is_whitelist());
|
||||||
@@ -787,6 +920,21 @@ mod tests {
|
|||||||
assert!(ig.matched("baz", false).is_none());
|
assert!(ig.matched("baz", false).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn gitignore_allowed_no_git() {
|
||||||
|
let td = tmpdir();
|
||||||
|
wfile(td.path().join(".gitignore"), "foo\n!bar");
|
||||||
|
|
||||||
|
let (ig, err) = IgnoreBuilder::new()
|
||||||
|
.require_git(false)
|
||||||
|
.build()
|
||||||
|
.add_child(td.path());
|
||||||
|
assert!(err.is_none());
|
||||||
|
assert!(ig.matched("foo", false).is_ignore());
|
||||||
|
assert!(ig.matched("bar", false).is_whitelist());
|
||||||
|
assert!(ig.matched("baz", false).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ignore() {
|
fn ignore() {
|
||||||
let td = tmpdir();
|
let td = tmpdir();
|
||||||
@@ -991,4 +1139,62 @@ mod tests {
|
|||||||
assert!(ig2.matched("foo", false).is_ignore());
|
assert!(ig2.matched("foo", false).is_ignore());
|
||||||
assert!(ig2.matched("src/foo", false).is_ignore());
|
assert!(ig2.matched("src/foo", false).is_ignore());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn git_info_exclude_in_linked_worktree() {
|
||||||
|
let td = tmpdir();
|
||||||
|
let git_dir = td.path().join(".git");
|
||||||
|
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");
|
||||||
|
mkdirp(td.path().join("linked-worktree"));
|
||||||
|
let worktree_git_dir_abs = format!(
|
||||||
|
"gitdir: {}",
|
||||||
|
git_dir.join("worktrees/linked-worktree").to_str().unwrap(),
|
||||||
|
);
|
||||||
|
wfile(td.path().join("linked-worktree/.git"), &worktree_git_dir_abs);
|
||||||
|
|
||||||
|
// relative commondir
|
||||||
|
wfile(commondir_path(), "../..");
|
||||||
|
let ib = IgnoreBuilder::new().build();
|
||||||
|
let (ignore, err) = ib.add_child(td.path().join("linked-worktree"));
|
||||||
|
assert!(err.is_none());
|
||||||
|
assert!(ignore.matched("ignore_me", false).is_ignore());
|
||||||
|
|
||||||
|
// absolute commondir
|
||||||
|
wfile(commondir_path(), git_dir.to_str().unwrap());
|
||||||
|
let (ignore, err) = ib.add_child(td.path().join("linked-worktree"));
|
||||||
|
assert!(err.is_none());
|
||||||
|
assert!(ignore.matched("ignore_me", false).is_ignore());
|
||||||
|
|
||||||
|
// missing commondir file
|
||||||
|
assert!(fs::remove_file(commondir_path()).is_ok());
|
||||||
|
let (_, err) = ib.add_child(td.path().join("linked-worktree"));
|
||||||
|
assert!(err.is_some());
|
||||||
|
assert!(match err {
|
||||||
|
Some(Error::WithPath { path, err }) => {
|
||||||
|
if path != commondir_path() {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
match *err {
|
||||||
|
Error::Io(ioerr) => {
|
||||||
|
ioerr.kind() == io::ErrorKind::NotFound
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
});
|
||||||
|
|
||||||
|
wfile(td.path().join("linked-worktree/.git"), "garbage");
|
||||||
|
let (_, err) = ib.add_child(td.path().join("linked-worktree"));
|
||||||
|
assert!(err.is_none());
|
||||||
|
|
||||||
|
wfile(td.path().join("linked-worktree/.git"), "gitdir: garbage");
|
||||||
|
let (_, err) = ib.add_child(td.path().join("linked-worktree"));
|
||||||
|
assert!(err.is_some());
|
||||||
|
}
|
||||||
}
|
}
|
@@ -249,7 +249,7 @@ impl Gitignore {
|
|||||||
return Match::None;
|
return Match::None;
|
||||||
}
|
}
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
let _matches = self.matches.as_ref().unwrap().get_default();
|
let _matches = self.matches.as_ref().unwrap().get_or_default();
|
||||||
let mut matches = _matches.borrow_mut();
|
let mut matches = _matches.borrow_mut();
|
||||||
let candidate = Candidate::new(path);
|
let candidate = Candidate::new(path);
|
||||||
self.set.matches_candidate_into(&candidate, &mut *matches);
|
self.set.matches_candidate_into(&candidate, &mut *matches);
|
||||||
@@ -332,13 +332,10 @@ impl GitignoreBuilder {
|
|||||||
pub fn build(&self) -> Result<Gitignore, Error> {
|
pub fn build(&self) -> Result<Gitignore, Error> {
|
||||||
let nignore = self.globs.iter().filter(|g| !g.is_whitelist()).count();
|
let nignore = self.globs.iter().filter(|g| !g.is_whitelist()).count();
|
||||||
let nwhite = self.globs.iter().filter(|g| g.is_whitelist()).count();
|
let nwhite = self.globs.iter().filter(|g| g.is_whitelist()).count();
|
||||||
let set =
|
let set = self
|
||||||
self.builder.build().map_err(|err| {
|
.builder
|
||||||
Error::Glob {
|
.build()
|
||||||
glob: None,
|
.map_err(|err| Error::Glob { glob: None, err: err.to_string() })?;
|
||||||
err: err.to_string(),
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
Ok(Gitignore {
|
Ok(Gitignore {
|
||||||
set: set,
|
set: set,
|
||||||
root: self.root.clone(),
|
root: self.root.clone(),
|
||||||
@@ -499,18 +496,15 @@ impl GitignoreBuilder {
|
|||||||
if glob.actual.ends_with("/**") {
|
if glob.actual.ends_with("/**") {
|
||||||
glob.actual = format!("{}/*", glob.actual);
|
glob.actual = format!("{}/*", glob.actual);
|
||||||
}
|
}
|
||||||
let parsed =
|
let parsed = GlobBuilder::new(&glob.actual)
|
||||||
GlobBuilder::new(&glob.actual)
|
.literal_separator(true)
|
||||||
.literal_separator(true)
|
.case_insensitive(self.case_insensitive)
|
||||||
.case_insensitive(self.case_insensitive)
|
.backslash_escape(true)
|
||||||
.backslash_escape(true)
|
.build()
|
||||||
.build()
|
.map_err(|err| Error::Glob {
|
||||||
.map_err(|err| {
|
glob: Some(glob.original.clone()),
|
||||||
Error::Glob {
|
err: err.kind().to_string(),
|
||||||
glob: Some(glob.original.clone()),
|
})?;
|
||||||
err: err.kind().to_string(),
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
self.builder.add(parsed);
|
self.builder.add(parsed);
|
||||||
self.globs.push(glob);
|
self.globs.push(glob);
|
||||||
Ok(self)
|
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
|
// probably works in more circumstances. I guess we would ideally have
|
||||||
// a full INI parser. Yuck.
|
// a full INI parser. Yuck.
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref RE: Regex = Regex::new(
|
static ref RE: Regex =
|
||||||
r"(?im)^\s*excludesfile\s*=\s*(.+)\s*$"
|
Regex::new(r"(?im)^\s*excludesfile\s*=\s*(.+)\s*$").unwrap();
|
||||||
).unwrap();
|
|
||||||
};
|
};
|
||||||
let caps = match RE.captures(data) {
|
let caps = match RE.captures(data) {
|
||||||
None => return None,
|
None => return None,
|
||||||
@@ -630,8 +623,8 @@ fn home_dir() -> Option<PathBuf> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::path::Path;
|
|
||||||
use super::{Gitignore, GitignoreBuilder};
|
use super::{Gitignore, GitignoreBuilder};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
fn gi_from_str<P: AsRef<Path>>(root: P, s: &str) -> Gitignore {
|
fn gi_from_str<P: AsRef<Path>>(root: P, s: &str) -> Gitignore {
|
||||||
let mut builder = GitignoreBuilder::new(root);
|
let mut builder = GitignoreBuilder::new(root);
|
||||||
@@ -726,8 +719,11 @@ mod tests {
|
|||||||
not_ignored!(ignot12, ROOT, "\n\n\n", "foo");
|
not_ignored!(ignot12, ROOT, "\n\n\n", "foo");
|
||||||
not_ignored!(ignot13, ROOT, "foo/**", "foo", true);
|
not_ignored!(ignot13, ROOT, "foo/**", "foo", true);
|
||||||
not_ignored!(
|
not_ignored!(
|
||||||
ignot14, "./third_party/protobuf", "m4/ltoptions.m4",
|
ignot14,
|
||||||
"./third_party/protobuf/csharp/src/packages/repositories.config");
|
"./third_party/protobuf",
|
||||||
|
"m4/ltoptions.m4",
|
||||||
|
"./third_party/protobuf/csharp/src/packages/repositories.config"
|
||||||
|
);
|
||||||
not_ignored!(ignot15, ROOT, "!/bar", "foo/bar");
|
not_ignored!(ignot15, ROOT, "!/bar", "foo/bar");
|
||||||
not_ignored!(ignot16, ROOT, "*\n!**/", "foo", true);
|
not_ignored!(ignot16, ROOT, "*\n!**/", "foo", true);
|
||||||
not_ignored!(ignot17, ROOT, "src/*.rs", "src/grep/src/main.rs");
|
not_ignored!(ignot17, ROOT, "src/*.rs", "src/grep/src/main.rs");
|
||||||
@@ -771,9 +767,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn case_insensitive() {
|
fn case_insensitive() {
|
||||||
let gi = GitignoreBuilder::new(ROOT)
|
let gi = GitignoreBuilder::new(ROOT)
|
||||||
.case_insensitive(true).unwrap()
|
.case_insensitive(true)
|
||||||
.add_str(None, "*.html").unwrap()
|
.unwrap()
|
||||||
.build().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.HTML", false).is_ignore());
|
assert!(gi.matched("foo.HTML", false).is_ignore());
|
||||||
assert!(!gi.matched("foo.htm", false).is_ignore());
|
assert!(!gi.matched("foo.htm", false).is_ignore());
|
@@ -65,12 +65,16 @@ use std::fmt;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub use walk::{DirEntry, Walk, WalkBuilder, WalkParallel, WalkState};
|
pub use walk::{
|
||||||
|
DirEntry, ParallelVisitor, ParallelVisitorBuilder, Walk, WalkBuilder,
|
||||||
|
WalkParallel, WalkState,
|
||||||
|
};
|
||||||
|
|
||||||
|
mod default_types;
|
||||||
mod dir;
|
mod dir;
|
||||||
pub mod gitignore;
|
pub mod gitignore;
|
||||||
mod pathutil;
|
|
||||||
pub mod overrides;
|
pub mod overrides;
|
||||||
|
mod pathutil;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
mod walk;
|
mod walk;
|
||||||
|
|
||||||
@@ -143,20 +147,14 @@ impl Clone for Error {
|
|||||||
Error::WithDepth { depth, ref err } => {
|
Error::WithDepth { depth, ref err } => {
|
||||||
Error::WithDepth { depth: depth, err: err.clone() }
|
Error::WithDepth { depth: depth, err: err.clone() }
|
||||||
}
|
}
|
||||||
Error::Loop { ref ancestor, ref child } => {
|
Error::Loop { ref ancestor, ref child } => Error::Loop {
|
||||||
Error::Loop {
|
ancestor: ancestor.clone(),
|
||||||
ancestor: ancestor.clone(),
|
child: child.clone(),
|
||||||
child: child.clone()
|
},
|
||||||
}
|
Error::Io(ref err) => match err.raw_os_error() {
|
||||||
}
|
Some(e) => Error::Io(io::Error::from_raw_os_error(e)),
|
||||||
Error::Io(ref err) => {
|
None => Error::Io(io::Error::new(err.kind(), err.to_string())),
|
||||||
match err.raw_os_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 { ref glob, ref err } => {
|
||||||
Error::Glob { glob: glob.clone(), err: err.clone() }
|
Error::Glob { glob: glob.clone(), err: err.clone() }
|
||||||
}
|
}
|
||||||
@@ -219,19 +217,14 @@ impl Error {
|
|||||||
|
|
||||||
/// Turn an error into a tagged error with the given depth.
|
/// Turn an error into a tagged error with the given depth.
|
||||||
fn with_depth(self, depth: usize) -> Error {
|
fn with_depth(self, depth: usize) -> Error {
|
||||||
Error::WithDepth {
|
Error::WithDepth { depth: depth, err: Box::new(self) }
|
||||||
depth: depth,
|
|
||||||
err: Box::new(self),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turn an error into a tagged error with the given file path and line
|
/// 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.
|
/// number. If path is empty, then it is omitted from the error.
|
||||||
fn tagged<P: AsRef<Path>>(self, path: P, lineno: u64) -> Error {
|
fn tagged<P: AsRef<Path>>(self, path: P, lineno: u64) -> Error {
|
||||||
let errline = Error::WithLineNumber {
|
let errline =
|
||||||
line: lineno,
|
Error::WithLineNumber { line: lineno, err: Box::new(self) };
|
||||||
err: Box::new(self),
|
|
||||||
};
|
|
||||||
if path.as_ref().as_os_str().is_empty() {
|
if path.as_ref().as_os_str().is_empty() {
|
||||||
return errline;
|
return errline;
|
||||||
}
|
}
|
||||||
@@ -253,16 +246,14 @@ impl Error {
|
|||||||
let path = err.path().map(|p| p.to_path_buf());
|
let path = err.path().map(|p| p.to_path_buf());
|
||||||
let mut ig_err = Error::Io(io::Error::from(err));
|
let mut ig_err = Error::Io(io::Error::from(err));
|
||||||
if let Some(path) = path {
|
if let Some(path) = path {
|
||||||
ig_err = Error::WithPath {
|
ig_err = Error::WithPath { path: path, err: Box::new(ig_err) };
|
||||||
path: path,
|
|
||||||
err: Box::new(ig_err),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
ig_err
|
ig_err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for Error {
|
impl error::Error for Error {
|
||||||
|
#[allow(deprecated)]
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
Error::Partial(_) => "partial error",
|
Error::Partial(_) => "partial error",
|
||||||
@@ -293,11 +284,13 @@ impl fmt::Display for Error {
|
|||||||
write!(f, "{}: {}", path.display(), err)
|
write!(f, "{}: {}", path.display(), err)
|
||||||
}
|
}
|
||||||
Error::WithDepth { ref err, .. } => err.fmt(f),
|
Error::WithDepth { ref err, .. } => err.fmt(f),
|
||||||
Error::Loop { ref ancestor, ref child } => {
|
Error::Loop { ref ancestor, ref child } => write!(
|
||||||
write!(f, "File system loop found: \
|
f,
|
||||||
|
"File system loop found: \
|
||||||
{} points to an ancestor {}",
|
{} points to an ancestor {}",
|
||||||
child.display(), ancestor.display())
|
child.display(),
|
||||||
}
|
ancestor.display()
|
||||||
|
),
|
||||||
Error::Io(ref err) => err.fmt(f),
|
Error::Io(ref err) => err.fmt(f),
|
||||||
Error::Glob { glob: None, ref err } => write!(f, "{}", err),
|
Error::Glob { glob: None, ref err } => write!(f, "{}", err),
|
||||||
Error::Glob { glob: Some(ref glob), ref err } => {
|
Error::Glob { glob: Some(ref glob), ref err } => {
|
||||||
@@ -306,10 +299,11 @@ impl fmt::Display for Error {
|
|||||||
Error::UnrecognizedFileType(ref ty) => {
|
Error::UnrecognizedFileType(ref ty) => {
|
||||||
write!(f, "unrecognized file type: {}", ty)
|
write!(f, "unrecognized file type: {}", ty)
|
||||||
}
|
}
|
||||||
Error::InvalidDefinition => {
|
Error::InvalidDefinition => write!(
|
||||||
write!(f, "invalid definition (format is type:glob, e.g., \
|
f,
|
||||||
html:*.html)")
|
"invalid definition (format is type:glob, e.g., \
|
||||||
}
|
html:*.html)"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -115,9 +115,7 @@ impl OverrideBuilder {
|
|||||||
///
|
///
|
||||||
/// Matching is done relative to the directory path provided.
|
/// Matching is done relative to the directory path provided.
|
||||||
pub fn new<P: AsRef<Path>>(path: P) -> OverrideBuilder {
|
pub fn new<P: AsRef<Path>>(path: P) -> OverrideBuilder {
|
||||||
OverrideBuilder {
|
OverrideBuilder { builder: GitignoreBuilder::new(path) }
|
||||||
builder: GitignoreBuilder::new(path),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a new override matcher from the globs added so far.
|
/// Builds a new override matcher from the globs added so far.
|
||||||
@@ -240,9 +238,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn case_insensitive() {
|
fn case_insensitive() {
|
||||||
let ov = OverrideBuilder::new(ROOT)
|
let ov = OverrideBuilder::new(ROOT)
|
||||||
.case_insensitive(true).unwrap()
|
.case_insensitive(true)
|
||||||
.add("*.html").unwrap()
|
.unwrap()
|
||||||
.build().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.HTML", false).is_whitelist());
|
assert!(ov.matched("foo.HTML", false).is_whitelist());
|
||||||
assert!(ov.matched("foo.htm", false).is_ignore());
|
assert!(ov.matched("foo.htm", false).is_ignore());
|
||||||
@@ -251,9 +252,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_case_sensitive() {
|
fn default_case_sensitive() {
|
||||||
let ov = OverrideBuilder::new(ROOT)
|
let ov =
|
||||||
.add("*.html").unwrap()
|
OverrideBuilder::new(ROOT).add("*.html").unwrap().build().unwrap();
|
||||||
.build().unwrap();
|
|
||||||
assert!(ov.matched("foo.html", false).is_whitelist());
|
assert!(ov.matched("foo.html", false).is_whitelist());
|
||||||
assert!(ov.matched("foo.HTML", false).is_ignore());
|
assert!(ov.matched("foo.HTML", false).is_ignore());
|
||||||
assert!(ov.matched("foo.htm", false).is_ignore());
|
assert!(ov.matched("foo.htm", false).is_ignore());
|
@@ -91,8 +91,8 @@ pub fn strip_prefix<'a, P: AsRef<Path> + ?Sized>(
|
|||||||
/// the empty string.
|
/// the empty string.
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub fn is_file_name<P: AsRef<Path>>(path: P) -> bool {
|
pub fn is_file_name<P: AsRef<Path>>(path: P) -> bool {
|
||||||
use std::os::unix::ffi::OsStrExt;
|
|
||||||
use memchr::memchr;
|
use memchr::memchr;
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
|
||||||
let path = path.as_ref().as_os_str().as_bytes();
|
let path = path.as_ref().as_os_str().as_bytes();
|
||||||
memchr(b'/', path).is_none()
|
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>(
|
pub fn file_name<'a, P: AsRef<Path> + ?Sized>(
|
||||||
path: &'a P,
|
path: &'a P,
|
||||||
) -> Option<&'a OsStr> {
|
) -> Option<&'a OsStr> {
|
||||||
use std::os::unix::ffi::OsStrExt;
|
|
||||||
use memchr::memrchr;
|
use memchr::memrchr;
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
|
||||||
let path = path.as_ref().as_os_str().as_bytes();
|
let path = path.as_ref().as_os_str().as_bytes();
|
||||||
if path.is_empty() {
|
if path.is_empty() {
|
@@ -93,236 +93,10 @@ use globset::{GlobBuilder, GlobSet, GlobSetBuilder};
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use thread_local::ThreadLocal;
|
use thread_local::ThreadLocal;
|
||||||
|
|
||||||
|
use default_types::DEFAULT_TYPES;
|
||||||
use pathutil::file_name;
|
use pathutil::file_name;
|
||||||
use {Error, Match};
|
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"]),
|
|
||||||
("docker", &["*Dockerfile*"]),
|
|
||||||
("edn", &["*.edn"]),
|
|
||||||
("elisp", &["*.el"]),
|
|
||||||
("elixir", &["*.ex", "*.eex", "*.exs"]),
|
|
||||||
("elm", &["*.elm"]),
|
|
||||||
("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"]),
|
|
||||||
("h", &["*.h", "*.hpp"]),
|
|
||||||
("hbs", &["*.hbs"]),
|
|
||||||
("haskell", &["*.hs", "*.lhs", "*.cpphs", "*.c2hs", "*.hsc"]),
|
|
||||||
("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"]),
|
|
||||||
("jupyter", &["*.ipynb", "*.jpynb"]),
|
|
||||||
("jl", &["*.jl"]),
|
|
||||||
("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"]),
|
|
||||||
("lzma", &["*.lzma"]),
|
|
||||||
("lz4", &["*.lz4"]),
|
|
||||||
("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"]),
|
|
||||||
("markdown", &["*.markdown", "*.md", "*.mdown", "*.mkdn"]),
|
|
||||||
("md", &["*.markdown", "*.md", "*.mdown", "*.mkdn"]),
|
|
||||||
("man", &["*.[0-9lnpx]", "*.[0-9][cEFMmpSx]"]),
|
|
||||||
("matlab", &["*.m"]),
|
|
||||||
("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"]),
|
|
||||||
("pascal", &["*.pas", "*.dpr", "*.lpr", "*.pp", "*.inc"]),
|
|
||||||
("perl", &["*.perl", "*.pl", "*.PL", "*.plh", "*.plx", "*.pm", "*.t"]),
|
|
||||||
("pdf", &["*.pdf"]),
|
|
||||||
("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"]),
|
|
||||||
("readme", &["README*", "*README"]),
|
|
||||||
("r", &["*.R", "*.r", "*.Rmd", "*.Rnw"]),
|
|
||||||
("rdoc", &["*.rdoc"]),
|
|
||||||
("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",
|
|
||||||
]),
|
|
||||||
("smarty", &["*.tpl"]),
|
|
||||||
("sml", &["*.sml", "*.sig"]),
|
|
||||||
("soy", &["*.soy"]),
|
|
||||||
("spark", &["*.spark"]),
|
|
||||||
("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"]),
|
|
||||||
("thrift", &["*.thrift"]),
|
|
||||||
("tf", &["*.tf"]),
|
|
||||||
("ts", &["*.ts", "*.tsx"]),
|
|
||||||
("txt", &["*.txt"]),
|
|
||||||
("toml", &["*.toml", "Cargo.lock"]),
|
|
||||||
("twig", &["*.twig"]),
|
|
||||||
("vala", &["*.vala"]),
|
|
||||||
("vb", &["*.vb"]),
|
|
||||||
("verilog", &["*.v", "*.vh", "*.sv", "*.svh"]),
|
|
||||||
("vhdl", &["*.vhd", "*.vhdl"]),
|
|
||||||
("vim", &["*.vim"]),
|
|
||||||
("vimscript", &["*.vim"]),
|
|
||||||
("wiki", &["*.mediawiki", "*.wiki"]),
|
|
||||||
("webidl", &["*.idl", "*.webidl", "*.widl"]),
|
|
||||||
("xml", &[
|
|
||||||
"*.xml", "*.xml.dist", "*.dtd", "*.xsl", "*.xslt", "*.xsd", "*.xjb",
|
|
||||||
"*.rng", "*.sch",
|
|
||||||
]),
|
|
||||||
("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"]),
|
|
||||||
];
|
|
||||||
|
|
||||||
/// Glob represents a single glob in a set of file type definitions.
|
/// Glob represents a single glob in a set of file type definitions.
|
||||||
///
|
///
|
||||||
/// There may be more than one glob for a particular file type.
|
/// There may be more than one glob for a particular file type.
|
||||||
@@ -352,7 +126,7 @@ enum GlobInner<'a> {
|
|||||||
which: usize,
|
which: usize,
|
||||||
/// Whether the selection was negated or not.
|
/// Whether the selection was negated or not.
|
||||||
negated: bool,
|
negated: bool,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Glob<'a> {
|
impl<'a> Glob<'a> {
|
||||||
@@ -366,9 +140,7 @@ impl<'a> Glob<'a> {
|
|||||||
pub fn file_type_def(&self) -> Option<&FileTypeDef> {
|
pub fn file_type_def(&self) -> Option<&FileTypeDef> {
|
||||||
match self {
|
match self {
|
||||||
Glob(GlobInner::UnmatchedIgnore) => None,
|
Glob(GlobInner::UnmatchedIgnore) => None,
|
||||||
Glob(GlobInner::Matched { def, .. }) => {
|
Glob(GlobInner::Matched { def, .. }) => Some(def),
|
||||||
Some(def)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -515,7 +287,7 @@ impl Types {
|
|||||||
return Match::None;
|
return Match::None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut matches = self.matches.get_default().borrow_mut();
|
let mut matches = self.matches.get_or_default().borrow_mut();
|
||||||
self.set.matches_into(name, &mut *matches);
|
self.set.matches_into(name, &mut *matches);
|
||||||
// The highest precedent match is the last one.
|
// The highest precedent match is the last one.
|
||||||
if let Some(&i) = matches.last() {
|
if let Some(&i) = matches.last() {
|
||||||
@@ -554,10 +326,7 @@ impl TypesBuilder {
|
|||||||
/// of default type definitions can be added with `add_defaults`, and
|
/// of default type definitions can be added with `add_defaults`, and
|
||||||
/// additional type definitions can be added with `select` and `negate`.
|
/// additional type definitions can be added with `select` and `negate`.
|
||||||
pub fn new() -> TypesBuilder {
|
pub fn new() -> TypesBuilder {
|
||||||
TypesBuilder {
|
TypesBuilder { types: HashMap::new(), selections: vec![] }
|
||||||
types: HashMap::new(),
|
|
||||||
selections: vec![],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the current set of file type definitions *and* selections into
|
/// Build the current set of file type definitions *and* selections into
|
||||||
@@ -582,19 +351,18 @@ impl TypesBuilder {
|
|||||||
GlobBuilder::new(glob)
|
GlobBuilder::new(glob)
|
||||||
.literal_separator(true)
|
.literal_separator(true)
|
||||||
.build()
|
.build()
|
||||||
.map_err(|err| {
|
.map_err(|err| Error::Glob {
|
||||||
Error::Glob {
|
glob: Some(glob.to_string()),
|
||||||
glob: Some(glob.to_string()),
|
err: err.kind().to_string(),
|
||||||
err: err.kind().to_string(),
|
})?,
|
||||||
}
|
);
|
||||||
})?);
|
|
||||||
glob_to_selection.push((isel, iglob));
|
glob_to_selection.push((isel, iglob));
|
||||||
}
|
}
|
||||||
selections.push(selection.clone().map(move |_| def));
|
selections.push(selection.clone().map(move |_| def));
|
||||||
}
|
}
|
||||||
let set = build_set.build().map_err(|err| {
|
let set = build_set
|
||||||
Error::Glob { glob: None, err: err.to_string() }
|
.build()
|
||||||
})?;
|
.map_err(|err| Error::Glob { glob: None, err: err.to_string() })?;
|
||||||
Ok(Types {
|
Ok(Types {
|
||||||
defs: defs,
|
defs: defs,
|
||||||
selections: selections,
|
selections: selections,
|
||||||
@@ -666,9 +434,14 @@ impl TypesBuilder {
|
|||||||
return Err(Error::InvalidDefinition);
|
return Err(Error::InvalidDefinition);
|
||||||
}
|
}
|
||||||
let (key, glob) = (name.to_string(), glob.to_string());
|
let (key, glob) = (name.to_string(), glob.to_string());
|
||||||
self.types.entry(key).or_insert_with(|| {
|
self.types
|
||||||
FileTypeDef { name: name.to_string(), globs: vec![] }
|
.entry(key)
|
||||||
}).globs.push(glob);
|
.or_insert_with(|| FileTypeDef {
|
||||||
|
name: name.to_string(),
|
||||||
|
globs: vec![],
|
||||||
|
})
|
||||||
|
.globs
|
||||||
|
.push(glob);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -695,7 +468,10 @@ impl TypesBuilder {
|
|||||||
3 => {
|
3 => {
|
||||||
let name = parts[0];
|
let name = parts[0];
|
||||||
let types_string = parts[2];
|
let types_string = parts[2];
|
||||||
if name.is_empty() || parts[1] != "include" || types_string.is_empty() {
|
if name.is_empty()
|
||||||
|
|| parts[1] != "include"
|
||||||
|
|| types_string.is_empty()
|
||||||
|
{
|
||||||
return Err(Error::InvalidDefinition);
|
return Err(Error::InvalidDefinition);
|
||||||
}
|
}
|
||||||
let types = types_string.split(',');
|
let types = types_string.split(',');
|
||||||
@@ -705,14 +481,15 @@ impl TypesBuilder {
|
|||||||
return Err(Error::InvalidDefinition);
|
return Err(Error::InvalidDefinition);
|
||||||
}
|
}
|
||||||
for type_name in types {
|
for type_name in types {
|
||||||
let globs = self.types.get(type_name).unwrap().globs.clone();
|
let globs =
|
||||||
|
self.types.get(type_name).unwrap().globs.clone();
|
||||||
for glob in globs {
|
for glob in globs {
|
||||||
self.add(name, &glob)?;
|
self.add(name, &glob)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(Error::InvalidDefinition)
|
_ => Err(Error::InvalidDefinition),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -769,7 +546,7 @@ mod tests {
|
|||||||
"rust:*.rs",
|
"rust:*.rs",
|
||||||
"js:*.js",
|
"js:*.js",
|
||||||
"foo:*.{rs,foo}",
|
"foo:*.{rs,foo}",
|
||||||
"combo:include:html,rust"
|
"combo:include:html,rust",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -803,7 +580,7 @@ mod tests {
|
|||||||
"combo:include:html,python",
|
"combo:include:html,python",
|
||||||
// Bad format
|
// Bad format
|
||||||
"combo:foobar:html,rust",
|
"combo:foobar:html,rust",
|
||||||
""
|
"",
|
||||||
];
|
];
|
||||||
for def in bad_defs {
|
for def in bad_defs {
|
||||||
assert!(btypes.add_def(def).is_err());
|
assert!(btypes.add_def(def).is_err());
|
@@ -6,11 +6,9 @@ use std::io;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
|
||||||
use std::time::Duration;
|
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
use channel;
|
use channel::{self, TryRecvError};
|
||||||
use same_file::Handle;
|
use same_file::Handle;
|
||||||
use walkdir::{self, WalkDir};
|
use walkdir::{self, WalkDir};
|
||||||
|
|
||||||
@@ -104,24 +102,15 @@ impl DirEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn new_stdin() -> DirEntry {
|
fn new_stdin() -> DirEntry {
|
||||||
DirEntry {
|
DirEntry { dent: DirEntryInner::Stdin, err: None }
|
||||||
dent: DirEntryInner::Stdin,
|
|
||||||
err: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_walkdir(dent: walkdir::DirEntry, err: Option<Error>) -> DirEntry {
|
fn new_walkdir(dent: walkdir::DirEntry, err: Option<Error>) -> DirEntry {
|
||||||
DirEntry {
|
DirEntry { dent: DirEntryInner::Walkdir(dent), err: err }
|
||||||
dent: DirEntryInner::Walkdir(dent),
|
|
||||||
err: err,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_raw(dent: DirEntryRaw, err: Option<Error>) -> DirEntry {
|
fn new_raw(dent: DirEntryRaw, err: Option<Error>) -> DirEntry {
|
||||||
DirEntry {
|
DirEntry { dent: DirEntryInner::Raw(dent), err: err }
|
||||||
dent: DirEntryInner::Raw(dent),
|
|
||||||
err: err,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,9 +176,9 @@ impl DirEntryInner {
|
|||||||
));
|
));
|
||||||
Err(err.with_path("<stdin>"))
|
Err(err.with_path("<stdin>"))
|
||||||
}
|
}
|
||||||
Walkdir(ref x) => x
|
Walkdir(ref x) => x.metadata().map_err(|err| {
|
||||||
.metadata()
|
Error::Io(io::Error::from(err)).with_path(x.path())
|
||||||
.map_err(|err| Error::Io(io::Error::from(err)).with_path(x.path())),
|
}),
|
||||||
Raw(ref x) => x.metadata(),
|
Raw(ref x) => x.metadata(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,9 +305,7 @@ impl DirEntryRaw {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn file_name(&self) -> &OsStr {
|
fn file_name(&self) -> &OsStr {
|
||||||
self.path
|
self.path.file_name().unwrap_or_else(|| self.path.as_os_str())
|
||||||
.file_name()
|
|
||||||
.unwrap_or_else(|| self.path.as_os_str())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn depth(&self) -> usize {
|
fn depth(&self) -> usize {
|
||||||
@@ -330,13 +317,13 @@ impl DirEntryRaw {
|
|||||||
self.ino
|
self.ino
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_entry(depth: usize, ent: &fs::DirEntry) -> Result<DirEntryRaw, Error> {
|
fn from_entry(
|
||||||
|
depth: usize,
|
||||||
|
ent: &fs::DirEntry,
|
||||||
|
) -> Result<DirEntryRaw, Error> {
|
||||||
let ty = ent.file_type().map_err(|err| {
|
let ty = ent.file_type().map_err(|err| {
|
||||||
let err = Error::Io(io::Error::from(err)).with_path(ent.path());
|
let err = Error::Io(io::Error::from(err)).with_path(ent.path());
|
||||||
Error::WithDepth {
|
Error::WithDepth { depth: depth, err: Box::new(err) }
|
||||||
depth: depth,
|
|
||||||
err: Box::new(err),
|
|
||||||
}
|
|
||||||
})?;
|
})?;
|
||||||
DirEntryRaw::from_entry_os(depth, ent, ty)
|
DirEntryRaw::from_entry_os(depth, ent, ty)
|
||||||
}
|
}
|
||||||
@@ -349,10 +336,7 @@ impl DirEntryRaw {
|
|||||||
) -> Result<DirEntryRaw, Error> {
|
) -> Result<DirEntryRaw, Error> {
|
||||||
let md = ent.metadata().map_err(|err| {
|
let md = ent.metadata().map_err(|err| {
|
||||||
let err = Error::Io(io::Error::from(err)).with_path(ent.path());
|
let err = Error::Io(io::Error::from(err)).with_path(ent.path());
|
||||||
Error::WithDepth {
|
Error::WithDepth { depth: depth, err: Box::new(err) }
|
||||||
depth: depth,
|
|
||||||
err: Box::new(err),
|
|
||||||
}
|
|
||||||
})?;
|
})?;
|
||||||
Ok(DirEntryRaw {
|
Ok(DirEntryRaw {
|
||||||
path: ent.path(),
|
path: ent.path(),
|
||||||
@@ -394,8 +378,13 @@ impl DirEntryRaw {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn from_path(depth: usize, pb: PathBuf, link: bool) -> Result<DirEntryRaw, Error> {
|
fn from_path(
|
||||||
let md = fs::metadata(&pb).map_err(|err| Error::Io(err).with_path(&pb))?;
|
depth: usize,
|
||||||
|
pb: PathBuf,
|
||||||
|
link: bool,
|
||||||
|
) -> Result<DirEntryRaw, Error> {
|
||||||
|
let md =
|
||||||
|
fs::metadata(&pb).map_err(|err| Error::Io(err).with_path(&pb))?;
|
||||||
Ok(DirEntryRaw {
|
Ok(DirEntryRaw {
|
||||||
path: pb,
|
path: pb,
|
||||||
ty: md.file_type(),
|
ty: md.file_type(),
|
||||||
@@ -406,10 +395,15 @@ impl DirEntryRaw {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn from_path(depth: usize, pb: PathBuf, link: bool) -> Result<DirEntryRaw, Error> {
|
fn from_path(
|
||||||
|
depth: usize,
|
||||||
|
pb: PathBuf,
|
||||||
|
link: bool,
|
||||||
|
) -> Result<DirEntryRaw, Error> {
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
|
||||||
let md = fs::metadata(&pb).map_err(|err| Error::Io(err).with_path(&pb))?;
|
let md =
|
||||||
|
fs::metadata(&pb).map_err(|err| Error::Io(err).with_path(&pb))?;
|
||||||
Ok(DirEntryRaw {
|
Ok(DirEntryRaw {
|
||||||
path: pb,
|
path: pb,
|
||||||
ty: md.file_type(),
|
ty: md.file_type(),
|
||||||
@@ -421,7 +415,11 @@ impl DirEntryRaw {
|
|||||||
|
|
||||||
// Placeholder implementation to allow compiling on non-standard platforms (e.g. wasm32).
|
// Placeholder implementation to allow compiling on non-standard platforms (e.g. wasm32).
|
||||||
#[cfg(not(any(windows, unix)))]
|
#[cfg(not(any(windows, unix)))]
|
||||||
fn from_path(depth: usize, pb: PathBuf, link: bool) -> Result<DirEntryRaw, Error> {
|
fn from_path(
|
||||||
|
depth: usize,
|
||||||
|
pb: PathBuf,
|
||||||
|
link: bool,
|
||||||
|
) -> Result<DirEntryRaw, Error> {
|
||||||
Err(Error::Io(io::Error::new(
|
Err(Error::Io(io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
"unsupported platform",
|
"unsupported platform",
|
||||||
@@ -492,7 +490,9 @@ pub struct WalkBuilder {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum Sorter {
|
enum Sorter {
|
||||||
ByName(Arc<dyn Fn(&OsStr, &OsStr) -> cmp::Ordering + Send + Sync + 'static>),
|
ByName(
|
||||||
|
Arc<dyn Fn(&OsStr, &OsStr) -> cmp::Ordering + Send + Sync + 'static>,
|
||||||
|
),
|
||||||
ByPath(Arc<dyn Fn(&Path, &Path) -> cmp::Ordering + Send + Sync + 'static>),
|
ByPath(Arc<dyn Fn(&Path, &Path) -> cmp::Ordering + Send + Sync + 'static>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,10 +552,14 @@ impl WalkBuilder {
|
|||||||
if let Some(ref sorter) = sorter {
|
if let Some(ref sorter) = sorter {
|
||||||
match sorter.clone() {
|
match sorter.clone() {
|
||||||
Sorter::ByName(cmp) => {
|
Sorter::ByName(cmp) => {
|
||||||
wd = wd.sort_by(move |a, b| cmp(a.file_name(), b.file_name()));
|
wd = wd.sort_by(move |a, b| {
|
||||||
|
cmp(a.file_name(), b.file_name())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Sorter::ByPath(cmp) => {
|
Sorter::ByPath(cmp) => {
|
||||||
wd = wd.sort_by(move |a, b| cmp(a.path(), b.path()));
|
wd = wd.sort_by(move |a, b| {
|
||||||
|
cmp(a.path(), b.path())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -780,6 +784,16 @@ impl WalkBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether a git repository is required to apply git-related ignore
|
||||||
|
/// rules (global rules, .gitignore and local exclude rules).
|
||||||
|
///
|
||||||
|
/// When disabled, git-related ignore rules are applied even when searching
|
||||||
|
/// outside a git repository.
|
||||||
|
pub fn require_git(&mut self, yes: bool) -> &mut WalkBuilder {
|
||||||
|
self.ig_builder.require_git(yes);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Process ignore files case insensitively
|
/// Process ignore files case insensitively
|
||||||
///
|
///
|
||||||
/// This is disabled by default.
|
/// This is disabled by default.
|
||||||
@@ -1004,11 +1018,7 @@ enum WalkEvent {
|
|||||||
|
|
||||||
impl From<WalkDir> for WalkEventIter {
|
impl From<WalkDir> for WalkEventIter {
|
||||||
fn from(it: WalkDir) -> WalkEventIter {
|
fn from(it: WalkDir) -> WalkEventIter {
|
||||||
WalkEventIter {
|
WalkEventIter { depth: 0, it: it.into_iter(), next: None }
|
||||||
depth: 0,
|
|
||||||
it: it.into_iter(),
|
|
||||||
next: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1033,7 +1043,7 @@ impl Iterator for WalkEventIter {
|
|||||||
None => None,
|
None => None,
|
||||||
Some(Err(err)) => Some(Err(err)),
|
Some(Err(err)) => Some(Err(err)),
|
||||||
Some(Ok(dent)) => {
|
Some(Ok(dent)) => {
|
||||||
if dent.file_type().is_dir() {
|
if walkdir_is_dir(&dent) {
|
||||||
self.depth += 1;
|
self.depth += 1;
|
||||||
Some(Ok(WalkEvent::Dir(dent)))
|
Some(Ok(WalkEvent::Dir(dent)))
|
||||||
} else {
|
} else {
|
||||||
@@ -1063,11 +1073,70 @@ pub enum WalkState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WalkState {
|
impl WalkState {
|
||||||
|
fn is_continue(&self) -> bool {
|
||||||
|
*self == WalkState::Continue
|
||||||
|
}
|
||||||
|
|
||||||
fn is_quit(&self) -> bool {
|
fn is_quit(&self) -> bool {
|
||||||
*self == WalkState::Quit
|
*self == WalkState::Quit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A builder for constructing a visitor when using
|
||||||
|
/// [`WalkParallel::visit`](struct.WalkParallel.html#method.visit). The builder
|
||||||
|
/// will be called for each thread started by `WalkParallel`. The visitor
|
||||||
|
/// returned from each builder is then called for every directory entry.
|
||||||
|
pub trait ParallelVisitorBuilder<'s> {
|
||||||
|
/// Create per-thread `ParallelVisitor`s for `WalkParallel`.
|
||||||
|
fn build(&mut self) -> Box<dyn ParallelVisitor + 's>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, 's, P: ParallelVisitorBuilder<'s>> ParallelVisitorBuilder<'s>
|
||||||
|
for &'a mut P
|
||||||
|
{
|
||||||
|
fn build(&mut self) -> Box<dyn ParallelVisitor + 's> {
|
||||||
|
(**self).build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Receives files and directories for the current thread.
|
||||||
|
///
|
||||||
|
/// Setup for the traversal can be implemented as part of
|
||||||
|
/// [`ParallelVisitorBuilder::build`](trait.ParallelVisitorBuilder.html#tymethod.build).
|
||||||
|
/// Teardown when traversal finishes can be implemented by implementing the
|
||||||
|
/// `Drop` trait on your traversal type.
|
||||||
|
pub trait ParallelVisitor: Send {
|
||||||
|
/// Receives files and directories for the current thread. This is called
|
||||||
|
/// once for every directory entry visited by traversal.
|
||||||
|
fn visit(&mut self, entry: Result<DirEntry, Error>) -> WalkState;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FnBuilder<F> {
|
||||||
|
builder: F,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s, F: FnMut() -> FnVisitor<'s>> ParallelVisitorBuilder<'s>
|
||||||
|
for FnBuilder<F>
|
||||||
|
{
|
||||||
|
fn build(&mut self) -> Box<dyn ParallelVisitor + 's> {
|
||||||
|
let visitor = (self.builder)();
|
||||||
|
Box::new(FnVisitorImp { visitor })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type FnVisitor<'s> =
|
||||||
|
Box<dyn FnMut(Result<DirEntry, Error>) -> WalkState + Send + 's>;
|
||||||
|
|
||||||
|
struct FnVisitorImp<'s> {
|
||||||
|
visitor: FnVisitor<'s>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> ParallelVisitor for FnVisitorImp<'s> {
|
||||||
|
fn visit(&mut self, entry: Result<DirEntry, Error>) -> WalkState {
|
||||||
|
(self.visitor)(entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// WalkParallel is a parallel recursive directory iterator over files paths
|
/// WalkParallel is a parallel recursive directory iterator over files paths
|
||||||
/// in one or more directories.
|
/// in one or more directories.
|
||||||
///
|
///
|
||||||
@@ -1091,11 +1160,31 @@ impl WalkParallel {
|
|||||||
/// Execute the parallel recursive directory iterator. `mkf` is called
|
/// Execute the parallel recursive directory iterator. `mkf` is called
|
||||||
/// for each thread used for iteration. The function produced by `mkf`
|
/// for each thread used for iteration. The function produced by `mkf`
|
||||||
/// is then in turn called for each visited file path.
|
/// is then in turn called for each visited file path.
|
||||||
pub fn run<F>(self, mut mkf: F)
|
pub fn run<'s, F>(self, mkf: F)
|
||||||
where
|
where
|
||||||
F: FnMut() -> Box<dyn FnMut(Result<DirEntry, Error>) -> WalkState + Send + 'static>,
|
F: FnMut() -> FnVisitor<'s>,
|
||||||
{
|
{
|
||||||
let mut f = mkf();
|
self.visit(&mut FnBuilder { builder: mkf })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Execute the parallel recursive directory iterator using a custom
|
||||||
|
/// visitor.
|
||||||
|
///
|
||||||
|
/// The builder given is used to construct a visitor for every thread
|
||||||
|
/// used by this traversal. The visitor returned from each builder is then
|
||||||
|
/// called for every directory entry seen by that thread.
|
||||||
|
///
|
||||||
|
/// Typically, creating a custom visitor is useful if you need to perform
|
||||||
|
/// some kind of cleanup once traversal is finished. This can be achieved
|
||||||
|
/// by implementing `Drop` for your builder (or for your visitor, if you
|
||||||
|
/// want to execute cleanup for every thread that is launched).
|
||||||
|
///
|
||||||
|
/// For example, each visitor might build up a data structure of results
|
||||||
|
/// corresponding to the directory entries seen for each thread. Since each
|
||||||
|
/// visitor runs on only one thread, this build-up can be done without
|
||||||
|
/// synchronization. Then, once traversal is complete, all of the results
|
||||||
|
/// can be merged together into a single data structure.
|
||||||
|
pub fn visit(mut self, builder: &mut dyn ParallelVisitorBuilder) {
|
||||||
let threads = self.threads();
|
let threads = self.threads();
|
||||||
// TODO: Figure out how to use a bounded channel here. With an
|
// TODO: Figure out how to use a bounded channel here. With an
|
||||||
// unbounded channel, the workers can run away and fill up memory
|
// unbounded channel, the workers can run away and fill up memory
|
||||||
@@ -1106,78 +1195,81 @@ impl WalkParallel {
|
|||||||
// this. The best case scenario would be finding a way to use rayon
|
// this. The best case scenario would be finding a way to use rayon
|
||||||
// to do this.
|
// to do this.
|
||||||
let (tx, rx) = channel::unbounded();
|
let (tx, rx) = channel::unbounded();
|
||||||
let mut any_work = false;
|
{
|
||||||
// Send the initial set of root paths to the pool of workers.
|
let mut visitor = builder.build();
|
||||||
// Note that we only send directories. For files, we send to them the
|
let mut paths = Vec::new().into_iter();
|
||||||
// callback directly.
|
std::mem::swap(&mut paths, &mut self.paths);
|
||||||
for path in self.paths {
|
// Send the initial set of root paths to the pool of workers. Note
|
||||||
let (dent, root_device) = if path == Path::new("-") {
|
// that we only send directories. For files, we send to them the
|
||||||
(DirEntry::new_stdin(), None)
|
// callback directly.
|
||||||
} else {
|
for path in paths {
|
||||||
let root_device = if !self.same_file_system {
|
let (dent, root_device) = if path == Path::new("-") {
|
||||||
None
|
(DirEntry::new_stdin(), None)
|
||||||
} else {
|
} else {
|
||||||
match device_num(&path) {
|
let root_device = if !self.same_file_system {
|
||||||
Ok(root_device) => Some(root_device),
|
None
|
||||||
|
} else {
|
||||||
|
match device_num(&path) {
|
||||||
|
Ok(root_device) => Some(root_device),
|
||||||
|
Err(err) => {
|
||||||
|
let err = Error::Io(err).with_path(path);
|
||||||
|
if visitor.visit(Err(err)).is_quit() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match DirEntryRaw::from_path(0, path, false) {
|
||||||
|
Ok(dent) => {
|
||||||
|
(DirEntry::new_raw(dent, None), root_device)
|
||||||
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let err = Error::Io(err).with_path(path);
|
if visitor.visit(Err(err)).is_quit() {
|
||||||
if f(Err(err)).is_quit() {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match DirEntryRaw::from_path(0, path, false) {
|
tx.send(Message::Work(Work {
|
||||||
Ok(dent) => (DirEntry::new_raw(dent, None), root_device),
|
dent: dent,
|
||||||
Err(err) => {
|
ignore: self.ig_root.clone(),
|
||||||
if f(Err(err)).is_quit() {
|
root_device: root_device,
|
||||||
return;
|
}))
|
||||||
}
|
.unwrap();
|
||||||
continue;
|
}
|
||||||
}
|
// ... but there's no need to start workers if we don't need them.
|
||||||
}
|
if tx.is_empty() {
|
||||||
};
|
return;
|
||||||
tx.send(Message::Work(Work {
|
}
|
||||||
dent: dent,
|
|
||||||
ignore: self.ig_root.clone(),
|
|
||||||
root_device: root_device,
|
|
||||||
}))
|
|
||||||
.unwrap();
|
|
||||||
any_work = true;
|
|
||||||
}
|
|
||||||
// ... but there's no need to start workers if we don't need them.
|
|
||||||
if !any_work {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Create the workers and then wait for them to finish.
|
// Create the workers and then wait for them to finish.
|
||||||
let num_waiting = Arc::new(AtomicUsize::new(0));
|
|
||||||
let num_quitting = Arc::new(AtomicUsize::new(0));
|
|
||||||
let quit_now = Arc::new(AtomicBool::new(false));
|
let quit_now = Arc::new(AtomicBool::new(false));
|
||||||
let mut handles = vec![];
|
let num_pending = Arc::new(AtomicUsize::new(tx.len()));
|
||||||
for _ in 0..threads {
|
crossbeam_utils::thread::scope(|s| {
|
||||||
let worker = Worker {
|
let mut handles = vec![];
|
||||||
f: mkf(),
|
for _ in 0..threads {
|
||||||
tx: tx.clone(),
|
let worker = Worker {
|
||||||
rx: rx.clone(),
|
visitor: builder.build(),
|
||||||
quit_now: quit_now.clone(),
|
tx: tx.clone(),
|
||||||
is_waiting: false,
|
rx: rx.clone(),
|
||||||
is_quitting: false,
|
quit_now: quit_now.clone(),
|
||||||
num_waiting: num_waiting.clone(),
|
num_pending: num_pending.clone(),
|
||||||
num_quitting: num_quitting.clone(),
|
max_depth: self.max_depth,
|
||||||
threads: threads,
|
max_filesize: self.max_filesize,
|
||||||
max_depth: self.max_depth,
|
follow_links: self.follow_links,
|
||||||
max_filesize: self.max_filesize,
|
skip: self.skip.clone(),
|
||||||
follow_links: self.follow_links,
|
};
|
||||||
skip: self.skip.clone(),
|
handles.push(s.spawn(|_| worker.run()));
|
||||||
};
|
}
|
||||||
handles.push(thread::spawn(|| worker.run()));
|
drop(tx);
|
||||||
}
|
drop(rx);
|
||||||
drop(tx);
|
for handle in handles {
|
||||||
drop(rx);
|
handle.join().unwrap();
|
||||||
for handle in handles {
|
}
|
||||||
handle.join().unwrap();
|
})
|
||||||
}
|
.unwrap(); // Pass along panics from threads
|
||||||
}
|
}
|
||||||
|
|
||||||
fn threads(&self) -> usize {
|
fn threads(&self) -> usize {
|
||||||
@@ -1195,7 +1287,7 @@ enum Message {
|
|||||||
/// Work items for entries that should be skipped or ignored should not
|
/// Work items for entries that should be skipped or ignored should not
|
||||||
/// be produced.
|
/// be produced.
|
||||||
Work(Work),
|
Work(Work),
|
||||||
/// This instruction indicates that the worker should start quitting.
|
/// This instruction indicates that the worker should quit.
|
||||||
Quit,
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1267,28 +1359,19 @@ impl Work {
|
|||||||
/// ignore matchers, producing new work and invoking the caller's callback.
|
/// ignore matchers, producing new work and invoking the caller's callback.
|
||||||
///
|
///
|
||||||
/// Note that a worker is *both* a producer and a consumer.
|
/// Note that a worker is *both* a producer and a consumer.
|
||||||
struct Worker {
|
struct Worker<'s> {
|
||||||
/// The caller's callback.
|
/// The caller's callback.
|
||||||
f: Box<dyn FnMut(Result<DirEntry, Error>) -> WalkState + Send + 'static>,
|
visitor: Box<dyn ParallelVisitor + 's>,
|
||||||
/// The push side of our mpmc queue.
|
/// The push side of our mpmc queue.
|
||||||
tx: channel::Sender<Message>,
|
tx: channel::Sender<Message>,
|
||||||
/// The receive side of our mpmc queue.
|
/// The receive side of our mpmc queue.
|
||||||
rx: channel::Receiver<Message>,
|
rx: channel::Receiver<Message>,
|
||||||
/// Whether all workers should quit at the next opportunity. Note that
|
/// Whether all workers should terminate at the next opportunity. Note
|
||||||
/// this is distinct from quitting because of exhausting the contents of
|
/// that we need this because we don't want other `Work` to be done after
|
||||||
/// a directory. Instead, this is used when the caller's callback indicates
|
/// we quit. We wouldn't need this if have a priority channel.
|
||||||
/// that the iterator should quit immediately.
|
|
||||||
quit_now: Arc<AtomicBool>,
|
quit_now: Arc<AtomicBool>,
|
||||||
/// Whether this worker is waiting for more work.
|
/// The number of outstanding work items.
|
||||||
is_waiting: bool,
|
num_pending: Arc<AtomicUsize>,
|
||||||
/// Whether this worker has started to quit.
|
|
||||||
is_quitting: bool,
|
|
||||||
/// The number of workers waiting for more work.
|
|
||||||
num_waiting: Arc<AtomicUsize>,
|
|
||||||
/// The number of workers waiting to quit.
|
|
||||||
num_quitting: Arc<AtomicUsize>,
|
|
||||||
/// The total number of workers.
|
|
||||||
threads: usize,
|
|
||||||
/// The maximum depth of directories to descend. A value of `0` means no
|
/// The maximum depth of directories to descend. A value of `0` means no
|
||||||
/// descension at all.
|
/// descension at all.
|
||||||
max_depth: Option<usize>,
|
max_depth: Option<usize>,
|
||||||
@@ -1303,84 +1386,95 @@ struct Worker {
|
|||||||
skip: Option<Arc<Handle>>,
|
skip: Option<Arc<Handle>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Worker {
|
impl<'s> Worker<'s> {
|
||||||
/// Runs this worker until there is no more work left to do.
|
/// Runs this worker until there is no more work left to do.
|
||||||
///
|
///
|
||||||
/// The worker will call the caller's callback for all entries that aren't
|
/// The worker will call the caller's callback for all entries that aren't
|
||||||
/// skipped by the ignore matcher.
|
/// skipped by the ignore matcher.
|
||||||
fn run(mut self) {
|
fn run(mut self) {
|
||||||
while let Some(mut work) = self.get_work() {
|
while let Some(work) = self.get_work() {
|
||||||
// If the work is not a directory, then we can just execute the
|
if let WalkState::Quit = self.run_one(work) {
|
||||||
// caller's callback immediately and move on.
|
self.quit_now();
|
||||||
if work.is_symlink() || !work.is_dir() {
|
|
||||||
if (self.f)(Ok(work.dent)).is_quit() {
|
|
||||||
self.quit_now();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if let Some(err) = work.add_parents() {
|
|
||||||
if (self.f)(Err(err)).is_quit() {
|
|
||||||
self.quit_now();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let readdir = match work.read_dir() {
|
|
||||||
Ok(readdir) => readdir,
|
|
||||||
Err(err) => {
|
|
||||||
if (self.f)(Err(err)).is_quit() {
|
|
||||||
self.quit_now();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let descend = if let Some(root_device) = work.root_device {
|
|
||||||
match is_same_file_system(root_device, work.dent.path()) {
|
|
||||||
Ok(true) => true,
|
|
||||||
Ok(false) => false,
|
|
||||||
Err(err) => {
|
|
||||||
if (self.f)(Err(err)).is_quit() {
|
|
||||||
self.quit_now();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
};
|
|
||||||
|
|
||||||
let depth = work.dent.depth();
|
|
||||||
match (self.f)(Ok(work.dent)) {
|
|
||||||
WalkState::Continue => {}
|
|
||||||
WalkState::Skip => continue,
|
|
||||||
WalkState::Quit => {
|
|
||||||
self.quit_now();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !descend {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if self.max_depth.map_or(false, |max| depth >= max) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for result in readdir {
|
|
||||||
let state = self.run_one(&work.ignore, depth + 1, work.root_device, result);
|
|
||||||
if state.is_quit() {
|
|
||||||
self.quit_now();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
self.work_done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the worker on a single entry from a directory iterator.
|
fn run_one(&mut self, mut work: Work) -> WalkState {
|
||||||
|
// If the work is not a directory, then we can just execute the
|
||||||
|
// caller's callback immediately and move on.
|
||||||
|
if work.is_symlink() || !work.is_dir() {
|
||||||
|
return self.visitor.visit(Ok(work.dent));
|
||||||
|
}
|
||||||
|
if let Some(err) = work.add_parents() {
|
||||||
|
let state = self.visitor.visit(Err(err));
|
||||||
|
if state.is_quit() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let descend = if let Some(root_device) = work.root_device {
|
||||||
|
match is_same_file_system(root_device, work.dent.path()) {
|
||||||
|
Ok(true) => true,
|
||||||
|
Ok(false) => false,
|
||||||
|
Err(err) => {
|
||||||
|
let state = self.visitor.visit(Err(err));
|
||||||
|
if state.is_quit() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
// Try to read the directory first before we transfer ownership
|
||||||
|
// to the provided closure. Do not unwrap it immediately, though,
|
||||||
|
// as we may receive an `Err` value e.g. in the case when we do not
|
||||||
|
// have sufficient read permissions to list the directory.
|
||||||
|
// In that case we still want to provide the closure with a valid
|
||||||
|
// entry before passing the error value.
|
||||||
|
let readdir = work.read_dir();
|
||||||
|
let depth = work.dent.depth();
|
||||||
|
let state = self.visitor.visit(Ok(work.dent));
|
||||||
|
if !state.is_continue() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
if !descend {
|
||||||
|
return WalkState::Skip;
|
||||||
|
}
|
||||||
|
|
||||||
|
let readdir = match readdir {
|
||||||
|
Ok(readdir) => readdir,
|
||||||
|
Err(err) => {
|
||||||
|
return self.visitor.visit(Err(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if self.max_depth.map_or(false, |max| depth >= max) {
|
||||||
|
return WalkState::Skip;
|
||||||
|
}
|
||||||
|
for result in readdir {
|
||||||
|
let state = self.generate_work(
|
||||||
|
&work.ignore,
|
||||||
|
depth + 1,
|
||||||
|
work.root_device,
|
||||||
|
result,
|
||||||
|
);
|
||||||
|
if state.is_quit() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WalkState::Continue
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decides whether to submit the given directory entry as a file to
|
||||||
|
/// search.
|
||||||
///
|
///
|
||||||
/// If the entry is a path that should be ignored, then this is a no-op.
|
/// If the entry is a path that should be ignored, then this is a no-op.
|
||||||
/// Otherwise, the entry is pushed on to the queue. (The actual execution
|
/// Otherwise, the entry is pushed on to the queue. (The actual execution
|
||||||
/// of the callback happens in `run`.)
|
/// of the callback happens in `run_one`.)
|
||||||
///
|
///
|
||||||
/// If an error occurs while reading the entry, then it is sent to the
|
/// If an error occurs while reading the entry, then it is sent to the
|
||||||
/// caller's callback.
|
/// caller's callback.
|
||||||
@@ -1388,7 +1482,7 @@ impl Worker {
|
|||||||
/// `ig` is the `Ignore` matcher for the parent directory. `depth` should
|
/// `ig` is the `Ignore` matcher for the parent directory. `depth` should
|
||||||
/// be the depth of this entry. `result` should be the item yielded by
|
/// be the depth of this entry. `result` should be the item yielded by
|
||||||
/// a directory iterator.
|
/// a directory iterator.
|
||||||
fn run_one(
|
fn generate_work(
|
||||||
&mut self,
|
&mut self,
|
||||||
ig: &Ignore,
|
ig: &Ignore,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
@@ -1398,13 +1492,15 @@ impl Worker {
|
|||||||
let fs_dent = match result {
|
let fs_dent = match result {
|
||||||
Ok(fs_dent) => fs_dent,
|
Ok(fs_dent) => fs_dent,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return (self.f)(Err(Error::from(err).with_depth(depth)));
|
return self
|
||||||
|
.visitor
|
||||||
|
.visit(Err(Error::from(err).with_depth(depth)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut dent = match DirEntryRaw::from_entry(depth, &fs_dent) {
|
let mut dent = match DirEntryRaw::from_entry(depth, &fs_dent) {
|
||||||
Ok(dent) => DirEntry::new_raw(dent, None),
|
Ok(dent) => DirEntry::new_raw(dent, None),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return (self.f)(Err(err));
|
return self.visitor.visit(Err(err));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let is_symlink = dent.file_type().map_or(false, |ft| ft.is_symlink());
|
let is_symlink = dent.file_type().map_or(false, |ft| ft.is_symlink());
|
||||||
@@ -1413,43 +1509,38 @@ impl Worker {
|
|||||||
dent = match DirEntryRaw::from_path(depth, path, true) {
|
dent = match DirEntryRaw::from_path(depth, path, true) {
|
||||||
Ok(dent) => DirEntry::new_raw(dent, None),
|
Ok(dent) => DirEntry::new_raw(dent, None),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return (self.f)(Err(err));
|
return self.visitor.visit(Err(err));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if dent.is_dir() {
|
if dent.is_dir() {
|
||||||
if let Err(err) = check_symlink_loop(ig, dent.path(), depth) {
|
if let Err(err) = check_symlink_loop(ig, dent.path(), depth) {
|
||||||
return (self.f)(Err(err));
|
return self.visitor.visit(Err(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(ref stdout) = self.skip {
|
if let Some(ref stdout) = self.skip {
|
||||||
let is_stdout = match path_equals(&dent, stdout) {
|
let is_stdout = match path_equals(&dent, stdout) {
|
||||||
Ok(is_stdout) => is_stdout,
|
Ok(is_stdout) => is_stdout,
|
||||||
Err(err) => return (self.f)(Err(err)),
|
Err(err) => return self.visitor.visit(Err(err)),
|
||||||
};
|
};
|
||||||
if is_stdout {
|
if is_stdout {
|
||||||
return WalkState::Continue;
|
return WalkState::Continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let should_skip_path = should_skip_entry(ig, &dent);
|
let should_skip_path = should_skip_entry(ig, &dent);
|
||||||
let should_skip_filesize = if self.max_filesize.is_some() && !dent.is_dir() {
|
let should_skip_filesize =
|
||||||
skip_filesize(
|
if self.max_filesize.is_some() && !dent.is_dir() {
|
||||||
self.max_filesize.unwrap(),
|
skip_filesize(
|
||||||
dent.path(),
|
self.max_filesize.unwrap(),
|
||||||
&dent.metadata().ok(),
|
dent.path(),
|
||||||
)
|
&dent.metadata().ok(),
|
||||||
} else {
|
)
|
||||||
false
|
} else {
|
||||||
};
|
false
|
||||||
|
};
|
||||||
|
|
||||||
if !should_skip_path && !should_skip_filesize {
|
if !should_skip_path && !should_skip_filesize {
|
||||||
self.tx
|
self.send(Work { dent, ignore: ig.clone(), root_device });
|
||||||
.send(Message::Work(Work {
|
|
||||||
dent: dent,
|
|
||||||
ignore: ig.clone(),
|
|
||||||
root_device: root_device,
|
|
||||||
}))
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
WalkState::Continue
|
WalkState::Continue
|
||||||
}
|
}
|
||||||
@@ -1459,64 +1550,47 @@ impl Worker {
|
|||||||
/// If all work has been exhausted, then this returns None. The worker
|
/// If all work has been exhausted, then this returns None. The worker
|
||||||
/// should then subsequently quit.
|
/// should then subsequently quit.
|
||||||
fn get_work(&mut self) -> Option<Work> {
|
fn get_work(&mut self) -> Option<Work> {
|
||||||
|
let mut value = self.rx.try_recv();
|
||||||
loop {
|
loop {
|
||||||
|
// Simulate a priority channel: If quit_now flag is set, we can
|
||||||
|
// receive only quit messages.
|
||||||
if self.is_quit_now() {
|
if self.is_quit_now() {
|
||||||
return None;
|
value = Ok(Message::Quit)
|
||||||
}
|
}
|
||||||
match self.rx.try_recv() {
|
match value {
|
||||||
Ok(Message::Work(work)) => {
|
Ok(Message::Work(work)) => {
|
||||||
self.waiting(false);
|
|
||||||
self.quitting(false);
|
|
||||||
return Some(work);
|
return Some(work);
|
||||||
}
|
}
|
||||||
Ok(Message::Quit) => {
|
Ok(Message::Quit) => {
|
||||||
// We can't just quit because a Message::Quit could be
|
// Repeat quit message to wake up sleeping threads, if
|
||||||
// spurious. For example, it's possible to observe that
|
// any. The domino effect will ensure that every thread
|
||||||
// all workers are waiting even if there's more work to
|
// will quit.
|
||||||
// be done.
|
self.tx.send(Message::Quit).unwrap();
|
||||||
//
|
return None;
|
||||||
// Therefore, we do a bit of a dance to wait until all
|
|
||||||
// workers have signaled that they're ready to quit before
|
|
||||||
// actually quitting.
|
|
||||||
//
|
|
||||||
// If the Quit message turns out to be spurious, then the
|
|
||||||
// loop below will break and we'll go back to looking for
|
|
||||||
// more work.
|
|
||||||
self.waiting(true);
|
|
||||||
self.quitting(true);
|
|
||||||
while !self.is_quit_now() {
|
|
||||||
let nwait = self.num_waiting();
|
|
||||||
let nquit = self.num_quitting();
|
|
||||||
// If the number of waiting workers dropped, then
|
|
||||||
// abort our attempt to quit.
|
|
||||||
if nwait < self.threads {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// If all workers are in this quit loop, then we
|
|
||||||
// can stop.
|
|
||||||
if nquit == self.threads {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
// Otherwise, spin.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(TryRecvError::Empty) => {
|
||||||
self.waiting(true);
|
// Once num_pending reaches 0, it is impossible for it to
|
||||||
self.quitting(false);
|
// ever increase again. Namely, it only reaches 0 once
|
||||||
if self.num_waiting() == self.threads {
|
// all jobs have run such that no jobs have produced more
|
||||||
for _ in 0..self.threads {
|
// work. We have this guarantee because num_pending is
|
||||||
self.tx.send(Message::Quit).unwrap();
|
// always incremented before each job is submitted and only
|
||||||
}
|
// decremented once each job is completely finished.
|
||||||
} else {
|
// Therefore, if this reaches zero, then there can be no
|
||||||
// You're right to consider this suspicious, but it's
|
// other job running.
|
||||||
// a useful heuristic to permit producers to catch up
|
if self.num_pending() == 0 {
|
||||||
// to consumers without burning the CPU. It is also
|
// Every other thread is blocked at the next recv().
|
||||||
// useful as a means to prevent burning the CPU if only
|
// Send the initial quit message and quit.
|
||||||
// one worker is left doing actual work. It's not
|
self.tx.send(Message::Quit).unwrap();
|
||||||
// perfect and it doesn't leave the CPU completely
|
return None;
|
||||||
// idle, but it's not clear what else we can do. :-/
|
|
||||||
thread::sleep(Duration::from_millis(1));
|
|
||||||
}
|
}
|
||||||
|
// Wait for next `Work` or `Quit` message.
|
||||||
|
value = Ok(self
|
||||||
|
.rx
|
||||||
|
.recv()
|
||||||
|
.expect("channel disconnected while worker is alive"));
|
||||||
|
}
|
||||||
|
Err(TryRecvError::Disconnected) => {
|
||||||
|
unreachable!("channel disconnected while worker is alive");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1532,44 +1606,20 @@ impl Worker {
|
|||||||
self.quit_now.load(Ordering::SeqCst)
|
self.quit_now.load(Ordering::SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the total number of workers waiting for work.
|
/// Returns the number of pending jobs.
|
||||||
fn num_waiting(&self) -> usize {
|
fn num_pending(&self) -> usize {
|
||||||
self.num_waiting.load(Ordering::SeqCst)
|
self.num_pending.load(Ordering::SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the total number of workers ready to quit.
|
/// Send work.
|
||||||
fn num_quitting(&self) -> usize {
|
fn send(&self, work: Work) {
|
||||||
self.num_quitting.load(Ordering::SeqCst)
|
self.num_pending.fetch_add(1, Ordering::SeqCst);
|
||||||
|
self.tx.send(Message::Work(work)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets this worker's "quitting" state to the value of `yes`.
|
/// Signal that work has been received.
|
||||||
fn quitting(&mut self, yes: bool) {
|
fn work_done(&self) {
|
||||||
if yes {
|
self.num_pending.fetch_sub(1, Ordering::SeqCst);
|
||||||
if !self.is_quitting {
|
|
||||||
self.is_quitting = true;
|
|
||||||
self.num_quitting.fetch_add(1, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if self.is_quitting {
|
|
||||||
self.is_quitting = false;
|
|
||||||
self.num_quitting.fetch_sub(1, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets this worker's "waiting" state to the value of `yes`.
|
|
||||||
fn waiting(&mut self, yes: bool) {
|
|
||||||
if yes {
|
|
||||||
if !self.is_waiting {
|
|
||||||
self.is_waiting = true;
|
|
||||||
self.num_waiting.fetch_add(1, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if self.is_waiting {
|
|
||||||
self.is_waiting = false;
|
|
||||||
self.num_waiting.fetch_sub(1, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1579,18 +1629,11 @@ fn check_symlink_loop(
|
|||||||
child_depth: usize,
|
child_depth: usize,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let hchild = Handle::from_path(child_path).map_err(|err| {
|
let hchild = Handle::from_path(child_path).map_err(|err| {
|
||||||
Error::from(err)
|
Error::from(err).with_path(child_path).with_depth(child_depth)
|
||||||
.with_path(child_path)
|
|
||||||
.with_depth(child_depth)
|
|
||||||
})?;
|
})?;
|
||||||
for ig in ig_parent
|
for ig in ig_parent.parents().take_while(|ig| !ig.is_absolute_parent()) {
|
||||||
.parents()
|
|
||||||
.take_while(|ig| !ig.is_absolute_parent())
|
|
||||||
{
|
|
||||||
let h = Handle::from_path(ig.path()).map_err(|err| {
|
let h = Handle::from_path(ig.path()).map_err(|err| {
|
||||||
Error::from(err)
|
Error::from(err).with_path(child_path).with_depth(child_depth)
|
||||||
.with_path(child_path)
|
|
||||||
.with_depth(child_depth)
|
|
||||||
})?;
|
})?;
|
||||||
if hchild == h {
|
if hchild == h {
|
||||||
return Err(Error::Loop {
|
return Err(Error::Loop {
|
||||||
@@ -1605,7 +1648,11 @@ fn check_symlink_loop(
|
|||||||
|
|
||||||
// Before calling this function, make sure that you ensure that is really
|
// Before calling this function, make sure that you ensure that is really
|
||||||
// necessary as the arguments imply a file stat.
|
// necessary as the arguments imply a file stat.
|
||||||
fn skip_filesize(max_filesize: u64, path: &Path, ent: &Option<Metadata>) -> bool {
|
fn skip_filesize(
|
||||||
|
max_filesize: u64,
|
||||||
|
path: &Path,
|
||||||
|
ent: &Option<Metadata>,
|
||||||
|
) -> bool {
|
||||||
let filesize = match *ent {
|
let filesize = match *ent {
|
||||||
Some(ref md) => Some(md.len()),
|
Some(ref md) => Some(md.len()),
|
||||||
None => None,
|
None => None,
|
||||||
@@ -1682,10 +1729,29 @@ fn path_equals(dent: &DirEntry, handle: &Handle) -> Result<bool, Error> {
|
|||||||
.map_err(|err| Error::Io(err).with_path(dent.path()))
|
.map_err(|err| Error::Io(err).with_path(dent.path()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if the given walkdir entry corresponds to a directory.
|
||||||
|
///
|
||||||
|
/// This is normally just `dent.file_type().is_dir()`, but when we aren't
|
||||||
|
/// following symlinks, the root directory entry may be a symlink to a
|
||||||
|
/// directory that we *do* follow---by virtue of it being specified by the user
|
||||||
|
/// explicitly. In that case, we need to follow the symlink and query whether
|
||||||
|
/// it's a directory or not. But we only do this for root entries to avoid an
|
||||||
|
/// additional stat check in most cases.
|
||||||
|
fn walkdir_is_dir(dent: &walkdir::DirEntry) -> bool {
|
||||||
|
if dent.file_type().is_dir() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if !dent.file_type().is_symlink() || dent.depth() > 0 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
dent.path().metadata().ok().map_or(false, |md| md.file_type().is_dir())
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if and only if the given path is on the same device as the
|
/// Returns true if and only if the given path is on the same device as the
|
||||||
/// given root device.
|
/// given root device.
|
||||||
fn is_same_file_system(root_device: u64, path: &Path) -> Result<bool, Error> {
|
fn is_same_file_system(root_device: u64, path: &Path) -> Result<bool, Error> {
|
||||||
let dent_device = device_num(path).map_err(|err| Error::Io(err).with_path(path))?;
|
let dent_device =
|
||||||
|
device_num(path).map_err(|err| Error::Io(err).with_path(path))?;
|
||||||
Ok(root_device == dent_device)
|
Ok(root_device == dent_device)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1767,7 +1833,10 @@ mod tests {
|
|||||||
paths
|
paths
|
||||||
}
|
}
|
||||||
|
|
||||||
fn walk_collect_parallel(prefix: &Path, builder: &WalkBuilder) -> Vec<String> {
|
fn walk_collect_parallel(
|
||||||
|
prefix: &Path,
|
||||||
|
builder: &WalkBuilder,
|
||||||
|
) -> Vec<String> {
|
||||||
let mut paths = vec![];
|
let mut paths = vec![];
|
||||||
for dent in walk_collect_entries_parallel(builder) {
|
for dent in walk_collect_entries_parallel(builder) {
|
||||||
let path = dent.path().strip_prefix(prefix).unwrap();
|
let path = dent.path().strip_prefix(prefix).unwrap();
|
||||||
@@ -2021,7 +2090,9 @@ mod tests {
|
|||||||
assert_eq!(1, dents.len());
|
assert_eq!(1, dents.len());
|
||||||
assert!(!dents[0].path_is_symlink());
|
assert!(!dents[0].path_is_symlink());
|
||||||
|
|
||||||
let dents = walk_collect_entries_parallel(&WalkBuilder::new(td.path().join("foo")));
|
let dents = walk_collect_entries_parallel(&WalkBuilder::new(
|
||||||
|
td.path().join("foo"),
|
||||||
|
));
|
||||||
assert_eq!(1, dents.len());
|
assert_eq!(1, dents.len());
|
||||||
assert!(!dents[0].path_is_symlink());
|
assert!(!dents[0].path_is_symlink());
|
||||||
}
|
}
|
||||||
@@ -2071,4 +2142,23 @@ mod tests {
|
|||||||
builder.follow_links(true).same_file_system(true);
|
builder.follow_links(true).same_file_system(true);
|
||||||
assert_paths(td.path(), &builder, &["same_file", "same_file/alink"]);
|
assert_paths(td.path(), &builder, &["same_file", "same_file/alink"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
#[test]
|
||||||
|
fn no_read_permissions() {
|
||||||
|
let dir_path = Path::new("/root");
|
||||||
|
|
||||||
|
// There's no /etc/sudoers.d, skip the test.
|
||||||
|
if !dir_path.is_dir() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// We're the root, so the test won't check what we want it to.
|
||||||
|
if fs::read_dir(&dir_path).is_ok() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that we can't descend but get an entry for the parent dir.
|
||||||
|
let builder = WalkBuilder::new(&dir_path);
|
||||||
|
assert_paths(dir_path.parent().unwrap(), &builder, &["root"]);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -55,7 +55,6 @@ fn test_files_in_root() {
|
|||||||
assert!(m("ROOT/file_root_33").is_none());
|
assert!(m("ROOT/file_root_33").is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_files_in_deep() {
|
fn test_files_in_deep() {
|
||||||
let gitignore = get_gitignore();
|
let gitignore = get_gitignore();
|
||||||
@@ -88,7 +87,6 @@ fn test_files_in_deep() {
|
|||||||
assert!(m("ROOT/parent_dir/file_deep_33").is_none());
|
assert!(m("ROOT/parent_dir/file_deep_33").is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dirs_in_root() {
|
fn test_dirs_in_root() {
|
||||||
let gitignore = get_gitignore();
|
let gitignore = get_gitignore();
|
||||||
@@ -193,7 +191,6 @@ fn test_dirs_in_root() {
|
|||||||
assert!(m("ROOT/dir_root_33/child_dir/file", false).is_ignore());
|
assert!(m("ROOT/dir_root_33/child_dir/file", false).is_ignore());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dirs_in_deep() {
|
fn test_dirs_in_deep() {
|
||||||
let gitignore = get_gitignore();
|
let gitignore = get_gitignore();
|
||||||
@@ -205,17 +202,13 @@ fn test_dirs_in_deep() {
|
|||||||
assert!(m("ROOT/parent_dir/dir_deep_00", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_00", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_00/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_00/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_00/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_00/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_00/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_00/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 01
|
// 01
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_01", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_01", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_01/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_01/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_01/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_01/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_01/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_01/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 02
|
// 02
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_02", true).is_none());
|
assert!(m("ROOT/parent_dir/dir_deep_02", true).is_none());
|
||||||
@@ -257,67 +250,51 @@ fn test_dirs_in_deep() {
|
|||||||
assert!(m("ROOT/parent_dir/dir_deep_20", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_20", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_20/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_20/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_20/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_20/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_20/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_20/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 21
|
// 21
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_21", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_21", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_21/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_21/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_21/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_21/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_21/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_21/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 22
|
// 22
|
||||||
// dir itself doesn't match
|
// dir itself doesn't match
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_22", true).is_none());
|
assert!(m("ROOT/parent_dir/dir_deep_22", true).is_none());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_22/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_22/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_22/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_22/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_22/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_22/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 23
|
// 23
|
||||||
// dir itself doesn't match
|
// dir itself doesn't match
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_23", true).is_none());
|
assert!(m("ROOT/parent_dir/dir_deep_23", true).is_none());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_23/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_23/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_23/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_23/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_23/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_23/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 30
|
// 30
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_30", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_30", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_30/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_30/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_30/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_30/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_30/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_30/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 31
|
// 31
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_31", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_31", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_31/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_31/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_31/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_31/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_31/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_31/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 32
|
// 32
|
||||||
// dir itself doesn't match
|
// dir itself doesn't match
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_32", true).is_none());
|
assert!(m("ROOT/parent_dir/dir_deep_32", true).is_none());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_32/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_32/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_32/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_32/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_32/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_32/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 33
|
// 33
|
||||||
// dir itself doesn't match
|
// dir itself doesn't match
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_33", true).is_none());
|
assert!(m("ROOT/parent_dir/dir_deep_33", true).is_none());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_33/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_33/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_33/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_33/child_dir", true).is_ignore());
|
||||||
assert!(
|
assert!(m("ROOT/parent_dir/dir_deep_33/child_dir/file", false).is_ignore());
|
||||||
m("ROOT/parent_dir/dir_deep_33/child_dir/file", false).is_ignore()
|
|
||||||
);
|
|
||||||
}
|
}
|
@@ -1,13 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "grep-matcher"
|
name = "grep-matcher"
|
||||||
version = "0.1.3" #:version
|
version = "0.1.4" #:version
|
||||||
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
A trait for regular expressions, with a focus on line oriented search.
|
A trait for regular expressions, with a focus on line oriented search.
|
||||||
"""
|
"""
|
||||||
documentation = "https://docs.rs/grep-matcher"
|
documentation = "https://docs.rs/grep-matcher"
|
||||||
homepage = "https://github.com/BurntSushi/ripgrep"
|
homepage = "https://github.com/BurntSushi/ripgrep/tree/master/crates/matcher"
|
||||||
repository = "https://github.com/BurntSushi/ripgrep"
|
repository = "https://github.com/BurntSushi/ripgrep/tree/master/crates/matcher"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["regex", "pattern", "trait"]
|
keywords = ["regex", "pattern", "trait"]
|
||||||
license = "Unlicense/MIT"
|
license = "Unlicense/MIT"
|
@@ -19,7 +19,7 @@ pub fn interpolate<A, N>(
|
|||||||
dst: &mut Vec<u8>,
|
dst: &mut Vec<u8>,
|
||||||
) where
|
) where
|
||||||
A: FnMut(usize, &mut Vec<u8>),
|
A: FnMut(usize, &mut Vec<u8>),
|
||||||
N: FnMut(&str) -> Option<usize>
|
N: FnMut(&str) -> Option<usize>,
|
||||||
{
|
{
|
||||||
while !replacement.is_empty() {
|
while !replacement.is_empty() {
|
||||||
match memchr(b'$', replacement) {
|
match memchr(b'$', replacement) {
|
||||||
@@ -134,14 +134,14 @@ fn find_cap_ref(replacement: &[u8]) -> Option<CaptureRef> {
|
|||||||
/// Returns true if and only if the given byte is allowed in a capture name.
|
/// Returns true if and only if the given byte is allowed in a capture name.
|
||||||
fn is_valid_cap_letter(b: &u8) -> bool {
|
fn is_valid_cap_letter(b: &u8) -> bool {
|
||||||
match *b {
|
match *b {
|
||||||
b'0' ..= b'9' | b'a' ..= b'z' | b'A' ..= b'Z' | b'_' => true,
|
b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b'_' => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{CaptureRef, find_cap_ref, interpolate};
|
use super::{find_cap_ref, interpolate, CaptureRef};
|
||||||
|
|
||||||
macro_rules! find {
|
macro_rules! find {
|
||||||
($name:ident, $text:expr) => {
|
($name:ident, $text:expr) => {
|
||||||
@@ -211,7 +211,7 @@ mod tests {
|
|||||||
fn $name() {
|
fn $name() {
|
||||||
assert_eq!($expected, interpolate_string($map, $caps, $hay));
|
assert_eq!($expected, interpolate_string($map, $caps, $hay));
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interp!(
|
interp!(
|
@@ -278,7 +278,7 @@ impl LineTerminator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LineTerminator {
|
impl Default for LineTerminator {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> LineTerminator {
|
fn default() -> LineTerminator {
|
||||||
LineTerminator::byte(b'\n')
|
LineTerminator::byte(b'\n')
|
||||||
@@ -439,7 +439,8 @@ pub trait Captures {
|
|||||||
haystack: &[u8],
|
haystack: &[u8],
|
||||||
replacement: &[u8],
|
replacement: &[u8],
|
||||||
dst: &mut Vec<u8>,
|
dst: &mut Vec<u8>,
|
||||||
) where F: FnMut(&str) -> Option<usize>
|
) where
|
||||||
|
F: FnMut(&str) -> Option<usize>,
|
||||||
{
|
{
|
||||||
interpolate(
|
interpolate(
|
||||||
replacement,
|
replacement,
|
||||||
@@ -463,12 +464,18 @@ pub struct NoCaptures(());
|
|||||||
|
|
||||||
impl NoCaptures {
|
impl NoCaptures {
|
||||||
/// Create an empty set of capturing groups.
|
/// Create an empty set of capturing groups.
|
||||||
pub fn new() -> NoCaptures { NoCaptures(()) }
|
pub fn new() -> NoCaptures {
|
||||||
|
NoCaptures(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Captures for NoCaptures {
|
impl Captures for NoCaptures {
|
||||||
fn len(&self) -> usize { 0 }
|
fn len(&self) -> usize {
|
||||||
fn get(&self, _: usize) -> Option<Match> { None }
|
0
|
||||||
|
}
|
||||||
|
fn get(&self, _: usize) -> Option<Match> {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NoError provides an error type for matchers that never produce errors.
|
/// NoError provides an error type for matchers that never produce errors.
|
||||||
@@ -481,7 +488,9 @@ impl Captures for NoCaptures {
|
|||||||
pub struct NoError(());
|
pub struct NoError(());
|
||||||
|
|
||||||
impl ::std::error::Error for NoError {
|
impl ::std::error::Error for NoError {
|
||||||
fn description(&self) -> &str { "no error" }
|
fn description(&self) -> &str {
|
||||||
|
"no error"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for NoError {
|
impl fmt::Display for NoError {
|
||||||
@@ -599,10 +608,7 @@ pub trait Matcher {
|
|||||||
///
|
///
|
||||||
/// The text encoding of `haystack` is not strictly specified. Matchers are
|
/// The text encoding of `haystack` is not strictly specified. Matchers are
|
||||||
/// advised to assume UTF-8, or at worst, some ASCII compatible encoding.
|
/// advised to assume UTF-8, or at worst, some ASCII compatible encoding.
|
||||||
fn find(
|
fn find(&self, haystack: &[u8]) -> Result<Option<Match>, Self::Error> {
|
||||||
&self,
|
|
||||||
haystack: &[u8],
|
|
||||||
) -> Result<Option<Match>, Self::Error> {
|
|
||||||
self.find_at(haystack, 0)
|
self.find_at(haystack, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,7 +620,8 @@ pub trait Matcher {
|
|||||||
haystack: &[u8],
|
haystack: &[u8],
|
||||||
mut matched: F,
|
mut matched: F,
|
||||||
) -> Result<(), Self::Error>
|
) -> Result<(), Self::Error>
|
||||||
where F: FnMut(Match) -> bool
|
where
|
||||||
|
F: FnMut(Match) -> bool,
|
||||||
{
|
{
|
||||||
self.try_find_iter(haystack, |m| Ok(matched(m)))
|
self.try_find_iter(haystack, |m| Ok(matched(m)))
|
||||||
.map(|r: Result<(), ()>| r.unwrap())
|
.map(|r: Result<(), ()>| r.unwrap())
|
||||||
@@ -632,7 +639,8 @@ pub trait Matcher {
|
|||||||
haystack: &[u8],
|
haystack: &[u8],
|
||||||
mut matched: F,
|
mut matched: F,
|
||||||
) -> Result<Result<(), E>, Self::Error>
|
) -> Result<Result<(), E>, Self::Error>
|
||||||
where F: FnMut(Match) -> Result<bool, E>
|
where
|
||||||
|
F: FnMut(Match) -> Result<bool, E>,
|
||||||
{
|
{
|
||||||
let mut last_end = 0;
|
let mut last_end = 0;
|
||||||
let mut last_match = None;
|
let mut last_match = None;
|
||||||
@@ -690,7 +698,8 @@ pub trait Matcher {
|
|||||||
caps: &mut Self::Captures,
|
caps: &mut Self::Captures,
|
||||||
mut matched: F,
|
mut matched: F,
|
||||||
) -> Result<(), Self::Error>
|
) -> Result<(), Self::Error>
|
||||||
where F: FnMut(&Self::Captures) -> bool
|
where
|
||||||
|
F: FnMut(&Self::Captures) -> bool,
|
||||||
{
|
{
|
||||||
self.try_captures_iter(haystack, caps, |caps| Ok(matched(caps)))
|
self.try_captures_iter(haystack, caps, |caps| Ok(matched(caps)))
|
||||||
.map(|r: Result<(), ()>| r.unwrap())
|
.map(|r: Result<(), ()>| r.unwrap())
|
||||||
@@ -709,7 +718,8 @@ pub trait Matcher {
|
|||||||
caps: &mut Self::Captures,
|
caps: &mut Self::Captures,
|
||||||
mut matched: F,
|
mut matched: F,
|
||||||
) -> Result<Result<(), E>, Self::Error>
|
) -> Result<Result<(), E>, Self::Error>
|
||||||
where F: FnMut(&Self::Captures) -> Result<bool, E>
|
where
|
||||||
|
F: FnMut(&Self::Captures) -> Result<bool, E>,
|
||||||
{
|
{
|
||||||
let mut last_end = 0;
|
let mut last_end = 0;
|
||||||
let mut last_match = None;
|
let mut last_match = None;
|
||||||
@@ -787,7 +797,8 @@ pub trait Matcher {
|
|||||||
dst: &mut Vec<u8>,
|
dst: &mut Vec<u8>,
|
||||||
mut append: F,
|
mut append: F,
|
||||||
) -> Result<(), Self::Error>
|
) -> Result<(), Self::Error>
|
||||||
where F: FnMut(Match, &mut Vec<u8>) -> bool
|
where
|
||||||
|
F: FnMut(Match, &mut Vec<u8>) -> bool,
|
||||||
{
|
{
|
||||||
let mut last_match = 0;
|
let mut last_match = 0;
|
||||||
self.find_iter(haystack, |m| {
|
self.find_iter(haystack, |m| {
|
||||||
@@ -810,7 +821,8 @@ pub trait Matcher {
|
|||||||
dst: &mut Vec<u8>,
|
dst: &mut Vec<u8>,
|
||||||
mut append: F,
|
mut append: F,
|
||||||
) -> Result<(), Self::Error>
|
) -> Result<(), Self::Error>
|
||||||
where F: FnMut(&Self::Captures, &mut Vec<u8>) -> bool
|
where
|
||||||
|
F: FnMut(&Self::Captures, &mut Vec<u8>) -> bool,
|
||||||
{
|
{
|
||||||
let mut last_match = 0;
|
let mut last_match = 0;
|
||||||
self.captures_iter(haystack, caps, |caps| {
|
self.captures_iter(haystack, caps, |caps| {
|
||||||
@@ -1012,10 +1024,7 @@ impl<'a, M: Matcher> Matcher for &'a M {
|
|||||||
(*self).capture_count()
|
(*self).capture_count()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find(
|
fn find(&self, haystack: &[u8]) -> Result<Option<Match>, Self::Error> {
|
||||||
&self,
|
|
||||||
haystack: &[u8]
|
|
||||||
) -> Result<Option<Match>, Self::Error> {
|
|
||||||
(*self).find(haystack)
|
(*self).find(haystack)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1024,7 +1033,8 @@ impl<'a, M: Matcher> Matcher for &'a M {
|
|||||||
haystack: &[u8],
|
haystack: &[u8],
|
||||||
matched: F,
|
matched: F,
|
||||||
) -> Result<(), Self::Error>
|
) -> Result<(), Self::Error>
|
||||||
where F: FnMut(Match) -> bool
|
where
|
||||||
|
F: FnMut(Match) -> bool,
|
||||||
{
|
{
|
||||||
(*self).find_iter(haystack, matched)
|
(*self).find_iter(haystack, matched)
|
||||||
}
|
}
|
||||||
@@ -1034,7 +1044,8 @@ impl<'a, M: Matcher> Matcher for &'a M {
|
|||||||
haystack: &[u8],
|
haystack: &[u8],
|
||||||
matched: F,
|
matched: F,
|
||||||
) -> Result<Result<(), E>, Self::Error>
|
) -> Result<Result<(), E>, Self::Error>
|
||||||
where F: FnMut(Match) -> Result<bool, E>
|
where
|
||||||
|
F: FnMut(Match) -> Result<bool, E>,
|
||||||
{
|
{
|
||||||
(*self).try_find_iter(haystack, matched)
|
(*self).try_find_iter(haystack, matched)
|
||||||
}
|
}
|
||||||
@@ -1053,7 +1064,8 @@ impl<'a, M: Matcher> Matcher for &'a M {
|
|||||||
caps: &mut Self::Captures,
|
caps: &mut Self::Captures,
|
||||||
matched: F,
|
matched: F,
|
||||||
) -> Result<(), Self::Error>
|
) -> Result<(), Self::Error>
|
||||||
where F: FnMut(&Self::Captures) -> bool
|
where
|
||||||
|
F: FnMut(&Self::Captures) -> bool,
|
||||||
{
|
{
|
||||||
(*self).captures_iter(haystack, caps, matched)
|
(*self).captures_iter(haystack, caps, matched)
|
||||||
}
|
}
|
||||||
@@ -1064,7 +1076,8 @@ impl<'a, M: Matcher> Matcher for &'a M {
|
|||||||
caps: &mut Self::Captures,
|
caps: &mut Self::Captures,
|
||||||
matched: F,
|
matched: F,
|
||||||
) -> Result<Result<(), E>, Self::Error>
|
) -> Result<Result<(), E>, Self::Error>
|
||||||
where F: FnMut(&Self::Captures) -> Result<bool, E>
|
where
|
||||||
|
F: FnMut(&Self::Captures) -> Result<bool, E>,
|
||||||
{
|
{
|
||||||
(*self).try_captures_iter(haystack, caps, matched)
|
(*self).try_captures_iter(haystack, caps, matched)
|
||||||
}
|
}
|
||||||
@@ -1075,7 +1088,8 @@ impl<'a, M: Matcher> Matcher for &'a M {
|
|||||||
dst: &mut Vec<u8>,
|
dst: &mut Vec<u8>,
|
||||||
append: F,
|
append: F,
|
||||||
) -> Result<(), Self::Error>
|
) -> Result<(), Self::Error>
|
||||||
where F: FnMut(Match, &mut Vec<u8>) -> bool
|
where
|
||||||
|
F: FnMut(Match, &mut Vec<u8>) -> bool,
|
||||||
{
|
{
|
||||||
(*self).replace(haystack, dst, append)
|
(*self).replace(haystack, dst, append)
|
||||||
}
|
}
|
||||||
@@ -1087,7 +1101,8 @@ impl<'a, M: Matcher> Matcher for &'a M {
|
|||||||
dst: &mut Vec<u8>,
|
dst: &mut Vec<u8>,
|
||||||
append: F,
|
append: F,
|
||||||
) -> Result<(), Self::Error>
|
) -> Result<(), Self::Error>
|
||||||
where F: FnMut(&Self::Captures, &mut Vec<u8>) -> bool
|
where
|
||||||
|
F: FnMut(&Self::Captures, &mut Vec<u8>) -> bool,
|
||||||
{
|
{
|
||||||
(*self).replace_with_captures(haystack, caps, dst, append)
|
(*self).replace_with_captures(haystack, caps, dst, append)
|
||||||
}
|
}
|
||||||
@@ -1099,7 +1114,7 @@ impl<'a, M: Matcher> Matcher for &'a M {
|
|||||||
fn is_match_at(
|
fn is_match_at(
|
||||||
&self,
|
&self,
|
||||||
haystack: &[u8],
|
haystack: &[u8],
|
||||||
at: usize
|
at: usize,
|
||||||
) -> Result<bool, Self::Error> {
|
) -> Result<bool, Self::Error> {
|
||||||
(*self).is_match_at(haystack, at)
|
(*self).is_match_at(haystack, at)
|
||||||
}
|
}
|
@@ -25,18 +25,22 @@ fn find() {
|
|||||||
fn find_iter() {
|
fn find_iter() {
|
||||||
let matcher = matcher(r"(\w+)\s+(\w+)");
|
let matcher = matcher(r"(\w+)\s+(\w+)");
|
||||||
let mut matches = vec![];
|
let mut matches = vec![];
|
||||||
matcher.find_iter(b"aa bb cc dd", |m| {
|
matcher
|
||||||
matches.push(m);
|
.find_iter(b"aa bb cc dd", |m| {
|
||||||
true
|
matches.push(m);
|
||||||
}).unwrap();
|
true
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
assert_eq!(matches, vec![m(0, 5), m(6, 11)]);
|
assert_eq!(matches, vec![m(0, 5), m(6, 11)]);
|
||||||
|
|
||||||
// Test that find_iter respects short circuiting.
|
// Test that find_iter respects short circuiting.
|
||||||
matches.clear();
|
matches.clear();
|
||||||
matcher.find_iter(b"aa bb cc dd", |m| {
|
matcher
|
||||||
matches.push(m);
|
.find_iter(b"aa bb cc dd", |m| {
|
||||||
false
|
matches.push(m);
|
||||||
}).unwrap();
|
false
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
assert_eq!(matches, vec![m(0, 5)]);
|
assert_eq!(matches, vec![m(0, 5)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,14 +51,17 @@ fn try_find_iter() {
|
|||||||
|
|
||||||
let matcher = matcher(r"(\w+)\s+(\w+)");
|
let matcher = matcher(r"(\w+)\s+(\w+)");
|
||||||
let mut matches = vec![];
|
let mut matches = vec![];
|
||||||
let err = matcher.try_find_iter(b"aa bb cc dd", |m| {
|
let err = matcher
|
||||||
if matches.is_empty() {
|
.try_find_iter(b"aa bb cc dd", |m| {
|
||||||
matches.push(m);
|
if matches.is_empty() {
|
||||||
Ok(true)
|
matches.push(m);
|
||||||
} else {
|
Ok(true)
|
||||||
Err(MyError)
|
} else {
|
||||||
}
|
Err(MyError)
|
||||||
}).unwrap().unwrap_err();
|
}
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_err();
|
||||||
assert_eq!(matches, vec![m(0, 5)]);
|
assert_eq!(matches, vec![m(0, 5)]);
|
||||||
assert_eq!(err, MyError);
|
assert_eq!(err, MyError);
|
||||||
}
|
}
|
||||||
@@ -89,28 +96,30 @@ fn captures_iter() {
|
|||||||
let matcher = matcher(r"(?P<a>\w+)\s+(?P<b>\w+)");
|
let matcher = matcher(r"(?P<a>\w+)\s+(?P<b>\w+)");
|
||||||
let mut caps = matcher.new_captures().unwrap();
|
let mut caps = matcher.new_captures().unwrap();
|
||||||
let mut matches = vec![];
|
let mut matches = vec![];
|
||||||
matcher.captures_iter(b"aa bb cc dd", &mut caps, |caps| {
|
matcher
|
||||||
matches.push(caps.get(0).unwrap());
|
.captures_iter(b"aa bb cc dd", &mut caps, |caps| {
|
||||||
matches.push(caps.get(1).unwrap());
|
matches.push(caps.get(0).unwrap());
|
||||||
matches.push(caps.get(2).unwrap());
|
matches.push(caps.get(1).unwrap());
|
||||||
true
|
matches.push(caps.get(2).unwrap());
|
||||||
}).unwrap();
|
true
|
||||||
assert_eq!(matches, vec![
|
})
|
||||||
m(0, 5), m(0, 2), m(3, 5),
|
.unwrap();
|
||||||
m(6, 11), m(6, 8), m(9, 11),
|
assert_eq!(
|
||||||
]);
|
matches,
|
||||||
|
vec![m(0, 5), m(0, 2), m(3, 5), m(6, 11), m(6, 8), m(9, 11),]
|
||||||
|
);
|
||||||
|
|
||||||
// Test that captures_iter respects short circuiting.
|
// Test that captures_iter respects short circuiting.
|
||||||
matches.clear();
|
matches.clear();
|
||||||
matcher.captures_iter(b"aa bb cc dd", &mut caps, |caps| {
|
matcher
|
||||||
matches.push(caps.get(0).unwrap());
|
.captures_iter(b"aa bb cc dd", &mut caps, |caps| {
|
||||||
matches.push(caps.get(1).unwrap());
|
matches.push(caps.get(0).unwrap());
|
||||||
matches.push(caps.get(2).unwrap());
|
matches.push(caps.get(1).unwrap());
|
||||||
false
|
matches.push(caps.get(2).unwrap());
|
||||||
}).unwrap();
|
false
|
||||||
assert_eq!(matches, vec![
|
})
|
||||||
m(0, 5), m(0, 2), m(3, 5),
|
.unwrap();
|
||||||
]);
|
assert_eq!(matches, vec![m(0, 5), m(0, 2), m(3, 5),]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -121,16 +130,19 @@ fn try_captures_iter() {
|
|||||||
let matcher = matcher(r"(?P<a>\w+)\s+(?P<b>\w+)");
|
let matcher = matcher(r"(?P<a>\w+)\s+(?P<b>\w+)");
|
||||||
let mut caps = matcher.new_captures().unwrap();
|
let mut caps = matcher.new_captures().unwrap();
|
||||||
let mut matches = vec![];
|
let mut matches = vec![];
|
||||||
let err = matcher.try_captures_iter(b"aa bb cc dd", &mut caps, |caps| {
|
let err = matcher
|
||||||
if matches.is_empty() {
|
.try_captures_iter(b"aa bb cc dd", &mut caps, |caps| {
|
||||||
matches.push(caps.get(0).unwrap());
|
if matches.is_empty() {
|
||||||
matches.push(caps.get(1).unwrap());
|
matches.push(caps.get(0).unwrap());
|
||||||
matches.push(caps.get(2).unwrap());
|
matches.push(caps.get(1).unwrap());
|
||||||
Ok(true)
|
matches.push(caps.get(2).unwrap());
|
||||||
} else {
|
Ok(true)
|
||||||
Err(MyError)
|
} else {
|
||||||
}
|
Err(MyError)
|
||||||
}).unwrap().unwrap_err();
|
}
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_err();
|
||||||
assert_eq!(matches, vec![m(0, 5), m(0, 2), m(3, 5)]);
|
assert_eq!(matches, vec![m(0, 5), m(0, 2), m(3, 5)]);
|
||||||
assert_eq!(err, MyError);
|
assert_eq!(err, MyError);
|
||||||
}
|
}
|
||||||
@@ -150,10 +162,12 @@ fn no_captures() {
|
|||||||
assert!(!matcher.captures(b"homer simpson", &mut caps).unwrap());
|
assert!(!matcher.captures(b"homer simpson", &mut caps).unwrap());
|
||||||
|
|
||||||
let mut called = false;
|
let mut called = false;
|
||||||
matcher.captures_iter(b"homer simpson", &mut caps, |_| {
|
matcher
|
||||||
called = true;
|
.captures_iter(b"homer simpson", &mut caps, |_| {
|
||||||
true
|
called = true;
|
||||||
}).unwrap();
|
true
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
assert!(!called);
|
assert!(!called);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,18 +175,22 @@ fn no_captures() {
|
|||||||
fn replace() {
|
fn replace() {
|
||||||
let matcher = matcher(r"(\w+)\s+(\w+)");
|
let matcher = matcher(r"(\w+)\s+(\w+)");
|
||||||
let mut dst = vec![];
|
let mut dst = vec![];
|
||||||
matcher.replace(b"aa bb cc dd", &mut dst, |_, dst| {
|
matcher
|
||||||
dst.push(b'z');
|
.replace(b"aa bb cc dd", &mut dst, |_, dst| {
|
||||||
true
|
dst.push(b'z');
|
||||||
}).unwrap();
|
true
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
assert_eq!(dst, b"z z");
|
assert_eq!(dst, b"z z");
|
||||||
|
|
||||||
// Test that replacements respect short circuiting.
|
// Test that replacements respect short circuiting.
|
||||||
dst.clear();
|
dst.clear();
|
||||||
matcher.replace(b"aa bb cc dd", &mut dst, |_, dst| {
|
matcher
|
||||||
dst.push(b'z');
|
.replace(b"aa bb cc dd", &mut dst, |_, dst| {
|
||||||
false
|
dst.push(b'z');
|
||||||
}).unwrap();
|
false
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
assert_eq!(dst, b"z cc dd");
|
assert_eq!(dst, b"z cc dd");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,27 +200,31 @@ fn replace_with_captures() {
|
|||||||
let haystack = b"aa bb cc dd";
|
let haystack = b"aa bb cc dd";
|
||||||
let mut caps = matcher.new_captures().unwrap();
|
let mut caps = matcher.new_captures().unwrap();
|
||||||
let mut dst = vec![];
|
let mut dst = vec![];
|
||||||
matcher.replace_with_captures(haystack, &mut caps, &mut dst, |caps, dst| {
|
matcher
|
||||||
caps.interpolate(
|
.replace_with_captures(haystack, &mut caps, &mut dst, |caps, dst| {
|
||||||
|name| matcher.capture_index(name),
|
caps.interpolate(
|
||||||
haystack,
|
|name| matcher.capture_index(name),
|
||||||
b"$2 $1",
|
haystack,
|
||||||
dst,
|
b"$2 $1",
|
||||||
);
|
dst,
|
||||||
true
|
);
|
||||||
}).unwrap();
|
true
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
assert_eq!(dst, b"bb aa dd cc");
|
assert_eq!(dst, b"bb aa dd cc");
|
||||||
|
|
||||||
// Test that replacements respect short circuiting.
|
// Test that replacements respect short circuiting.
|
||||||
dst.clear();
|
dst.clear();
|
||||||
matcher.replace_with_captures(haystack, &mut caps, &mut dst, |caps, dst| {
|
matcher
|
||||||
caps.interpolate(
|
.replace_with_captures(haystack, &mut caps, &mut dst, |caps, dst| {
|
||||||
|name| matcher.capture_index(name),
|
caps.interpolate(
|
||||||
haystack,
|
|name| matcher.capture_index(name),
|
||||||
b"$2 $1",
|
haystack,
|
||||||
dst,
|
b"$2 $1",
|
||||||
);
|
dst,
|
||||||
false
|
);
|
||||||
}).unwrap();
|
false
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
assert_eq!(dst, b"bb aa cc dd");
|
assert_eq!(dst, b"bb aa cc dd");
|
||||||
}
|
}
|
@@ -18,10 +18,7 @@ impl RegexMatcher {
|
|||||||
names.insert(name.to_string(), i);
|
names.insert(name.to_string(), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RegexMatcher {
|
RegexMatcher { re: re, names: names }
|
||||||
re: re,
|
|
||||||
names: names,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,12 +28,9 @@ impl Matcher for RegexMatcher {
|
|||||||
type Captures = RegexCaptures;
|
type Captures = RegexCaptures;
|
||||||
type Error = NoError;
|
type Error = NoError;
|
||||||
|
|
||||||
fn find_at(
|
fn find_at(&self, haystack: &[u8], at: usize) -> Result<Option<Match>> {
|
||||||
&self,
|
Ok(self
|
||||||
haystack: &[u8],
|
.re
|
||||||
at: usize,
|
|
||||||
) -> Result<Option<Match>> {
|
|
||||||
Ok(self.re
|
|
||||||
.find_at(haystack, at)
|
.find_at(haystack, at)
|
||||||
.map(|m| Match::new(m.start(), m.end())))
|
.map(|m| Match::new(m.start(), m.end())))
|
||||||
}
|
}
|
||||||
@@ -75,12 +69,9 @@ impl Matcher for RegexMatcherNoCaps {
|
|||||||
type Captures = NoCaptures;
|
type Captures = NoCaptures;
|
||||||
type Error = NoError;
|
type Error = NoError;
|
||||||
|
|
||||||
fn find_at(
|
fn find_at(&self, haystack: &[u8], at: usize) -> Result<Option<Match>> {
|
||||||
&self,
|
Ok(self
|
||||||
haystack: &[u8],
|
.0
|
||||||
at: usize,
|
|
||||||
) -> Result<Option<Match>> {
|
|
||||||
Ok(self.0
|
|
||||||
.find_at(haystack, at)
|
.find_at(haystack, at)
|
||||||
.map(|m| Match::new(m.start(), m.end())))
|
.map(|m| Match::new(m.start(), m.end())))
|
||||||
}
|
}
|
@@ -1,17 +1,17 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "grep-pcre2"
|
name = "grep-pcre2"
|
||||||
version = "0.1.3" #:version
|
version = "0.1.4" #:version
|
||||||
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
Use PCRE2 with the 'grep' crate.
|
Use PCRE2 with the 'grep' crate.
|
||||||
"""
|
"""
|
||||||
documentation = "https://docs.rs/grep-pcre2"
|
documentation = "https://docs.rs/grep-pcre2"
|
||||||
homepage = "https://github.com/BurntSushi/ripgrep"
|
homepage = "https://github.com/BurntSushi/ripgrep/tree/master/crates/pcre2"
|
||||||
repository = "https://github.com/BurntSushi/ripgrep"
|
repository = "https://github.com/BurntSushi/ripgrep/tree/master/crates/pcre2"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["regex", "grep", "pcre", "backreference", "look"]
|
keywords = ["regex", "grep", "pcre", "backreference", "look"]
|
||||||
license = "Unlicense/MIT"
|
license = "Unlicense/MIT"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
grep-matcher = { version = "0.1.2", path = "../grep-matcher" }
|
grep-matcher = { version = "0.1.2", path = "../matcher" }
|
||||||
pcre2 = "0.2.0"
|
pcre2 = "0.2.0"
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user