style: apply rustfmt
Maybe 2024 changes? Note that we now set `edition = "2024"` explicitly in `rustfmt.toml`. Without this, it seems like it's possible in some cases for rustfmt to run under an older edition's style. Not sure how though.
This commit is contained in:
@@ -16,7 +16,7 @@ use std::{ffi::OsString, io};
|
|||||||
pub fn hostname() -> io::Result<OsString> {
|
pub fn hostname() -> io::Result<OsString> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
use winapi_util::sysinfo::{get_computer_name, ComputerNameKind};
|
use winapi_util::sysinfo::{ComputerNameKind, get_computer_name};
|
||||||
get_computer_name(ComputerNameKind::PhysicalDnsHostname)
|
get_computer_name(ComputerNameKind::PhysicalDnsHostname)
|
||||||
}
|
}
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
|||||||
@@ -133,19 +133,19 @@ mod wtr;
|
|||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
decompress::{
|
decompress::{
|
||||||
resolve_binary, DecompressionMatcher, DecompressionMatcherBuilder,
|
DecompressionMatcher, DecompressionMatcherBuilder,
|
||||||
DecompressionReader, DecompressionReaderBuilder,
|
DecompressionReader, DecompressionReaderBuilder, resolve_binary,
|
||||||
},
|
},
|
||||||
escape::{escape, escape_os, unescape, unescape_os},
|
escape::{escape, escape_os, unescape, unescape_os},
|
||||||
hostname::hostname,
|
hostname::hostname,
|
||||||
human::{parse_human_readable_size, ParseSizeError},
|
human::{ParseSizeError, parse_human_readable_size},
|
||||||
pattern::{
|
pattern::{
|
||||||
pattern_from_bytes, pattern_from_os, patterns_from_path,
|
InvalidPatternError, pattern_from_bytes, pattern_from_os,
|
||||||
patterns_from_reader, patterns_from_stdin, InvalidPatternError,
|
patterns_from_path, patterns_from_reader, patterns_from_stdin,
|
||||||
},
|
},
|
||||||
process::{CommandError, CommandReader, CommandReaderBuilder},
|
process::{CommandError, CommandReader, CommandReaderBuilder},
|
||||||
wtr::{
|
wtr::{
|
||||||
stdout, stdout_buffered_block, stdout_buffered_line, StandardStream,
|
StandardStream, stdout, stdout_buffered_block, stdout_buffered_line,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
Provides completions for ripgrep's CLI for the fish shell.
|
Provides completions for ripgrep's CLI for the fish shell.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::flags::{defs::FLAGS, CompletionType};
|
use crate::flags::{CompletionType, defs::FLAGS};
|
||||||
|
|
||||||
const TEMPLATE: &'static str = "complete -c rg !SHORT! -l !LONG! -d '!DOC!'";
|
const TEMPLATE: &'static str = "complete -c rg !SHORT! -l !LONG! -d '!DOC!'";
|
||||||
const TEMPLATE_NEGATED: &'static str =
|
const TEMPLATE_NEGATED: &'static str = "complete -c rg -l !NEGATED! -n '__rg_contains_opt !LONG! !SHORT!' -d '!DOC!'\n";
|
||||||
"complete -c rg -l !NEGATED! -n '__rg_contains_opt !LONG! !SHORT!' -d '!DOC!'\n";
|
|
||||||
|
|
||||||
/// Generate completions for Fish.
|
/// Generate completions for Fish.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ Register-ArgumentCompleter -Native -CommandName 'rg' -ScriptBlock {
|
|||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
|
||||||
const TEMPLATE_FLAG: &'static str =
|
const TEMPLATE_FLAG: &'static str = "[CompletionResult]::new('!DASH_NAME!', '!NAME!', [CompletionResultType]::ParameterName, '!DOC!')";
|
||||||
"[CompletionResult]::new('!DASH_NAME!', '!NAME!', [CompletionResultType]::ParameterName, '!DOC!')";
|
|
||||||
|
|
||||||
/// Generate completions for PowerShell.
|
/// Generate completions for PowerShell.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use bstr::{io::BufReadExt, ByteSlice};
|
use bstr::{ByteSlice, io::BufReadExt};
|
||||||
|
|
||||||
/// Return a sequence of arguments derived from ripgrep rc configuration files.
|
/// Return a sequence of arguments derived from ripgrep rc configuration files.
|
||||||
pub fn args() -> Vec<OsString> {
|
pub fn args() -> Vec<OsString> {
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ use std::{path::PathBuf, sync::LazyLock};
|
|||||||
use {anyhow::Context as AnyhowContext, bstr::ByteVec};
|
use {anyhow::Context as AnyhowContext, bstr::ByteVec};
|
||||||
|
|
||||||
use crate::flags::{
|
use crate::flags::{
|
||||||
|
Category, Flag, FlagValue,
|
||||||
lowargs::{
|
lowargs::{
|
||||||
BinaryMode, BoundaryMode, BufferMode, CaseMode, ColorChoice,
|
BinaryMode, BoundaryMode, BufferMode, CaseMode, ColorChoice,
|
||||||
ContextMode, EncodingMode, EngineChoice, GenerateMode, LoggingMode,
|
ContextMode, EncodingMode, EngineChoice, GenerateMode, LoggingMode,
|
||||||
LowArgs, MmapMode, Mode, PatternSource, SearchMode, SortMode,
|
LowArgs, MmapMode, Mode, PatternSource, SearchMode, SortMode,
|
||||||
SortModeKind, SpecialMode, TypeChange,
|
SortModeKind, SpecialMode, TypeChange,
|
||||||
},
|
},
|
||||||
Category, Flag, FlagValue,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ is used when the `--help` flag is given.
|
|||||||
|
|
||||||
use std::{collections::BTreeMap, fmt::Write};
|
use std::{collections::BTreeMap, fmt::Write};
|
||||||
|
|
||||||
use crate::flags::{defs::FLAGS, doc::version, Category, Flag};
|
use crate::flags::{Category, Flag, defs::FLAGS, doc::version};
|
||||||
|
|
||||||
const TEMPLATE_SHORT: &'static str = include_str!("template.short.help");
|
const TEMPLATE_SHORT: &'static str = include_str!("template.short.help");
|
||||||
const TEMPLATE_LONG: &'static str = include_str!("template.long.help");
|
const TEMPLATE_LONG: &'static str = include_str!("template.long.help");
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Provides routines for generating ripgrep's man page in `roff` format.
|
|||||||
|
|
||||||
use std::{collections::BTreeMap, fmt::Write};
|
use std::{collections::BTreeMap, fmt::Write};
|
||||||
|
|
||||||
use crate::flags::{defs::FLAGS, doc::version, Flag};
|
use crate::flags::{Flag, defs::FLAGS, doc::version};
|
||||||
|
|
||||||
const TEMPLATE: &'static str = include_str!("template.rg.1");
|
const TEMPLATE: &'static str = include_str!("template.rg.1");
|
||||||
|
|
||||||
|
|||||||
@@ -169,9 +169,5 @@ fn features() -> Vec<String> {
|
|||||||
|
|
||||||
/// Returns `+` when `enabled` is `true` and `-` otherwise.
|
/// Returns `+` when `enabled` is `true` and `-` otherwise.
|
||||||
fn sign(enabled: bool) -> &'static str {
|
fn sign(enabled: bool) -> &'static str {
|
||||||
if enabled {
|
if enabled { "+" } else { "-" }
|
||||||
"+"
|
|
||||||
} else {
|
|
||||||
"-"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -579,10 +579,10 @@ impl HiArgs {
|
|||||||
SearchMode::Count => SummaryKind::Count,
|
SearchMode::Count => SummaryKind::Count,
|
||||||
SearchMode::CountMatches => SummaryKind::CountMatches,
|
SearchMode::CountMatches => SummaryKind::CountMatches,
|
||||||
SearchMode::JSON => {
|
SearchMode::JSON => {
|
||||||
return Printer::JSON(self.printer_json(wtr))
|
return Printer::JSON(self.printer_json(wtr));
|
||||||
}
|
}
|
||||||
SearchMode::Standard => {
|
SearchMode::Standard => {
|
||||||
return Printer::Standard(self.printer_standard(wtr))
|
return Printer::Standard(self.printer_standard(wtr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -809,11 +809,7 @@ impl HiArgs {
|
|||||||
// When both error, we can't distinguish, so treat as equal.
|
// When both error, we can't distinguish, so treat as equal.
|
||||||
(None, None) => Ordering::Equal,
|
(None, None) => Ordering::Equal,
|
||||||
};
|
};
|
||||||
if sort.reverse {
|
if sort.reverse { ordering.reverse() } else { ordering }
|
||||||
ordering.reverse()
|
|
||||||
} else {
|
|
||||||
ordering
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Box::new(with_timestamps.into_iter().map(|(s, _)| s))
|
Box::new(with_timestamps.into_iter().map(|(s, _)| s))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ pub(crate) use crate::flags::{
|
|||||||
},
|
},
|
||||||
hiargs::HiArgs,
|
hiargs::HiArgs,
|
||||||
lowargs::{GenerateMode, Mode, SearchMode, SpecialMode},
|
lowargs::{GenerateMode, Mode, SearchMode, SpecialMode},
|
||||||
parse::{parse, ParseResult},
|
parse::{ParseResult, parse},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod complete;
|
mod complete;
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ use std::{borrow::Cow, collections::BTreeSet, ffi::OsString};
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
|
||||||
use crate::flags::{
|
use crate::flags::{
|
||||||
|
Flag, FlagValue,
|
||||||
defs::FLAGS,
|
defs::FLAGS,
|
||||||
hiargs::HiArgs,
|
hiargs::HiArgs,
|
||||||
lowargs::{LoggingMode, LowArgs, SpecialMode},
|
lowargs::{LoggingMode, LowArgs, SpecialMode},
|
||||||
Flag, FlagValue,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The result of parsing CLI arguments.
|
/// The result of parsing CLI arguments.
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::path::{is_separator, Path};
|
use std::path::{Path, is_separator};
|
||||||
|
|
||||||
use regex_automata::meta::Regex;
|
use regex_automata::meta::Regex;
|
||||||
|
|
||||||
use crate::{new_regex, Candidate, Error, ErrorKind};
|
use crate::{Candidate, Error, ErrorKind, new_regex};
|
||||||
|
|
||||||
/// Describes a matching strategy for a particular pattern.
|
/// Describes a matching strategy for a particular pattern.
|
||||||
///
|
///
|
||||||
@@ -340,11 +340,7 @@ impl Glob {
|
|||||||
let Token::Literal(c) = *t else { return None };
|
let Token::Literal(c) = *t else { return None };
|
||||||
lit.push(c);
|
lit.push(c);
|
||||||
}
|
}
|
||||||
if lit.is_empty() {
|
if lit.is_empty() { None } else { Some(lit) }
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(lit)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an extension if this pattern matches a file path if and only
|
/// Returns an extension if this pattern matches a file path if and only
|
||||||
@@ -385,11 +381,7 @@ impl Glob {
|
|||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if lit.is_empty() {
|
if lit.is_empty() { None } else { Some(lit) }
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(lit)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is like `ext`, but returns an extension even if it isn't sufficient
|
/// This is like `ext`, but returns an extension even if it isn't sufficient
|
||||||
@@ -452,11 +444,7 @@ impl Glob {
|
|||||||
if need_sep {
|
if need_sep {
|
||||||
lit.push('/');
|
lit.push('/');
|
||||||
}
|
}
|
||||||
if lit.is_empty() {
|
if lit.is_empty() { None } else { Some(lit) }
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(lit)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a literal suffix of this pattern if the entire pattern matches
|
/// Returns a literal suffix of this pattern if the entire pattern matches
|
||||||
@@ -505,11 +493,7 @@ impl Glob {
|
|||||||
let Token::Literal(c) = *t else { return None };
|
let Token::Literal(c) = *t else { return None };
|
||||||
lit.push(c);
|
lit.push(c);
|
||||||
}
|
}
|
||||||
if lit.is_empty() || lit == "/" {
|
if lit.is_empty() || lit == "/" { None } else { Some((lit, entire)) }
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some((lit, entire))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If this pattern only needs to inspect the basename of a file path,
|
/// If this pattern only needs to inspect the basename of a file path,
|
||||||
|
|||||||
@@ -120,11 +120,11 @@ use std::{
|
|||||||
|
|
||||||
use {
|
use {
|
||||||
aho_corasick::AhoCorasick,
|
aho_corasick::AhoCorasick,
|
||||||
bstr::{ByteSlice, ByteVec, B},
|
bstr::{B, ByteSlice, ByteVec},
|
||||||
regex_automata::{
|
regex_automata::{
|
||||||
|
PatternSet,
|
||||||
meta::Regex,
|
meta::Regex,
|
||||||
util::pool::{Pool, PoolGuard},
|
util::pool::{Pool, PoolGuard},
|
||||||
PatternSet,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -634,11 +634,7 @@ impl<'a> Candidate<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn path_prefix(&self, max: usize) -> &[u8] {
|
fn path_prefix(&self, max: usize) -> &[u8] {
|
||||||
if self.path.len() <= max {
|
if self.path.len() <= max { &*self.path } else { &self.path[..max] }
|
||||||
&*self.path
|
|
||||||
} else {
|
|
||||||
&self.path[..max]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_suffix(&self, max: usize) -> &[u8] {
|
fn path_suffix(&self, max: usize) -> &[u8] {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ pub(crate) fn normalize_path(mut path: Cow<[u8]>) -> Cow<[u8]> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use bstr::{ByteVec, B};
|
use bstr::{B, ByteVec};
|
||||||
|
|
||||||
use super::{file_name_ext, normalize_path};
|
use super::{file_name_ext, normalize_path};
|
||||||
|
|
||||||
|
|||||||
@@ -891,7 +891,7 @@ mod tests {
|
|||||||
use std::{io::Write, path::Path};
|
use std::{io::Write, path::Path};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dir::IgnoreBuilder, gitignore::Gitignore, tests::TempDir, Error,
|
Error, dir::IgnoreBuilder, gitignore::Gitignore, tests::TempDir,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn wfile<P: AsRef<Path>>(path: P, contents: &str) {
|
fn wfile<P: AsRef<Path>>(path: P, contents: &str) {
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ use {
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
pathutil::{is_file_name, strip_prefix},
|
|
||||||
Error, Match, PartialErrorBuilder,
|
Error, Match, PartialErrorBuilder,
|
||||||
|
pathutil::{is_file_name, strip_prefix},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Glob represents a single glob in a gitignore file.
|
/// Glob represents a single glob in a gitignore file.
|
||||||
|
|||||||
@@ -477,11 +477,7 @@ impl<T> Match<T> {
|
|||||||
|
|
||||||
/// Return the match if it is not none. Otherwise, return other.
|
/// Return the match if it is not none. Otherwise, return other.
|
||||||
pub fn or(self, other: Self) -> Self {
|
pub fn or(self, other: Self) -> Self {
|
||||||
if self.is_none() {
|
if self.is_none() { other } else { self }
|
||||||
other
|
|
||||||
} else {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ line tools.
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
gitignore::{self, Gitignore, GitignoreBuilder},
|
|
||||||
Error, Match,
|
Error, Match,
|
||||||
|
gitignore::{self, Gitignore, GitignoreBuilder},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Glob represents a single glob in an override matcher.
|
/// Glob represents a single glob in an override matcher.
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ use {
|
|||||||
regex_automata::util::pool::Pool,
|
regex_automata::util::pool::Pool,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{default_types::DEFAULT_TYPES, pathutil::file_name, Error, Match};
|
use crate::{Error, Match, default_types::DEFAULT_TYPES, pathutil::file_name};
|
||||||
|
|
||||||
/// Glob represents a single glob in a set of file type definitions.
|
/// Glob represents a single glob in a set of file type definitions.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use std::{
|
|||||||
fs::{self, FileType, Metadata},
|
fs::{self, FileType, Metadata},
|
||||||
io,
|
io,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering},
|
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering},
|
||||||
};
|
};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
@@ -15,11 +15,11 @@ use {
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Error, PartialErrorBuilder,
|
||||||
dir::{Ignore, IgnoreBuilder},
|
dir::{Ignore, IgnoreBuilder},
|
||||||
gitignore::GitignoreBuilder,
|
gitignore::GitignoreBuilder,
|
||||||
overrides::Override,
|
overrides::Override,
|
||||||
types::Types,
|
types::Types,
|
||||||
Error, PartialErrorBuilder,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A directory entry with a possible error attached.
|
/// A directory entry with a possible error attached.
|
||||||
@@ -1894,7 +1894,7 @@ fn device_num<P: AsRef<Path>>(path: P) -> io::Result<u64> {
|
|||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn device_num<P: AsRef<Path>>(path: P) -> io::Result<u64> {
|
fn device_num<P: AsRef<Path>>(path: P) -> io::Result<u64> {
|
||||||
use winapi_util::{file, Handle};
|
use winapi_util::{Handle, file};
|
||||||
|
|
||||||
let h = Handle::from_path_any(path)?;
|
let h = Handle::from_path_any(path)?;
|
||||||
file::information(h).map(|info| info.volume_serial_number())
|
file::information(h).map(|info| info.volume_serial_number())
|
||||||
@@ -1940,11 +1940,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn normal_path(unix: &str) -> String {
|
fn normal_path(unix: &str) -> String {
|
||||||
if cfg!(windows) {
|
if cfg!(windows) { unix.replace("\\", "/") } else { unix.to_string() }
|
||||||
unix.replace("\\", "/")
|
|
||||||
} else {
|
|
||||||
unix.to_string()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn walk_collect(prefix: &Path, builder: &WalkBuilder) -> Vec<String> {
|
fn walk_collect(prefix: &Path, builder: &WalkBuilder) -> Vec<String> {
|
||||||
|
|||||||
@@ -200,13 +200,17 @@ 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!(m("ROOT/parent_dir/dir_deep_00/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
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!(m("ROOT/parent_dir/dir_deep_01/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
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());
|
||||||
@@ -248,51 +252,67 @@ 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!(m("ROOT/parent_dir/dir_deep_20/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
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!(m("ROOT/parent_dir/dir_deep_21/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
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!(m("ROOT/parent_dir/dir_deep_22/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
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!(m("ROOT/parent_dir/dir_deep_23/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
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!(m("ROOT/parent_dir/dir_deep_30/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
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!(m("ROOT/parent_dir/dir_deep_31/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
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!(m("ROOT/parent_dir/dir_deep_32/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
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!(m("ROOT/parent_dir/dir_deep_33/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_33/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ fn is_valid_cap_letter(b: &u8) -> bool {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{find_cap_ref, interpolate, CaptureRef};
|
use super::{CaptureRef, find_cap_ref, interpolate};
|
||||||
|
|
||||||
macro_rules! find {
|
macro_rules! find {
|
||||||
($name:ident, $text:expr) => {
|
($name:ident, $text:expr) => {
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ use {
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
counter::CounterWriter, jsont, stats::Stats,
|
counter::CounterWriter, jsont, stats::Stats, util::Replacer,
|
||||||
util::find_iter_at_in_context, util::Replacer,
|
util::find_iter_at_in_context,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The configuration for the JSON printer.
|
/// The configuration for the JSON printer.
|
||||||
@@ -969,7 +969,7 @@ mod tests {
|
|||||||
use grep_regex::{RegexMatcher, RegexMatcherBuilder};
|
use grep_regex::{RegexMatcher, RegexMatcherBuilder};
|
||||||
use grep_searcher::SearcherBuilder;
|
use grep_searcher::SearcherBuilder;
|
||||||
|
|
||||||
use super::{JSONBuilder, JSON};
|
use super::{JSON, JSONBuilder};
|
||||||
|
|
||||||
const SHERLOCK: &'static [u8] = b"\
|
const SHERLOCK: &'static [u8] = b"\
|
||||||
For the Doctor Watsons of this world, as opposed to the Sherlock
|
For the Doctor Watsons of this world, as opposed to the Sherlock
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ assert_eq!(output, expected);
|
|||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
color::{default_color_specs, ColorError, ColorSpecs, UserColorSpec},
|
color::{ColorError, ColorSpecs, UserColorSpec, default_color_specs},
|
||||||
hyperlink::{
|
hyperlink::{
|
||||||
hyperlink_aliases, HyperlinkAlias, HyperlinkConfig,
|
HyperlinkAlias, HyperlinkConfig, HyperlinkEnvironment,
|
||||||
HyperlinkEnvironment, HyperlinkFormat, HyperlinkFormatError,
|
HyperlinkFormat, HyperlinkFormatError, hyperlink_aliases,
|
||||||
},
|
},
|
||||||
path::{PathPrinter, PathPrinterBuilder},
|
path::{PathPrinter, PathPrinterBuilder},
|
||||||
standard::{Standard, StandardBuilder, StandardSink},
|
standard::{Standard, StandardBuilder, StandardSink},
|
||||||
@@ -73,7 +73,7 @@ pub use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
pub use crate::json::{JSONBuilder, JSONSink, JSON};
|
pub use crate::json::{JSON, JSONBuilder, JSONSink};
|
||||||
|
|
||||||
// The maximum number of bytes to execute a search to account for look-ahead.
|
// The maximum number of bytes to execute a search to account for look-ahead.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ use crate::{
|
|||||||
hyperlink::{self, HyperlinkConfig},
|
hyperlink::{self, HyperlinkConfig},
|
||||||
stats::Stats,
|
stats::Stats,
|
||||||
util::{
|
util::{
|
||||||
find_iter_at_in_context, trim_ascii_prefix, trim_line_terminator,
|
|
||||||
DecimalFormatter, PrinterPath, Replacer, Sunk,
|
DecimalFormatter, PrinterPath, Replacer, Sunk,
|
||||||
|
find_iter_at_in_context, trim_ascii_prefix, trim_line_terminator,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use crate::{
|
|||||||
counter::CounterWriter,
|
counter::CounterWriter,
|
||||||
hyperlink::{self, HyperlinkConfig},
|
hyperlink::{self, HyperlinkConfig},
|
||||||
stats::Stats,
|
stats::Stats,
|
||||||
util::{find_iter_at_in_context, PrinterPath},
|
util::{PrinterPath, find_iter_at_in_context},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The configuration for the summary printer.
|
/// The configuration for the summary printer.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{hyperlink::HyperlinkPath, MAX_LOOK_AHEAD};
|
use crate::{MAX_LOOK_AHEAD, hyperlink::HyperlinkPath};
|
||||||
|
|
||||||
/// A type for handling replacements while amortizing allocation.
|
/// A type for handling replacements while amortizing allocation.
|
||||||
pub(crate) struct Replacer<M: Matcher> {
|
pub(crate) struct Replacer<M: Matcher> {
|
||||||
|
|||||||
@@ -341,11 +341,7 @@ impl ConfiguredHIR {
|
|||||||
|
|
||||||
/// Returns the "end line" anchor for this configuration.
|
/// Returns the "end line" anchor for this configuration.
|
||||||
fn line_anchor_end(&self) -> hir::Look {
|
fn line_anchor_end(&self) -> hir::Look {
|
||||||
if self.config.crlf {
|
if self.config.crlf { hir::Look::EndCRLF } else { hir::Look::EndLF }
|
||||||
hir::Look::EndCRLF
|
|
||||||
} else {
|
|
||||||
hir::Look::EndLF
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
use {
|
use {
|
||||||
regex_automata::meta::Regex,
|
regex_automata::meta::Regex,
|
||||||
regex_syntax::hir::{
|
regex_syntax::hir::{
|
||||||
self,
|
self, Hir,
|
||||||
literal::{Literal, Seq},
|
literal::{Literal, Seq},
|
||||||
Hir,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -223,11 +222,7 @@ impl Extractor {
|
|||||||
// extracting prefixes or suffixes.
|
// extracting prefixes or suffixes.
|
||||||
seq = self.cross(seq, self.extract(hir));
|
seq = self.cross(seq, self.extract(hir));
|
||||||
}
|
}
|
||||||
if let Some(prev) = prev {
|
if let Some(prev) = prev { prev.choose(seq) } else { seq }
|
||||||
prev.choose(seq)
|
|
||||||
} else {
|
|
||||||
seq
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract a sequence from the given alternation.
|
/// Extract a sequence from the given alternation.
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use {
|
|||||||
NoError,
|
NoError,
|
||||||
},
|
},
|
||||||
regex_automata::{
|
regex_automata::{
|
||||||
meta::Regex, util::captures::Captures as AutomataCaptures, Input,
|
Input, PatternID, meta::Regex,
|
||||||
PatternID,
|
util::captures::Captures as AutomataCaptures,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -587,10 +587,12 @@ mod tests {
|
|||||||
// and the regex could not be modified to remove a line terminator.
|
// and the regex could not be modified to remove a line terminator.
|
||||||
#[test]
|
#[test]
|
||||||
fn line_terminator_error() {
|
fn line_terminator_error() {
|
||||||
assert!(RegexMatcherBuilder::new()
|
assert!(
|
||||||
.line_terminator(Some(b'\n'))
|
RegexMatcherBuilder::new()
|
||||||
.build(r"a\nz")
|
.line_terminator(Some(b'\n'))
|
||||||
.is_err())
|
.build(r"a\nz")
|
||||||
|
.is_err()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that enabling CRLF permits `$` to match at the end of a line.
|
// Test that enabling CRLF permits `$` to match at the end of a line.
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ fn strip_from_match_ascii(expr: Hir, byte: u8) -> Result<Hir, Error> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use regex_syntax::Parser;
|
use regex_syntax::Parser;
|
||||||
|
|
||||||
use super::{strip_from_match, LineTerminator};
|
use super::{LineTerminator, strip_from_match};
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
fn roundtrip(pattern: &str, byte: u8) -> String {
|
fn roundtrip(pattern: &str, byte: u8) -> String {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use std::io;
|
|||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use grep_regex::RegexMatcher;
|
use grep_regex::RegexMatcher;
|
||||||
use grep_searcher::sinks::UTF8;
|
|
||||||
use grep_searcher::Searcher;
|
use grep_searcher::Searcher;
|
||||||
|
use grep_searcher::sinks::UTF8;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if let Err(err) = example() {
|
if let Err(err) = example() {
|
||||||
@@ -18,7 +18,7 @@ fn example() -> Result<(), Box<dyn Error>> {
|
|||||||
let pattern = match env::args().nth(1) {
|
let pattern = match env::args().nth(1) {
|
||||||
Some(pattern) => pattern,
|
Some(pattern) => pattern,
|
||||||
None => {
|
None => {
|
||||||
return Err(From::from(format!("Usage: search-stdin <pattern>")))
|
return Err(From::from(format!("Usage: search-stdin <pattern>")));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let matcher = RegexMatcher::new(&pattern)?;
|
let matcher = RegexMatcher::new(&pattern)?;
|
||||||
|
|||||||
@@ -90,8 +90,8 @@ pub use crate::{
|
|||||||
SearcherBuilder,
|
SearcherBuilder,
|
||||||
},
|
},
|
||||||
sink::{
|
sink::{
|
||||||
sinks, Sink, SinkContext, SinkContextKind, SinkError, SinkFinish,
|
Sink, SinkContext, SinkContextKind, SinkError, SinkFinish, SinkMatch,
|
||||||
SinkMatch,
|
sinks,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use grep_matcher::Matcher;
|
use grep_matcher::Matcher;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
line_buffer::{LineBufferReader, DEFAULT_BUFFER_CAPACITY},
|
line_buffer::{DEFAULT_BUFFER_CAPACITY, LineBufferReader},
|
||||||
lines::{self, LineStep},
|
lines::{self, LineStep},
|
||||||
searcher::{core::Core, Config, Range, Searcher},
|
searcher::{Config, Range, Searcher, core::Core},
|
||||||
sink::{Sink, SinkError},
|
sink::{Sink, SinkError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ use {
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
line_buffer::{
|
line_buffer::{
|
||||||
self, alloc_error, BufferAllocation, LineBuffer, LineBufferBuilder,
|
self, BufferAllocation, DEFAULT_BUFFER_CAPACITY, LineBuffer,
|
||||||
LineBufferReader, DEFAULT_BUFFER_CAPACITY,
|
LineBufferBuilder, LineBufferReader, alloc_error,
|
||||||
},
|
},
|
||||||
searcher::glue::{MultiLine, ReadByLine, SliceByLine},
|
searcher::glue::{MultiLine, ReadByLine, SliceByLine},
|
||||||
sink::{Sink, SinkError},
|
sink::{Sink, SinkError},
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
max_width = 79
|
max_width = 79
|
||||||
use_small_heuristics = "max"
|
use_small_heuristics = "max"
|
||||||
|
edition = "2024"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::hay::{SHERLOCK, SHERLOCK_CRLF};
|
use crate::hay::{SHERLOCK, SHERLOCK_CRLF};
|
||||||
use crate::util::{sort_lines, Dir, TestCommand};
|
use crate::util::{Dir, TestCommand, sort_lines};
|
||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/1
|
// See: https://github.com/BurntSushi/ripgrep/issues/1
|
||||||
rgtest!(f1_sjis, |dir: Dir, mut cmd: TestCommand| {
|
rgtest!(f1_sjis, |dir: Dir, mut cmd: TestCommand| {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::hay::SHERLOCK;
|
use crate::hay::SHERLOCK;
|
||||||
use crate::util::{cmd_exists, sort_lines, Dir, TestCommand};
|
use crate::util::{Dir, TestCommand, cmd_exists, sort_lines};
|
||||||
|
|
||||||
// This file contains "miscellaneous" tests that were either written before
|
// This file contains "miscellaneous" tests that were either written before
|
||||||
// features were tracked more explicitly, or were simply written without
|
// features were tracked more explicitly, or were simply written without
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::hay::SHERLOCK;
|
use crate::hay::SHERLOCK;
|
||||||
use crate::util::{sort_lines, Dir, TestCommand};
|
use crate::util::{Dir, TestCommand, sort_lines};
|
||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/16
|
// See: https://github.com/BurntSushi/ripgrep/issues/16
|
||||||
rgtest!(r16, |dir: Dir, mut cmd: TestCommand| {
|
rgtest!(r16, |dir: Dir, mut cmd: TestCommand| {
|
||||||
|
|||||||
Reference in New Issue
Block a user