# HG changeset patch # User Raphaël Gomès # Date 1658849614 -7200 # Node ID b18e877ea304974d40400551ddd91b9ca54cf893 # Parent 5fbdd88824dcbdc67e336e480657cafcbfb46e28 rhg-status: extract a function for printing pattern file warnings This will be reused for the warnings produced by the sparse file parsing functions. diff -r 5fbdd88824dc -r b18e877ea304 rust/rhg/src/commands/status.rs --- a/rust/rhg/src/commands/status.rs Mon Jul 18 17:25:49 2022 +0200 +++ b/rust/rhg/src/commands/status.rs Tue Jul 26 17:33:34 2022 +0200 @@ -276,28 +276,7 @@ let after_status = |res: StatusResult| -> Result<_, CommandError> { let (mut ds_status, pattern_warnings) = res?; for warning in pattern_warnings { - match warning { - hg::PatternFileWarning::InvalidSyntax(path, syntax) => ui - .write_stderr(&format_bytes!( - b"{}: ignoring invalid syntax '{}'\n", - get_bytes_from_path(path), - &*syntax - ))?, - hg::PatternFileWarning::NoSuchFile(path) => { - let path = if let Ok(relative) = - path.strip_prefix(repo.working_directory_path()) - { - relative - } else { - &*path - }; - ui.write_stderr(&format_bytes!( - b"skipping unreadable pattern file '{}': \ - No such file or directory\n", - get_bytes_from_path(path), - ))? - } - } + ui.write_stderr(&print_pattern_file_warning(&warning, &repo))?; } for (path, error) in ds_status.bad { @@ -582,3 +561,30 @@ }; Ok(p1_contents != &*fs_contents) } + +fn print_pattern_file_warning( + warning: &PatternFileWarning, + repo: &Repo, +) -> Vec { + match warning { + PatternFileWarning::InvalidSyntax(path, syntax) => format_bytes!( + b"{}: ignoring invalid syntax '{}'\n", + get_bytes_from_path(path), + &*syntax + ), + PatternFileWarning::NoSuchFile(path) => { + let path = if let Ok(relative) = + path.strip_prefix(repo.working_directory_path()) + { + relative + } else { + &*path + }; + format_bytes!( + b"skipping unreadable pattern file '{}': \ + No such file or directory\n", + get_bytes_from_path(path), + ) + } + } +}