diff --git a/mercurial/match.py b/mercurial/match.py --- a/mercurial/match.py +++ b/mercurial/match.py @@ -1223,7 +1223,12 @@ def _regex(kind, pat, globsuffix): # Anything after the pattern must be a non-directory. return escaped + '[^/]+$' if kind == 'relglob': - return '(?:|.*/)' + _globre(pat) + globsuffix + globre = _globre(pat) + if globre.startswith('[^/]*'): + # When pat has the form *XYZ (common), make the returned regex more + # legible by returning the regex for **XYZ instead of **/*XYZ. + return '.*' + globre[len('[^/]*'):] + globsuffix + return '(?:|.*/)' + globre + globsuffix if kind == 'relre': if pat.startswith('^'): return pat diff --git a/rust/hg-core/src/filepatterns.rs b/rust/hg-core/src/filepatterns.rs --- a/rust/hg-core/src/filepatterns.rs +++ b/rust/hg-core/src/filepatterns.rs @@ -185,14 +185,22 @@ fn _build_single_regex( res.extend(b"[^/]+$"); res } + PatternSyntax::RelGlob => { + let mut res: Vec = vec![]; + let glob_re = glob_to_re(pattern); + if let Some(rest) = glob_re.drop_prefix(b"[^/]*") { + res.extend(b".*"); + res.extend(rest); + } else { + res.extend(b"(?:|.*/)"); + res.extend(glob_re); + } + res.extend(globsuffix.iter()); + res + } PatternSyntax::Glob - | PatternSyntax::RelGlob | PatternSyntax::RootGlob => { let mut res: Vec = vec![]; - if syntax == PatternSyntax::RelGlob { - res.extend(b"(?:|.*/)"); - } - res.extend(glob_to_re(pattern)); res.extend(globsuffix.iter()); res diff --git a/tests/test-hgignore.t b/tests/test-hgignore.t --- a/tests/test-hgignore.t +++ b/tests/test-hgignore.t @@ -177,7 +177,7 @@ Test relative ignore path (issue4473): ? a.c ? syntax $ hg debugignore - + $ cd .. $ echo > .hg/testhgignorerel @@ -224,7 +224,7 @@ Test relative ignore path (issue4473): A b.o $ hg debugignore - + $ hg debugignore b.o b.o is ignored diff --git a/tests/test-walk.t b/tests/test-walk.t --- a/tests/test-walk.t +++ b/tests/test-walk.t @@ -100,7 +100,7 @@ f mammals/skunk skunk $ hg debugwalk -v -I 'relglob:*k' * matcher: - + f beans/black ../beans/black f fenugreek ../fenugreek f mammals/skunk skunk @@ -108,7 +108,7 @@ * matcher: , - m2=> + m2=> f mammals/skunk skunk $ hg debugwalk -v -I 're:.*k$' * matcher: