~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/globbing.py

  • Committer: Ian Clatworthy
  • Date: 2008-05-06 02:57:11 UTC
  • mto: (3515.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3516.
  • Revision ID: ian.clatworthy@canonical.com-20080506025711-59ywlehptmne1xos
simplify the custom Globster to only care about ordering

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 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
214
214
            if match:
215
215
                return patterns[match.lastindex -1]
216
216
        return None
217
 
        
 
217
 
 
218
 
 
219
class _OrderedGlobster(Globster):
 
220
    """A Globster that keeps pattern order."""
 
221
 
 
222
    def __init__(self, patterns):
 
223
        """Constructor.
 
224
 
 
225
        :param patterns: sequence of glob patterns
 
226
        """
 
227
        # Note: This could be smarter by running like sequences together
 
228
        self._regex_patterns = []
 
229
        for pat in patterns:
 
230
            pat = normalize_pattern(pat)
 
231
            if pat.startswith(u'RE:') or u'/' in pat:
 
232
                self._add_patterns([pat], _sub_fullpath) 
 
233
            elif pat.startswith(u'*.'):
 
234
                self._add_patterns([pat], _sub_extension,
 
235
                    prefix=r'(?:.*/)?(?!.*/)(?:.*\.)')
 
236
            else:
 
237
                self._add_patterns([pat], _sub_basename, 
 
238
                    prefix=r'(?:.*/)?(?!.*/)')
 
239
 
218
240
 
219
241
def normalize_pattern(pattern):
220
242
    """Converts backslashes in path patterns to forward slashes.