##// END OF EJS Templates
rust-ui: refactor ui code for printing narrow/sparse warnings...
Raphaël Gomès -
r50876:364e7838 default
parent child Browse files
Show More
@@ -6,7 +6,9 b''
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 use crate::error::CommandError;
8 use crate::error::CommandError;
9 use crate::ui::Ui;
9 use crate::ui::{
10 format_pattern_file_warning, print_narrow_sparse_warnings, Ui,
11 };
10 use crate::utils::path_utils::RelativizePaths;
12 use crate::utils::path_utils::RelativizePaths;
11 use clap::Arg;
13 use clap::Arg;
12 use format_bytes::format_bytes;
14 use format_bytes::format_bytes;
@@ -20,7 +22,6 b' use hg::manifest::Manifest;'
20 use hg::matchers::{AlwaysMatcher, IntersectionMatcher};
22 use hg::matchers::{AlwaysMatcher, IntersectionMatcher};
21 use hg::repo::Repo;
23 use hg::repo::Repo;
22 use hg::utils::files::get_bytes_from_os_string;
24 use hg::utils::files::get_bytes_from_os_string;
23 use hg::utils::files::get_bytes_from_path;
24 use hg::utils::files::get_path_from_bytes;
25 use hg::utils::files::get_path_from_bytes;
25 use hg::utils::hg_path::{hg_path_to_path_buf, HgPath};
26 use hg::utils::hg_path::{hg_path_to_path_buf, HgPath};
26 use hg::DirstateStatus;
27 use hg::DirstateStatus;
@@ -269,7 +270,7 b' pub fn run(invocation: &crate::CliInvoca'
269 let after_status = |res: StatusResult| -> Result<_, CommandError> {
270 let after_status = |res: StatusResult| -> Result<_, CommandError> {
270 let (mut ds_status, pattern_warnings) = res?;
271 let (mut ds_status, pattern_warnings) = res?;
271 for warning in pattern_warnings {
272 for warning in pattern_warnings {
272 ui.write_stderr(&print_pattern_file_warning(&warning, repo))?;
273 ui.write_stderr(&format_pattern_file_warning(&warning, repo))?;
273 }
274 }
274
275
275 for (path, error) in ds_status.bad {
276 for (path, error) in ds_status.bad {
@@ -385,31 +386,12 b' pub fn run(invocation: &crate::CliInvoca'
385 (false, false) => Box::new(AlwaysMatcher),
386 (false, false) => Box::new(AlwaysMatcher),
386 };
387 };
387
388
388 for warning in narrow_warnings.into_iter().chain(sparse_warnings) {
389 print_narrow_sparse_warnings(
389 match &warning {
390 &narrow_warnings,
390 sparse::SparseWarning::RootWarning { context, line } => {
391 &sparse_warnings,
391 let msg = format_bytes!(
392 ui,
392 b"warning: {} profile cannot use paths \"
393 repo,
393 starting with /, ignoring {}\n",
394 )?;
394 context,
395 line
396 );
397 ui.write_stderr(&msg)?;
398 }
399 sparse::SparseWarning::ProfileNotFound { profile, rev } => {
400 let msg = format_bytes!(
401 b"warning: sparse profile '{}' not found \"
402 in rev {} - ignoring it\n",
403 profile,
404 rev
405 );
406 ui.write_stderr(&msg)?;
407 }
408 sparse::SparseWarning::Pattern(e) => {
409 ui.write_stderr(&print_pattern_file_warning(e, repo))?;
410 }
411 }
412 }
413 let (fixup, mut dirstate_write_needed, filesystem_time_at_status_start) =
395 let (fixup, mut dirstate_write_needed, filesystem_time_at_status_start) =
414 dmap.with_status(
396 dmap.with_status(
415 matcher.as_ref(),
397 matcher.as_ref(),
@@ -617,30 +599,3 b' fn unsure_is_modified('
617 };
599 };
618 Ok(p1_contents != &*fs_contents)
600 Ok(p1_contents != &*fs_contents)
619 }
601 }
620
621 fn print_pattern_file_warning(
622 warning: &PatternFileWarning,
623 repo: &Repo,
624 ) -> Vec<u8> {
625 match warning {
626 PatternFileWarning::InvalidSyntax(path, syntax) => format_bytes!(
627 b"{}: ignoring invalid syntax '{}'\n",
628 get_bytes_from_path(path),
629 &*syntax
630 ),
631 PatternFileWarning::NoSuchFile(path) => {
632 let path = if let Ok(relative) =
633 path.strip_prefix(repo.working_directory_path())
634 {
635 relative
636 } else {
637 &*path
638 };
639 format_bytes!(
640 b"skipping unreadable pattern file '{}': \
641 No such file or directory\n",
642 get_bytes_from_path(path),
643 )
644 }
645 }
646 }
@@ -1,10 +1,15 b''
1 use crate::color::ColorConfig;
1 use crate::color::ColorConfig;
2 use crate::color::Effect;
2 use crate::color::Effect;
3 use crate::error::CommandError;
3 use format_bytes::format_bytes;
4 use format_bytes::format_bytes;
4 use format_bytes::write_bytes;
5 use format_bytes::write_bytes;
5 use hg::config::Config;
6 use hg::config::Config;
6 use hg::config::PlainInfo;
7 use hg::config::PlainInfo;
7 use hg::errors::HgError;
8 use hg::errors::HgError;
9 use hg::repo::Repo;
10 use hg::sparse;
11 use hg::utils::files::get_bytes_from_path;
12 use hg::PatternFileWarning;
8 use std::borrow::Cow;
13 use std::borrow::Cow;
9 use std::io;
14 use std::io;
10 use std::io::{ErrorKind, Write};
15 use std::io::{ErrorKind, Write};
@@ -223,3 +228,68 b' fn isatty(config: &Config) -> Result<boo'
223 atty::is(atty::Stream::Stdout)
228 atty::is(atty::Stream::Stdout)
224 })
229 })
225 }
230 }
231
232 /// Return the formatted bytestring corresponding to a pattern file warning,
233 /// as expected by the CLI.
234 pub(crate) fn format_pattern_file_warning(
235 warning: &PatternFileWarning,
236 repo: &Repo,
237 ) -> Vec<u8> {
238 match warning {
239 PatternFileWarning::InvalidSyntax(path, syntax) => format_bytes!(
240 b"{}: ignoring invalid syntax '{}'\n",
241 get_bytes_from_path(path),
242 &*syntax
243 ),
244 PatternFileWarning::NoSuchFile(path) => {
245 let path = if let Ok(relative) =
246 path.strip_prefix(repo.working_directory_path())
247 {
248 relative
249 } else {
250 &*path
251 };
252 format_bytes!(
253 b"skipping unreadable pattern file '{}': \
254 No such file or directory\n",
255 get_bytes_from_path(path),
256 )
257 }
258 }
259 }
260
261 /// Print with `Ui` the formatted bytestring corresponding to a
262 /// sparse/narrow warning, as expected by the CLI.
263 pub(crate) fn print_narrow_sparse_warnings(
264 narrow_warnings: &[sparse::SparseWarning],
265 sparse_warnings: &[sparse::SparseWarning],
266 ui: &Ui,
267 repo: &Repo,
268 ) -> Result<(), CommandError> {
269 for warning in narrow_warnings.iter().chain(sparse_warnings) {
270 match &warning {
271 sparse::SparseWarning::RootWarning { context, line } => {
272 let msg = format_bytes!(
273 b"warning: {} profile cannot use paths \"
274 starting with /, ignoring {}\n",
275 context,
276 line
277 );
278 ui.write_stderr(&msg)?;
279 }
280 sparse::SparseWarning::ProfileNotFound { profile, rev } => {
281 let msg = format_bytes!(
282 b"warning: sparse profile '{}' not found \"
283 in rev {} - ignoring it\n",
284 profile,
285 rev
286 );
287 ui.write_stderr(&msg)?;
288 }
289 sparse::SparseWarning::Pattern(e) => {
290 ui.write_stderr(&format_pattern_file_warning(e, repo))?;
291 }
292 }
293 }
294 Ok(())
295 }
General Comments 0
You need to be logged in to leave comments. Login now