Skip to content

Commit

Permalink
logging: add new --no-ignore-messages flag
Browse files Browse the repository at this point in the history
The new --no-ignore-messages flag permits suppressing errors related to
parsing .gitignore or .ignore files. These error messages can be somewhat
annoying since they can surface from repositories that one has no control
over.

Fixes #646
  • Loading branch information
BurntSushi committed Apr 23, 2018
1 parent b4781e2 commit 0ee0b16
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
flag_mmap(&mut args);
flag_no_config(&mut args);
flag_no_ignore(&mut args);
flag_no_ignore_messages(&mut args);
flag_no_ignore_parent(&mut args);
flag_no_ignore_vcs(&mut args);
flag_no_messages(&mut args);
Expand Down Expand Up @@ -1240,6 +1241,25 @@ This flag can be disabled with the --ignore flag.
args.push(arg);
}

fn flag_no_ignore_messages(args: &mut Vec<RGArg>) {
const SHORT: &str = "Suppress gitignore parse error messages.";
const LONG: &str = long!("\
Suppresses all error messages related to parsing ignore files such as .ignore
or .gitignore.
This flag can be disabled with the --ignore-messages flag.
");
let arg = RGArg::switch("no-ignore-messages")
.help(SHORT).long_help(LONG)
.overrides("ignore-messages");
args.push(arg);

let arg = RGArg::switch("ignore-messages")
.hidden()
.overrides("no-ignore-messages");
args.push(arg);
}

fn flag_no_ignore_parent(args: &mut Vec<RGArg>) {
const SHORT: &str = "Don't respect ignore files in parent directories.";
const LONG: &str = long!("\
Expand Down Expand Up @@ -1279,7 +1299,7 @@ This flag can be disabled with the --ignore-vcs flag.
}

fn flag_no_messages(args: &mut Vec<RGArg>) {
const SHORT: &str = "Suppress all error messages.";
const SHORT: &str = "Suppress some error messages.";
const LONG: &str = long!("\
Suppress all error messages related to opening and reading files. Error
messages related to the syntax of the pattern given are still shown.
Expand Down
10 changes: 9 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct Args {
maxdepth: Option<usize>,
mmap: bool,
no_ignore: bool,
no_ignore_messages: bool,
no_ignore_parent: bool,
no_ignore_vcs: bool,
no_messages: bool,
Expand Down Expand Up @@ -308,6 +309,12 @@ impl Args {
self.no_messages
}

/// Returns true if error messages associated with parsing .ignore or
/// .gitignore files should be suppressed.
pub fn no_ignore_messages(&self) -> bool {
self.no_ignore_messages
}

/// Create a new recursive directory iterator over the paths in argv.
pub fn walker(&self) -> ignore::Walk {
self.walker_builder().build()
Expand All @@ -327,7 +334,7 @@ impl Args {
}
for path in &self.ignore_files {
if let Some(err) = wd.add_ignore(path) {
if !self.no_messages {
if !self.no_messages && !self.no_ignore_messages {
eprintln!("{}", err);
}
}
Expand Down Expand Up @@ -402,6 +409,7 @@ impl<'a> ArgMatches<'a> {
maxdepth: self.usize_of("maxdepth")?,
mmap: mmap,
no_ignore: self.no_ignore(),
no_ignore_messages: self.is_present("no-ignore-messages"),
no_ignore_parent: self.no_ignore_parent(),
no_ignore_vcs: self.no_ignore_vcs(),
no_messages: self.is_present("no-messages"),
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn run_parallel(args: &Arc<Args>) -> Result<u64> {
args.stdout_handle(),
args.files(),
args.no_messages(),
args.no_ignore_messages(),
) {
None => return Continue,
Some(dent) => dent,
Expand Down Expand Up @@ -176,6 +177,7 @@ fn run_one_thread(args: &Arc<Args>) -> Result<u64> {
args.stdout_handle(),
args.files(),
args.no_messages(),
args.no_ignore_messages(),
) {
None => continue,
Some(dent) => dent,
Expand Down Expand Up @@ -241,6 +243,7 @@ fn run_files_parallel(args: Arc<Args>) -> Result<u64> {
args.stdout_handle(),
args.files(),
args.no_messages(),
args.no_ignore_messages(),
) {
tx.send(dent).unwrap();
}
Expand All @@ -260,6 +263,7 @@ fn run_files_one_thread(args: &Arc<Args>) -> Result<u64> {
args.stdout_handle(),
args.files(),
args.no_messages(),
args.no_ignore_messages(),
) {
None => continue,
Some(dent) => dent,
Expand Down Expand Up @@ -288,6 +292,7 @@ fn get_or_log_dir_entry(
stdout_handle: Option<&same_file::Handle>,
files_only: bool,
no_messages: bool,
no_ignore_messages: bool,
) -> Option<ignore::DirEntry> {
match result {
Err(err) => {
Expand All @@ -298,7 +303,7 @@ fn get_or_log_dir_entry(
}
Ok(dent) => {
if let Some(err) = dent.error() {
if !no_messages {
if !no_messages && !no_ignore_messages {
eprintln!("{}", err);
}
}
Expand Down

0 comments on commit 0ee0b16

Please sign in to comment.