1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-06-04 05:57:39 +02:00

edition: move core ripgrep to Rust 2018

This commit is contained in:
Andrew Gallant 2019-01-19 10:15:56 -05:00
parent 1e9ee2cc85
commit 7a6a40bae1
15 changed files with 40 additions and 48 deletions

View File

@ -17,6 +17,7 @@ license = "Unlicense OR MIT"
exclude = ["HomebrewFormula"] exclude = ["HomebrewFormula"]
build = "build.rs" build = "build.rs"
autotests = false autotests = false
edition = "2018"
[badges] [badges]
travis-ci = { repository = "BurntSushi/ripgrep" } travis-ci = { repository = "BurntSushi/ripgrep" }

View File

@ -9,7 +9,8 @@
// is where we read clap's configuration from the end user's arguments and turn // is where we read clap's configuration from the end user's arguments and turn
// it into a ripgrep-specific configuration type that is not coupled with clap. // it into a ripgrep-specific configuration type that is not coupled with clap.
use clap::{self, App, AppSettings}; use clap::{self, App, AppSettings, crate_authors, crate_version};
use lazy_static::lazy_static;
const ABOUT: &str = " const ABOUT: &str = "
ripgrep (rg) recursively searches your current directory for a regex pattern. ripgrep (rg) recursively searches your current directory for a regex pattern.

View File

@ -34,20 +34,22 @@ use ignore::types::{FileTypeDef, Types, TypesBuilder};
use ignore::{Walk, WalkBuilder, WalkParallel}; use ignore::{Walk, WalkBuilder, WalkParallel};
use log; use log;
use num_cpus; use num_cpus;
use path_printer::{PathPrinter, PathPrinterBuilder};
use regex; use regex;
use termcolor::{ use termcolor::{
WriteColor, WriteColor,
BufferWriter, ColorChoice, BufferWriter, ColorChoice,
}; };
use app; use crate::app;
use config; use crate::config;
use logger::Logger; use crate::logger::Logger;
use messages::{set_messages, set_ignore_messages}; use crate::messages::{set_messages, set_ignore_messages};
use search::{PatternMatcher, Printer, SearchWorker, SearchWorkerBuilder}; use crate::path_printer::{PathPrinter, PathPrinterBuilder};
use subject::SubjectBuilder; use crate::search::{
use Result; PatternMatcher, Printer, SearchWorker, SearchWorkerBuilder,
};
use crate::subject::SubjectBuilder;
use crate::Result;
/// The command that ripgrep should execute based on the command line /// The command that ripgrep should execute based on the command line
/// configuration. /// configuration.
@ -491,7 +493,9 @@ impl ArgMatches {
fn reconfigure(self) -> ArgMatches { fn reconfigure(self) -> ArgMatches {
// If the end user says no config, then respect it. // If the end user says no config, then respect it.
if self.is_present("no-config") { if self.is_present("no-config") {
debug!("not reading config files because --no-config is present"); log::debug!(
"not reading config files because --no-config is present"
);
return self; return self;
} }
// If the user wants ripgrep to use a config file, then parse args // If the user wants ripgrep to use a config file, then parse args
@ -505,7 +509,7 @@ impl ArgMatches {
args.insert(0, bin); args.insert(0, bin);
} }
args.extend(cliargs); args.extend(cliargs);
debug!("final argv: {:?}", args); log::debug!("final argv: {:?}", args);
ArgMatches::new(app::app().get_matches_from(args)) ArgMatches::new(app::app().get_matches_from(args))
} }

View File

@ -9,7 +9,9 @@ use std::io::{self, BufRead};
use std::ffi::OsString; use std::ffi::OsString;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use Result; use log;
use crate::Result;
/// 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> {
@ -34,7 +36,7 @@ pub fn args() -> Vec<OsString> {
message!("{}:{}", config_path.display(), err); message!("{}:{}", config_path.display(), err);
} }
} }
debug!( log::debug!(
"{}: arguments loaded from config file: {:?}", "{}: arguments loaded from config file: {:?}",
config_path.display(), config_path.display(),
args args

View File

@ -1,17 +1,3 @@
#[macro_use]
extern crate clap;
extern crate grep;
extern crate ignore;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate num_cpus;
extern crate regex;
#[macro_use]
extern crate serde_json;
extern crate termcolor;
use std::io::{self, Write}; use std::io::{self, Write};
use std::process; use std::process;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};

View File

@ -6,7 +6,7 @@ static IGNORE_MESSAGES: AtomicBool = ATOMIC_BOOL_INIT;
#[macro_export] #[macro_export]
macro_rules! message { macro_rules! message {
($($tt:tt)*) => { ($($tt:tt)*) => {
if ::messages::messages() { if crate::messages::messages() {
eprintln!($($tt)*); eprintln!($($tt)*);
} }
} }
@ -15,7 +15,7 @@ macro_rules! message {
#[macro_export] #[macro_export]
macro_rules! ignore_message { macro_rules! ignore_message {
($($tt:tt)*) => { ($($tt:tt)*) => {
if ::messages::messages() && ::messages::ignore_messages() { if crate::messages::messages() && crate::messages::ignore_messages() {
eprintln!($($tt)*); eprintln!($($tt)*);
} }
} }

View File

@ -13,9 +13,10 @@ use grep::regex::{RegexMatcher as RustRegexMatcher};
use grep::searcher::Searcher; use grep::searcher::Searcher;
use ignore::overrides::Override; use ignore::overrides::Override;
use serde_json as json; use serde_json as json;
use serde_json::json;
use termcolor::WriteColor; use termcolor::WriteColor;
use subject::Subject; use crate::subject::Subject;
/// The configuration for the search worker. Among a few other things, the /// The configuration for the search worker. Among a few other things, the
/// configuration primarily controls the way we show search results to users /// configuration primarily controls the way we show search results to users

View File

@ -1,6 +1,7 @@
use std::path::Path; use std::path::Path;
use ignore::{self, DirEntry}; use ignore::{self, DirEntry};
use log;
/// A configuration for describing how subjects should be built. /// A configuration for describing how subjects should be built.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -79,7 +80,7 @@ impl SubjectBuilder {
// directory. Otherwise, emitting messages for directories is just // directory. Otherwise, emitting messages for directories is just
// noisy. // noisy.
if !subj.is_dir() { if !subj.is_dir() {
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(),

View File

@ -1,5 +1,5 @@
use hay::{SHERLOCK, SHERLOCK_CRLF}; use crate::hay::{SHERLOCK, SHERLOCK_CRLF};
use util::{Dir, TestCommand, sort_lines}; 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| {

View File

@ -1,9 +1,10 @@
use std::time; use std::time;
use serde_derive::Deserialize;
use serde_json as json; use serde_json as json;
use hay::{SHERLOCK, SHERLOCK_CRLF}; use crate::hay::{SHERLOCK, SHERLOCK_CRLF};
use util::{Dir, TestCommand}; use crate::util::{Dir, TestCommand};
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)] #[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", content = "data")] #[serde(tag = "type", content = "data")]

View File

@ -3,11 +3,11 @@ macro_rules! rgtest {
($name:ident, $fun:expr) => { ($name:ident, $fun:expr) => {
#[test] #[test]
fn $name() { fn $name() {
let (dir, cmd) = ::util::setup(stringify!($name)); let (dir, cmd) = crate::util::setup(stringify!($name));
$fun(dir, cmd); $fun(dir, cmd);
if cfg!(feature = "pcre2") { if cfg!(feature = "pcre2") {
let (dir, cmd) = ::util::setup_pcre2(stringify!($name)); let (dir, cmd) = crate::util::setup_pcre2(stringify!($name));
$fun(dir, cmd); $fun(dir, cmd);
} }
} }

View File

@ -1,5 +1,5 @@
use hay::SHERLOCK; use crate::hay::SHERLOCK;
use util::{Dir, TestCommand, cmd_exists, sort_lines}; 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

View File

@ -1,5 +1,5 @@
use hay::SHERLOCK; use crate::hay::SHERLOCK;
use util::{Dir, TestCommand}; use crate::util::{Dir, TestCommand};
// This tests that multiline matches that span multiple lines, but where // This tests that multiline matches that span multiple lines, but where
// multiple matches may begin and end on the same line work correctly. // multiple matches may begin and end on the same line work correctly.

View File

@ -1,5 +1,5 @@
use hay::SHERLOCK; use crate::hay::SHERLOCK;
use util::{Dir, TestCommand, sort_lines}; 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| {

View File

@ -1,8 +1,3 @@
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
// Macros useful for testing. // Macros useful for testing.
#[macro_use] #[macro_use]
mod macros; mod macros;