Mercurial > hg
diff 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 |
line wrap: on
line diff
--- a/rust/hg-core/src/filepatterns.rs Wed Aug 02 10:16:33 2023 -0400 +++ b/rust/hg-core/src/filepatterns.rs Wed Aug 02 10:46:47 2023 -0400 @@ -366,6 +366,7 @@ pattern: &[u8], source: &Path, default: PatternSyntax, + normalize: bool, ) -> IgnorePattern { let mut pattern_bytes: &[u8] = pattern; let mut syntax = default; @@ -378,7 +379,19 @@ } } - let pattern = pattern_bytes.to_vec(); + let pattern = match syntax { + PatternSyntax::RootGlob + | PatternSyntax::Path + | PatternSyntax::Glob + | PatternSyntax::RelGlob + | PatternSyntax::RelPath + | PatternSyntax::RootFiles + if normalize => + { + normalize_path_bytes(pattern_bytes) + } + _ => pattern_bytes.to_vec(), + }; IgnorePattern { syntax, @@ -438,6 +451,7 @@ line, file_path, current_syntax.clone(), + false, ); inputs.push(if relativize { pattern.to_relative() @@ -449,6 +463,35 @@ Ok((inputs, warnings)) } +pub fn parse_pattern_args( + patterns: Vec<Vec<u8>>, + cwd: &Path, + root: &Path, +) -> Result<Vec<IgnorePattern>, HgPathError> { + let mut ignore_patterns: Vec<IgnorePattern> = Vec::new(); + for pattern in patterns { + let pattern = parse_one_pattern( + &pattern, + Path::new("<args>"), + PatternSyntax::RelPath, + true, + ); + match pattern.syntax { + PatternSyntax::RelGlob | PatternSyntax::RelPath => { + let name = get_path_from_bytes(&pattern.pattern); + let canon = canonical_path(root, cwd, name)?; + ignore_patterns.push(IgnorePattern { + syntax: pattern.syntax, + pattern: get_bytes_from_path(canon), + source: pattern.source, + }) + } + _ => ignore_patterns.push(pattern.to_owned()), + }; + } + Ok(ignore_patterns) +} + pub fn read_pattern_file( file_path: &Path, warn: bool,