Patchwork D11941: rhg: Properly format warnings related to ignore patterns

login
register
mail settings
Submitter phabricator
Date Dec. 17, 2021, 4:45 p.m.
Message ID <differential-rev-PHID-DREV-3iefbqq4duxd6doblcfz-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50266/
State New
Headers show

Comments

phabricator - Dec. 17, 2021, 4:45 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11941

AFFECTED FILES
  rust/rhg/src/commands/status.rs

CHANGE DETAILS




To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs
--- a/rust/rhg/src/commands/status.rs
+++ b/rust/rhg/src/commands/status.rs
@@ -25,7 +25,7 @@ 
 use hg::utils::files::get_path_from_bytes;
 use hg::utils::hg_path::{hg_path_to_path_buf, HgPath};
 use hg::StatusOptions;
-use log::{info, warn};
+use log::info;
 use std::io;
 use std::path::PathBuf;
 
@@ -233,8 +233,29 @@ 
         ignore_files(repo, config),
         options,
     )?;
-    if !pattern_warnings.is_empty() {
-        warn!("Pattern warnings: {:?}", &pattern_warnings);
+    for warning in pattern_warnings {
+        match warning {
+            hg::PatternFileWarning::InvalidSyntax(path, syntax) => ui
+                .write_stderr(&format_bytes!(
+                    b"{}: ignoring invalid syntax '{}'\n",
+                    format_bytes::Utf8(path.display()),
+                    &*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",
+                    format_bytes::Utf8(path.display()),
+                ))?
+            }
+        }
     }
 
     for (path, error) in ds_status.bad {