Mercurial > hg
comparison rust/hg-core/src/filepatterns.rs @ 50866:c112cc9effdc
rhg: support "status FILE"
This change adds a new [file] argument to rhg status, parses them as
patterns, canonicalizes the paths, and constructs a new PatternMatcher
to intersect with the existing matcher being passed to the status
implementation.
We also make filepatterns a public module so we can access the
pattern-parsing functionality we need from commands/status.rs.
author | Spencer Baugh <sbaugh@janestreet.com> |
---|---|
date | Wed, 02 Aug 2023 10:46:47 -0400 |
parents | 090658724abf |
children | 532e74ad3ff6 |
comparison
equal
deleted
inserted
replaced
50865:f874342fa568 | 50866:c112cc9effdc |
---|---|
364 | 364 |
365 pub fn parse_one_pattern( | 365 pub fn parse_one_pattern( |
366 pattern: &[u8], | 366 pattern: &[u8], |
367 source: &Path, | 367 source: &Path, |
368 default: PatternSyntax, | 368 default: PatternSyntax, |
369 normalize: bool, | |
369 ) -> IgnorePattern { | 370 ) -> IgnorePattern { |
370 let mut pattern_bytes: &[u8] = pattern; | 371 let mut pattern_bytes: &[u8] = pattern; |
371 let mut syntax = default; | 372 let mut syntax = default; |
372 | 373 |
373 for (s, val) in SYNTAXES.iter() { | 374 for (s, val) in SYNTAXES.iter() { |
376 pattern_bytes = rest; | 377 pattern_bytes = rest; |
377 break; | 378 break; |
378 } | 379 } |
379 } | 380 } |
380 | 381 |
381 let pattern = pattern_bytes.to_vec(); | 382 let pattern = match syntax { |
383 PatternSyntax::RootGlob | |
384 | PatternSyntax::Path | |
385 | PatternSyntax::Glob | |
386 | PatternSyntax::RelGlob | |
387 | PatternSyntax::RelPath | |
388 | PatternSyntax::RootFiles | |
389 if normalize => | |
390 { | |
391 normalize_path_bytes(pattern_bytes) | |
392 } | |
393 _ => pattern_bytes.to_vec(), | |
394 }; | |
382 | 395 |
383 IgnorePattern { | 396 IgnorePattern { |
384 syntax, | 397 syntax, |
385 pattern, | 398 pattern, |
386 source: source.to_owned(), | 399 source: source.to_owned(), |
436 } else { | 449 } else { |
437 let pattern = parse_one_pattern( | 450 let pattern = parse_one_pattern( |
438 line, | 451 line, |
439 file_path, | 452 file_path, |
440 current_syntax.clone(), | 453 current_syntax.clone(), |
454 false, | |
441 ); | 455 ); |
442 inputs.push(if relativize { | 456 inputs.push(if relativize { |
443 pattern.to_relative() | 457 pattern.to_relative() |
444 } else { | 458 } else { |
445 pattern | 459 pattern |
446 }) | 460 }) |
447 } | 461 } |
448 } | 462 } |
449 Ok((inputs, warnings)) | 463 Ok((inputs, warnings)) |
464 } | |
465 | |
466 pub fn parse_pattern_args( | |
467 patterns: Vec<Vec<u8>>, | |
468 cwd: &Path, | |
469 root: &Path, | |
470 ) -> Result<Vec<IgnorePattern>, HgPathError> { | |
471 let mut ignore_patterns: Vec<IgnorePattern> = Vec::new(); | |
472 for pattern in patterns { | |
473 let pattern = parse_one_pattern( | |
474 &pattern, | |
475 Path::new("<args>"), | |
476 PatternSyntax::RelPath, | |
477 true, | |
478 ); | |
479 match pattern.syntax { | |
480 PatternSyntax::RelGlob | PatternSyntax::RelPath => { | |
481 let name = get_path_from_bytes(&pattern.pattern); | |
482 let canon = canonical_path(root, cwd, name)?; | |
483 ignore_patterns.push(IgnorePattern { | |
484 syntax: pattern.syntax, | |
485 pattern: get_bytes_from_path(canon), | |
486 source: pattern.source, | |
487 }) | |
488 } | |
489 _ => ignore_patterns.push(pattern.to_owned()), | |
490 }; | |
491 } | |
492 Ok(ignore_patterns) | |
450 } | 493 } |
451 | 494 |
452 pub fn read_pattern_file( | 495 pub fn read_pattern_file( |
453 file_path: &Path, | 496 file_path: &Path, |
454 warn: bool, | 497 warn: bool, |