/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/globbing.py

  • Committer: John Whitley
  • Date: 2010-01-11 16:44:02 UTC
  • mto: This revision was merged to the branch mainline in revision 4981.
  • Revision ID: whitley@bangpath.org-20100111164402-9luag9p9ahpy4kmz
Terminology change: exclusion => exception.
Tweaked presentation of new logic in ExceptionGlobster

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
                return patterns[match.lastindex -1]
216
216
        return None
217
217
 
218
 
class ExcludingGlobster(object):
219
 
    """A Globster that supports exclusion patterns.
 
218
class ExceptionGlobster(object):
 
219
    """A Globster that supports exception patterns.
220
220
    
221
 
    These are ignore patterns prefixed with '!'.  Exclusion
222
 
    patterns take precedence over regular patterns and negate the
223
 
    normal matching logic, causing a matching filename to return
224
 
    None from the match() function.
 
221
    Exceptions are ignore patterns prefixed with '!'.  Exception
 
222
    patterns take precedence over regular patterns and cause a 
 
223
    matching filename to return None from the match() function.  
 
224
    Patterns using a '!!' prefix are highest precedence, and act 
 
225
    as regular ignores. '!!' patterns are useful to establish ignores
 
226
    that apply under paths specified by '!' exception patterns.
225
227
    """
226
228
    
227
229
    def __init__(self,patterns):
228
 
        ignores = []
229
 
        excludes = [[], []]
 
230
        ignores = [[], [], []]
230
231
        for p in patterns:
231
232
            if p.startswith(u'!!'):
232
 
                excludes[1].append(p[2:])
 
233
                ignores[2].append(p[2:])
233
234
            elif p.startswith(u'!'):
234
 
                excludes[0].append(p[1:])
 
235
                ignores[1].append(p[1:])
235
236
            else:
236
 
                ignores.append(p)
237
 
        self._ignores = Globster(ignores)
238
 
        self._excludes = [Globster(i) for i in excludes]
 
237
                ignores[0].append(p)
 
238
        self._ignores = [Globster(i) for i in ignores]
239
239
        
240
240
    def match(self, filename):
241
241
        """Searches for a pattern that matches the given filename.
242
242
 
243
243
        :return A matching pattern or None if there is no matching pattern.
244
244
        """
245
 
        double_neg = self._excludes[1].match(filename)
 
245
        double_neg = self._ignores[2].match(filename)
246
246
        if double_neg:
247
247
            return "!!%s" % double_neg
248
 
 
249
 
        if self._excludes[0].match(filename):
 
248
        elif self._ignores[1].match(filename):
250
249
            return None
251
250
        else:
252
 
            return self._ignores.match(filename)
 
251
            return self._ignores[0].match(filename)
253
252
 
254
253
class _OrderedGlobster(Globster):
255
254
    """A Globster that keeps pattern order."""