[PATCH] ignore: add case-insensitive globs support

Martin Geisler mg at aragost.com
Thu Mar 31 02:58:41 CDT 2011


Eduard-Cristian Stefan <alexandrul.ct at gmail.com> writes:

(I'm sending it back on the mailinglist, please keep the list in Cc.)

> On 2011-03-30 17:06, Martin Geisler wrote:
>>> -def _globre(pat):
>>> +def _globre(pat, ci=False):
>> 
>> The argument name could be better, I would never have guessed that
>> 'ci' means 'case-insensitive' if I hadn't seen this patch.
>> 
>>>      "convert a glob pattern into a regexp"
>>>      i, n = 0, len(pat)
>>> -    res = ''
>>> +    res = ['', '(?i)'][ci]
>> 
>> Please use a real if-statement here -- it took me three attempts to
>> figure out what was going on here :)
>
> That is a python emulation of the C#'s conditional operator (condition
> ? first_expression : second_expression), but you are right, it's not
> very obvious.

The idiomatic way to do this in Python 2.4 is

  res = ci and '(?i)' or ''

and in Python 2.5 and later you can do

  res = '(?i)' if ci else ''

The conditional expression syntax helps in case the thing you want to
assign when the condition is true is itself false -- then the short
circuiting behavior of 'and' and 'or' fails to give the wanted result.

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://aragost.com/en/services/mercurial/blog/


More information about the Mercurial-devel mailing list