On Wed, Jan 6, 2016 at 8:08 AM, Mostyn Bramley-Moore <mostynb@xxxxxxxxx> wrote: > On 01/04/2016 06:46 PM, Junio C Hamano wrote: >>>> Magic pattern annotation like we do for pathspecs Duy raised may not >>>> be a bad idea, either, and would probably be easier to teach people. >>>> Just like in Perl "(?i)$any_pattern" is a way to introduce the case >>>> insensitive match with $any_pattern, we may be able to pick an >>>> extensible magic syntax and decorate the pattern you would specify >>>> for matching refnames to tell Git what kind of pattern it is, e.g. >>>> >>>> $ git mgrep -P -e foo --refs '/?glob/release_*' >>>> >>>> I am not suggesting that we must use /?<pattern type name>/ prefix >>>> as the "extensible magic syntax" here--I am just illustrating what >>>> I mean by "extensible magic syntax". >>> >>> >>> I hadn't seen the pathspec magic patterns before- interesting. We >>> could possibly share syntax with pathspecs, ie >>> :(?pattern-options...)pattern >> >> >> Even though we have DWIM between revisions and paths on the command >> line when the user omits "--" for disambiguation, I do not think we >> look at the shape of the string to DWIM/decide that it is a pattern, >> so as long as the magic syntax cannot be a valid pattern to match >> against refs right now (and your ":(?...)" qualifies as such, as a >> refname would not contain a component that begins with a colon), it >> would be possible to introduce it as the magic syntax for matching >> refs. >> >> Or did you mean to use this syntax also for patterns that match >> strings in contents, e.g. >> >> $ git grep -e ':(?perl-regexp)...' > > > I think it would be nice to support this syntax in every command that does > pattern matching. > > Corner case: what if we want to search for ":(?perl-regexp)", eg in git's > own source? I suppose this would do: > git grep -e ":(?fixed-strings):(?perl-regexp)" We can also override it with command line options. If you define --perl-regexp as "if no regex syntax is specified in the pattern, pcre is used", then you can have something like --force-perl-regexp that says "all patterns are in pcre, there's no magic whatsoever to choose a different regex syntax". Though I think --perl-regexp should play the role of --force-perl-regexp so you don't surprise current scripts, and have a new option --default-syntax=<type> instead. -- Duy -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html