~jameinel/bzr/ignore-exception

« back to all changes in this revision

Viewing changes to bzrlib/globbing.py

  • Committer: John Whitley
  • Date: 2010-01-05 19:29:07 UTC
  • Revision ID: whitley@bangpath.org-20100105192907-hy326yzkt7ywdao3
A trial implementation of '!!' syntax for double-negative ignore exclusions.
These act like regular ignores, but take precedence over the single '!' 
exclusions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
226
226
    
227
227
    def __init__(self,patterns):
228
228
        ignores = []
229
 
        excludes = []
 
229
        excludes = [[], []]
230
230
        for p in patterns:
231
 
            if p.startswith(u'!'):
232
 
                excludes.append(p[1:])
 
231
            if p.startswith(u'!!'):
 
232
                excludes[1].append(p[2:])
 
233
            elif p.startswith(u'!'):
 
234
                excludes[0].append(p[1:])
233
235
            else:
234
236
                ignores.append(p)
235
237
        self._ignores = Globster(ignores)
236
 
        self._excludes = Globster(excludes)
 
238
        self._excludes = [Globster(i) for i in excludes]
237
239
        
238
240
    def match(self, filename):
239
241
        """Searches for a pattern that matches the given filename.
240
242
 
241
243
        :return A matching pattern or None if there is no matching pattern.
242
244
        """
243
 
        if self._excludes.match(filename):
 
245
        double_neg = self._excludes[1].match(filename)
 
246
        if double_neg:
 
247
            return "!!%s" % double_neg
 
248
 
 
249
        if self._excludes[0].match(filename):
244
250
            return None
245
251
        else:
246
252
            return self._ignores.match(filename)