mirror of
https://github.com/uutils/grep.git
synced 2026-06-10 16:15:11 -07:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96762f26ca | ||
|
|
c8dfef6563 | ||
|
|
ddac723054 | ||
|
|
079619ee44 |
@@ -1,50 +0,0 @@
|
|||||||
name: Benchmarks
|
|
||||||
|
|
||||||
# spell-checker:ignore codspeed dtolnay Swatinem sccache
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main, master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main, master ]
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read # to fetch code (actions/checkout)
|
|
||||||
|
|
||||||
# End the current execution if there is a new changeset in the PR.
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
benchmarks:
|
|
||||||
name: Run benchmarks (CodSpeed)
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: Install Rust
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
|
|
||||||
- name: Run sccache-cache
|
|
||||||
uses: mozilla-actions/sccache-action@v0.0.10
|
|
||||||
|
|
||||||
- name: Install cargo-codspeed
|
|
||||||
uses: taiki-e/install-action@v2
|
|
||||||
with:
|
|
||||||
tool: cargo-codspeed
|
|
||||||
|
|
||||||
- name: Build benchmarks
|
|
||||||
run: cargo codspeed build -p uu_grep
|
|
||||||
|
|
||||||
- name: Run benchmarks
|
|
||||||
uses: CodSpeedHQ/action@v4
|
|
||||||
env:
|
|
||||||
CODSPEED_LOG: debug
|
|
||||||
with:
|
|
||||||
mode: simulation
|
|
||||||
run: cargo codspeed run -p uu_grep > /dev/null
|
|
||||||
token: ${{ secrets.CODSPEED_TOKEN }}
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
name: CodSpeed
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "main"
|
||||||
|
pull_request:
|
||||||
|
# `workflow_dispatch` allows CodSpeed to trigger backtest
|
||||||
|
# performance analysis in order to generate initial data.
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
codspeed:
|
||||||
|
name: Run benchmarks
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Rust toolchain, cache and cargo-codspeed binary
|
||||||
|
uses: moonrepo/setup-rust@v0
|
||||||
|
with:
|
||||||
|
channel: stable
|
||||||
|
cache-target: release
|
||||||
|
bins: cargo-codspeed
|
||||||
|
|
||||||
|
- name: Build the benchmark target(s)
|
||||||
|
run: cargo codspeed build
|
||||||
|
|
||||||
|
- name: Run the benchmarks
|
||||||
|
uses: CodSpeedHQ/action@v4
|
||||||
|
with:
|
||||||
|
mode: simulation
|
||||||
|
run: cargo codspeed run
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
# See https://pre-commit.com for more information
|
||||||
|
# See https://pre-commit.com/hooks.html for more hooks
|
||||||
|
exclude: ^tests/fixtures/
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v6.0.0
|
||||||
|
hooks:
|
||||||
|
- id: check-added-large-files
|
||||||
|
- id: check-executables-have-shebangs
|
||||||
|
- id: check-json
|
||||||
|
exclude: '\.vscode/(cSpell|extensions)\.json' # cSpell.json and extensions.json use comments
|
||||||
|
- id: check-shebang-scripts-are-executable
|
||||||
|
exclude: '.+\.rs' # would be triggered by #![some_attribute]
|
||||||
|
- id: check-symlinks
|
||||||
|
- id: check-toml
|
||||||
|
- id: check-yaml
|
||||||
|
args: [ --allow-multiple-documents ]
|
||||||
|
- id: destroyed-symlinks
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: mixed-line-ending
|
||||||
|
args: [ --fix=lf ]
|
||||||
|
- id: trailing-whitespace
|
||||||
|
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: rust-linting
|
||||||
|
name: Rust linting
|
||||||
|
description: Run cargo fmt on files included in the commit.
|
||||||
|
entry: cargo +stable fmt --
|
||||||
|
pass_filenames: true
|
||||||
|
types: [file, rust]
|
||||||
|
language: system
|
||||||
|
- id: rust-clippy
|
||||||
|
name: Rust clippy
|
||||||
|
description: Run cargo clippy on files included in the commit.
|
||||||
|
entry: cargo +stable clippy --workspace --all-targets --all-features -- -D warnings
|
||||||
|
pass_filenames: false
|
||||||
|
types: [file, rust]
|
||||||
|
language: system
|
||||||
|
- id: cargo-lock-check
|
||||||
|
name: Cargo.lock sync check
|
||||||
|
description: Ensure Cargo.lock and fuzz/Cargo.lock are up-to-date.
|
||||||
|
entry: bash -c 'for dir in . fuzz; do if [ -d "$dir" ]; then ( cd "$dir" && cargo fetch --quiet ); fi; done'
|
||||||
|
pass_filenames: false
|
||||||
|
files: 'Cargo\.(toml|lock)$'
|
||||||
|
language: system
|
||||||
|
- id: cspell
|
||||||
|
name: Code spell checker (cspell)
|
||||||
|
description: Run cspell to check for spelling errors (if available).
|
||||||
|
entry: bash -c 'if command -v cspell >/dev/null 2>&1; then cspell --no-must-find-files -- "$@"; else echo "cspell not found, skipping spell check"; exit 0; fi' --
|
||||||
|
pass_filenames: true
|
||||||
|
language: system
|
||||||
|
|
||||||
|
ci:
|
||||||
|
skip: [rust-linting, rust-clippy, cargo-lock-check, cspell]
|
||||||
Generated
+328
-98
File diff suppressed because it is too large
Load Diff
+4
-6
@@ -27,12 +27,10 @@ onig_sys = { version = "*", default-features = false }
|
|||||||
uucore = "0.8.0"
|
uucore = "0.8.0"
|
||||||
walkdir = "2.5"
|
walkdir = "2.5"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
divan = { package = "codspeed-divan-compat", version = "4.0.5" }
|
|
||||||
tempfile = "3.10.1"
|
|
||||||
uucore = { version = "0.8.0", features = ["benchmark"] }
|
|
||||||
uutests = "0.8.0"
|
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "grep_bench"
|
name = "grep_bench"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
criterion = { version = "4.7.0", package = "codspeed-criterion-compat" }
|
||||||
|
uutests = "0.8.0"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
[](https://deps.rs/repo/github/uutils/grep)
|
[](https://deps.rs/repo/github/uutils/grep)
|
||||||
|
|
||||||
[](https://codecov.io/gh/uutils/grep)
|
[](https://codecov.io/gh/uutils/grep)
|
||||||
|
[](https://codspeed.io/uutils/grep?utm_source=badge)
|
||||||
|
|
||||||
# Grep, now in Rust
|
# Grep, now in Rust
|
||||||
|
|
||||||
@@ -29,6 +30,10 @@ cargo build --release
|
|||||||
cargo test
|
cargo test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Pre-commit hooks
|
||||||
|
|
||||||
|
This project uses [pre-commit](https://pre-commit.com); run `pre-commit install` to enable the git hooks.
|
||||||
|
|
||||||
## Known Issues
|
## Known Issues
|
||||||
|
|
||||||
* Does not take `LANG`, etc., into account for handling file encodings (non-UTF8 matches are treated as binary)
|
* Does not take `LANG`, etc., into account for handling file encodings (non-UTF8 matches are treated as binary)
|
||||||
|
|||||||
+261
-228
File diff suppressed because it is too large
Load Diff
+79
-56
@@ -3,9 +3,12 @@
|
|||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
mod context_buffer;
|
#[doc(hidden)]
|
||||||
mod line_buffer;
|
pub mod context_buffer;
|
||||||
mod matcher;
|
#[doc(hidden)]
|
||||||
|
pub mod line_buffer;
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub mod matcher;
|
||||||
mod output;
|
mod output;
|
||||||
mod searcher;
|
mod searcher;
|
||||||
|
|
||||||
@@ -20,7 +23,8 @@ use std::path::Path;
|
|||||||
use uucore::error::{FromIo, UResult, USimpleError};
|
use uucore::error::{FromIo, UResult, USimpleError};
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
enum RegexMode {
|
#[doc(hidden)]
|
||||||
|
pub enum RegexMode {
|
||||||
Fixed,
|
Fixed,
|
||||||
Basic,
|
Basic,
|
||||||
Extended,
|
Extended,
|
||||||
@@ -28,7 +32,8 @@ enum RegexMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
enum BinaryMode {
|
#[doc(hidden)]
|
||||||
|
pub enum BinaryMode {
|
||||||
Binary,
|
Binary,
|
||||||
Text,
|
Text,
|
||||||
WithoutMatch,
|
WithoutMatch,
|
||||||
@@ -42,79 +47,84 @@ enum ColorMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
enum DirectoryMode {
|
#[doc(hidden)]
|
||||||
|
pub enum DirectoryMode {
|
||||||
Read,
|
Read,
|
||||||
Skip,
|
Skip,
|
||||||
Recurse,
|
Recurse,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
enum DeviceMode {
|
#[doc(hidden)]
|
||||||
|
pub enum DeviceMode {
|
||||||
Default,
|
Default,
|
||||||
Read,
|
Read,
|
||||||
Skip,
|
Skip,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ColorConfig<'a> {
|
#[doc(hidden)]
|
||||||
matched_selected: &'a str,
|
pub struct ColorConfig<'a> {
|
||||||
matched_context: &'a str,
|
pub matched_selected: &'a str,
|
||||||
filename: &'a str,
|
pub matched_context: &'a str,
|
||||||
line_number: &'a str,
|
pub filename: &'a str,
|
||||||
byte_offset: &'a str,
|
pub line_number: &'a str,
|
||||||
separator: &'a str,
|
pub byte_offset: &'a str,
|
||||||
selected_line: &'a str,
|
pub separator: &'a str,
|
||||||
context_line: &'a str,
|
pub selected_line: &'a str,
|
||||||
|
pub context_line: &'a str,
|
||||||
|
|
||||||
reverse_video: bool,
|
pub reverse_video: bool,
|
||||||
no_erase: bool,
|
pub no_erase: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GlobSet {
|
#[doc(hidden)]
|
||||||
|
pub struct GlobSet {
|
||||||
patterns: Vec<glob::Pattern>,
|
patterns: Vec<glob::Pattern>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Config<'a> {
|
#[doc(hidden)]
|
||||||
|
pub struct Config<'a> {
|
||||||
// Searcher
|
// Searcher
|
||||||
directory_mode: DirectoryMode,
|
pub directory_mode: DirectoryMode,
|
||||||
device_mode: DeviceMode,
|
pub device_mode: DeviceMode,
|
||||||
follow_symlinks: bool,
|
pub follow_symlinks: bool,
|
||||||
include_globs: GlobSet,
|
pub include_globs: GlobSet,
|
||||||
exclude_globs: GlobSet,
|
pub exclude_globs: GlobSet,
|
||||||
exclude_dir_globs: GlobSet,
|
pub exclude_dir_globs: GlobSet,
|
||||||
label: &'a str,
|
pub label: &'a str,
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
strip_cr: bool,
|
pub strip_cr: bool,
|
||||||
binary_mode: BinaryMode,
|
pub binary_mode: BinaryMode,
|
||||||
max_count: Option<u64>,
|
pub max_count: Option<u64>,
|
||||||
before_context: usize,
|
pub before_context: usize,
|
||||||
after_context: usize,
|
pub after_context: usize,
|
||||||
has_context: bool,
|
pub has_context: bool,
|
||||||
|
|
||||||
// Matcher
|
// Matcher
|
||||||
patterns: &'a [&'a str],
|
pub patterns: &'a [&'a str],
|
||||||
regex_mode: RegexMode,
|
pub regex_mode: RegexMode,
|
||||||
ignore_case: bool,
|
pub ignore_case: bool,
|
||||||
invert_match: bool,
|
pub invert_match: bool,
|
||||||
word_regexp: bool,
|
pub word_regexp: bool,
|
||||||
line_regexp: bool,
|
pub line_regexp: bool,
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
quiet: bool,
|
pub quiet: bool,
|
||||||
count: bool,
|
pub count: bool,
|
||||||
show_filename: bool,
|
pub show_filename: bool,
|
||||||
files_with_matches: bool,
|
pub files_with_matches: bool,
|
||||||
files_without_match: bool,
|
pub files_without_match: bool,
|
||||||
only_matching: bool,
|
pub only_matching: bool,
|
||||||
byte_offset: bool,
|
pub byte_offset: bool,
|
||||||
line_number: bool,
|
pub line_number: bool,
|
||||||
initial_tab: bool,
|
pub initial_tab: bool,
|
||||||
null_separator: bool,
|
pub null_separator: bool,
|
||||||
null_data: bool,
|
pub null_data: bool,
|
||||||
line_buffered: bool,
|
pub line_buffered: bool,
|
||||||
no_messages: bool,
|
pub no_messages: bool,
|
||||||
group_separator: Option<&'a str>,
|
pub group_separator: Option<&'a str>,
|
||||||
use_color: bool,
|
pub use_color: bool,
|
||||||
color_config: ColorConfig<'a>,
|
pub color_config: ColorConfig<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[uucore::main(no_signals)]
|
#[uucore::main(no_signals)]
|
||||||
@@ -854,8 +864,21 @@ fn expand_num_shorthand(args: impl Iterator<Item = OsString>) -> Vec<OsString> {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for GlobSet {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl GlobSet {
|
impl GlobSet {
|
||||||
fn with_capacity(capacity: usize) -> Self {
|
/// Create an empty GlobSet.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
patterns: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_capacity(capacity: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
patterns: Vec::with_capacity(capacity),
|
patterns: Vec::with_capacity(capacity),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user