/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-05 19:29:07 UTC
  • mto: This revision was merged to the branch mainline in revision 4981.
  • 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:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2008 Canonical Ltd
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
215
215
                return patterns[match.lastindex -1]
216
216
        return None
217
217
 
218
 
class ExceptionGlobster(object):
219
 
    """A Globster that supports exception patterns.
 
218
class ExcludingGlobster(object):
 
219
    """A Globster that supports exclusion patterns.
220
220
    
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.
 
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.
227
225
    """
228
226
    
229
227
    def __init__(self,patterns):
230
 
        ignores = [[], [], []]
 
228
        ignores = []
 
229
        excludes = [[], []]
231
230
        for p in patterns:
232
231
            if p.startswith(u'!!'):
233
 
                ignores[2].append(p[2:])
 
232
                excludes[1].append(p[2:])
234
233
            elif p.startswith(u'!'):
235
 
                ignores[1].append(p[1:])
 
234
                excludes[0].append(p[1:])
236
235
            else:
237
 
                ignores[0].append(p)
238
 
        self._ignores = [Globster(i) for i in ignores]
 
236
                ignores.append(p)
 
237
        self._ignores = Globster(ignores)
 
238
        self._excludes = [Globster(i) for i in excludes]
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._ignores[2].match(filename)
 
245
        double_neg = self._excludes[1].match(filename)
246
246
        if double_neg:
247
247
            return "!!%s" % double_neg
248
 
        elif self._ignores[1].match(filename):
 
248
 
 
249
        if self._excludes[0].match(filename):
249
250
            return None
250
251
        else:
251
 
            return self._ignores[0].match(filename)
 
252
            return self._ignores.match(filename)
252
253
 
253
254
class _OrderedGlobster(Globster):
254
255
    """A Globster that keeps pattern order."""