~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-09 07:00:48 UTC
  • Revision ID: mbp@sourcefrog.net-20050309070048-a0f0a23015e90267
new --timezone option for bzr log

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    trees or versioned trees.
54
54
    """
55
55
    
56
 
    def get_file(self, file_id):
57
 
        """Return an open file-like object for given file id."""
58
 
        raise NotImplementedError()
59
 
 
60
56
    def has_filename(self, filename):
61
57
        """True if the tree has given filename."""
62
58
        raise NotImplementedError()
149
145
        return os.path.exists(self._rel(filename))
150
146
 
151
147
    def get_file(self, file_id):
152
 
        return file(self._get_store_filename(file_id), 'rb')
 
148
        return self.get_file_byname(self.id2path(file_id))
 
149
 
 
150
    def get_file_byname(self, filename):
 
151
        return file(self._rel(filename), 'rb')
153
152
 
154
153
    def _get_store_filename(self, file_id):
155
154
        return self._rel(self.id2path(file_id))
257
256
                yield fpath
258
257
 
259
258
 
 
259
    def get_ignore_list(self):
 
260
        """Return list of ignore patterns."""
 
261
        if self.has_filename(bzrlib.IGNORE_FILENAME):
 
262
            f = self.get_file_byname(bzrlib.IGNORE_FILENAME)
 
263
            return [line.rstrip("\n\r") for line in f.readlines()]
 
264
        else:
 
265
            return bzrlib.DEFAULT_IGNORE
 
266
 
 
267
 
260
268
    def is_ignored(self, filename):
261
 
        """Check whether the filename matches an ignore pattern."""
 
269
        """Check whether the filename matches an ignore pattern.
 
270
 
 
271
        Patterns containing '/' need to match the whole path; others
 
272
        match against only the last component."""
262
273
        ## TODO: Take them from a file, not hardcoded
263
274
        ## TODO: Use extended zsh-style globs maybe?
264
275
        ## TODO: Use '**' to match directories?
265
 
        ## TODO: Patterns without / should match in subdirectories?
266
 
        for i in bzrlib.DEFAULT_IGNORE:
267
 
            if fnmatch.fnmatchcase(filename, i):
268
 
                return True
 
276
        for pat in self.get_ignore_list():
 
277
            if '/' in pat:
 
278
                if fnmatch.fnmatchcase(filename, pat):
 
279
                    return True
 
280
            else:
 
281
                if fnmatch.fnmatchcase(splitpath(filename)[-1], pat):
 
282
                    return True
269
283
        return False
270
284
        
271
285