~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 04:08:15 UTC
  • Revision ID: mbp@sourcefrog.net-20050309040815-13242001617e4a06
import from baz patch-364

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
 
56
60
    def has_filename(self, filename):
57
61
        """True if the tree has given filename."""
58
62
        raise NotImplementedError()
145
149
        return os.path.exists(self._rel(filename))
146
150
 
147
151
    def get_file(self, file_id):
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')
 
152
        return file(self._get_store_filename(file_id), 'rb')
152
153
 
153
154
    def _get_store_filename(self, file_id):
154
155
        return self._rel(self.id2path(file_id))
256
257
                yield fpath
257
258
 
258
259
 
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
 
 
268
260
    def is_ignored(self, filename):
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."""
 
261
        """Check whether the filename matches an ignore pattern."""
273
262
        ## TODO: Take them from a file, not hardcoded
274
263
        ## TODO: Use extended zsh-style globs maybe?
275
264
        ## TODO: Use '**' to match directories?
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
 
265
        ## TODO: Patterns without / should match in subdirectories?
 
266
        for i in bzrlib.DEFAULT_IGNORE:
 
267
            if fnmatch.fnmatchcase(filename, i):
 
268
                return True
283
269
        return False
284
270
        
285
271