Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/filepatterns.rs @ 49930:e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
All of these are simple changes that for the most part are clear improvements
and the rest are at most equivalent.
The remaining warnings have to be fixed either with a bigger refactor like for
the nested "revlog" module, or in the dependency `bytes-cast`, which we own.
This will be done sometime in the future.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 09 Jan 2023 19:18:43 +0100 |
parents | ccb6cfb0f2c0 |
children | 1c31b343e514 |
comparison
equal
deleted
inserted
replaced
49929:5f1cd6839c69 | 49930:e98fd81bb151 |
---|---|
311 } = entry; | 311 } = entry; |
312 let pattern = match syntax { | 312 let pattern = match syntax { |
313 PatternSyntax::RootGlob | 313 PatternSyntax::RootGlob |
314 | PatternSyntax::Path | 314 | PatternSyntax::Path |
315 | PatternSyntax::RelGlob | 315 | PatternSyntax::RelGlob |
316 | PatternSyntax::RootFiles => normalize_path_bytes(&pattern), | 316 | PatternSyntax::RootFiles => normalize_path_bytes(pattern), |
317 PatternSyntax::Include | PatternSyntax::SubInclude => { | 317 PatternSyntax::Include | PatternSyntax::SubInclude => { |
318 return Err(PatternError::NonRegexPattern(entry.clone())) | 318 return Err(PatternError::NonRegexPattern(entry.clone())) |
319 } | 319 } |
320 _ => pattern.to_owned(), | 320 _ => pattern.to_owned(), |
321 }; | 321 }; |
366 let comment_escape_regex = Regex::new(r"\\#").unwrap(); | 366 let comment_escape_regex = Regex::new(r"\\#").unwrap(); |
367 let mut inputs: Vec<IgnorePattern> = vec![]; | 367 let mut inputs: Vec<IgnorePattern> = vec![]; |
368 let mut warnings: Vec<PatternFileWarning> = vec![]; | 368 let mut warnings: Vec<PatternFileWarning> = vec![]; |
369 | 369 |
370 let mut current_syntax = | 370 let mut current_syntax = |
371 default_syntax_override.unwrap_or(b"relre:".as_ref()); | 371 default_syntax_override.unwrap_or_else(|| b"relre:".as_ref()); |
372 | 372 |
373 for (line_number, mut line) in lines.split(|c| *c == b'\n').enumerate() { | 373 for (line_number, mut line) in lines.split(|c| *c == b'\n').enumerate() { |
374 let line_number = line_number + 1; | 374 let line_number = line_number + 1; |
375 | 375 |
376 let line_buf; | 376 let line_buf; |
400 )); | 400 )); |
401 } | 401 } |
402 continue; | 402 continue; |
403 } | 403 } |
404 | 404 |
405 let mut line_syntax: &[u8] = ¤t_syntax; | 405 let mut line_syntax: &[u8] = current_syntax; |
406 | 406 |
407 for (s, rels) in SYNTAXES.iter() { | 407 for (s, rels) in SYNTAXES.iter() { |
408 if let Some(rest) = line.drop_prefix(rels) { | 408 if let Some(rest) = line.drop_prefix(rels) { |
409 line_syntax = rels; | 409 line_syntax = rels; |
410 line = rest; | 410 line = rest; |
416 break; | 416 break; |
417 } | 417 } |
418 } | 418 } |
419 | 419 |
420 inputs.push(IgnorePattern::new( | 420 inputs.push(IgnorePattern::new( |
421 parse_pattern_syntax(&line_syntax).map_err(|e| match e { | 421 parse_pattern_syntax(line_syntax).map_err(|e| match e { |
422 PatternError::UnsupportedSyntax(syntax) => { | 422 PatternError::UnsupportedSyntax(syntax) => { |
423 PatternError::UnsupportedSyntaxInFile( | 423 PatternError::UnsupportedSyntaxInFile( |
424 syntax, | 424 syntax, |
425 file_path.to_string_lossy().into(), | 425 file_path.to_string_lossy().into(), |
426 line_number, | 426 line_number, |
427 ) | 427 ) |
428 } | 428 } |
429 _ => e, | 429 _ => e, |
430 })?, | 430 })?, |
431 &line, | 431 line, |
432 file_path, | 432 file_path, |
433 )); | 433 )); |
434 } | 434 } |
435 Ok((inputs, warnings)) | 435 Ok((inputs, warnings)) |
436 } | 436 } |
500 warnings.extend(inner_warnings); | 500 warnings.extend(inner_warnings); |
501 inner_pats | 501 inner_pats |
502 } | 502 } |
503 PatternSyntax::SubInclude => { | 503 PatternSyntax::SubInclude => { |
504 let mut sub_include = SubInclude::new( | 504 let mut sub_include = SubInclude::new( |
505 &root_dir, | 505 root_dir, |
506 &entry.pattern, | 506 &entry.pattern, |
507 &entry.source, | 507 &entry.source, |
508 )?; | 508 )?; |
509 let (inner_patterns, inner_warnings) = | 509 let (inner_patterns, inner_warnings) = |
510 get_patterns_from_file( | 510 get_patterns_from_file( |
562 let new_root = path.parent().unwrap_or_else(|| path.deref()); | 562 let new_root = path.parent().unwrap_or_else(|| path.deref()); |
563 | 563 |
564 let prefix = canonical_path(root_dir, root_dir, new_root)?; | 564 let prefix = canonical_path(root_dir, root_dir, new_root)?; |
565 | 565 |
566 Ok(Self { | 566 Ok(Self { |
567 prefix: path_to_hg_path_buf(prefix).and_then(|mut p| { | 567 prefix: path_to_hg_path_buf(prefix).map(|mut p| { |
568 if !p.is_empty() { | 568 if !p.is_empty() { |
569 p.push_byte(b'/'); | 569 p.push_byte(b'/'); |
570 } | 570 } |
571 Ok(p) | 571 p |
572 })?, | 572 })?, |
573 path: path.to_owned(), | 573 path: path.to_owned(), |
574 root: new_root.to_owned(), | 574 root: new_root.to_owned(), |
575 included_patterns: Vec::new(), | 575 included_patterns: Vec::new(), |
576 }) | 576 }) |