~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: mbp at sourcefrog
  • Date: 2005-04-01 04:04:04 UTC
  • Revision ID: mbp@sourcefrog.net-20050401040404-c5cd90f539e27f91
bzr commit --help now works

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
        fp = fingerprint_file(f)
79
79
        f.seek(0)
80
80
        
81
 
        if ie.text_size != None:
 
81
        if ie.text_size is not None:
82
82
            if ie.text_size != fp['size']:
83
83
                bailout("mismatched size for file %r in %r" % (ie.file_id, self._store),
84
84
                        ["inventory expects %d bytes" % ie.text_size,
92
92
                     "store is probably damaged/corrupt"])
93
93
 
94
94
 
95
 
    def print_file(self, fileid):
96
 
        """Print file with id `fileid` to stdout."""
97
 
        import sys
98
 
        pumpfile(self.get_file(fileid), sys.stdout)
99
 
        
100
 
        
101
 
    def export(self, dest):        
 
95
    def export(self, dest):
102
96
        """Export this tree to a new directory.
103
97
 
104
98
        `dest` should not exist, and will be created holding the
105
99
        contents of this tree.
106
100
 
107
 
        TODO: To handle subdirectories we need to create the
 
101
        :todo: To handle subdirectories we need to create the
108
102
               directories first.
109
103
 
110
104
        :note: If the export fails, the destination directory will be
121
115
            elif kind == 'file':
122
116
                pumpfile(self.get_file(ie.file_id), file(fullpath, 'wb'))
123
117
            else:
124
 
                bailout("don't know how to export {%s} of kind %r" % (fid, kind))
 
118
                bailout("don't know how to export {%s} of kind %r", fid, kind)
125
119
            mutter("  export {%s} kind %s to %s" % (ie.file_id, kind, fullpath))
126
120
 
127
121
 
157
151
        return file(self.abspath(filename), 'rb')
158
152
 
159
153
    def _get_store_filename(self, file_id):
160
 
        ## XXX: badly named; this isn't in the store at all
161
154
        return self.abspath(self.id2path(file_id))
162
155
 
163
156
    def has_id(self, file_id):
195
188
        """
196
189
        inv = self.inventory
197
190
 
198
 
        def descend(from_dir_relpath, from_dir_id, dp):
 
191
        def descend(from_dir, from_dir_id, dp):
199
192
            ls = os.listdir(dp)
200
193
            ls.sort()
201
194
            for f in ls:
206
199
                    continue
207
200
 
208
201
                # path within tree
209
 
                fp = appendpath(from_dir_relpath, f)
 
202
                fp = appendpath(from_dir, f)
210
203
 
211
204
                # absolute path
212
205
                fap = appendpath(dp, f)
238
231
                for ff in descend(fp, f_ie.file_id, fap):
239
232
                    yield ff
240
233
 
241
 
        for f in descend('', inv.root.file_id, self.basedir):
 
234
        for f in descend('', None, self.basedir):
242
235
            yield f
243
236
            
244
237
 
304
297
 
305
298
 
306
299
    def is_ignored(self, filename):
307
 
        r"""Check whether the filename matches an ignore pattern.
 
300
        """Check whether the filename matches an ignore pattern.
308
301
 
309
 
        Patterns containing '/' or '\' need to match the whole path;
310
 
        others match against only the last component.
 
302
        Patterns containing '/' need to match the whole path; others
 
303
        match against only the last component.
311
304
 
312
305
        If the file is ignored, returns the pattern which caused it to
313
306
        be ignored, otherwise None.  So this can simply be used as a
314
307
        boolean if desired."""
315
308
 
316
 
        # TODO: Use '**' to match directories, and other extended
317
 
        # globbing stuff from cvs/rsync.
318
 
 
319
 
        # XXX: fnmatch is actually not quite what we want: it's only
320
 
        # approximately the same as real Unix fnmatch, and doesn't
321
 
        # treat dotfiles correctly and allows * to match /.
322
 
        # Eventually it should be replaced with something more
323
 
        # accurate.
 
309
        ## TODO: Use '**' to match directories, and other extended globbing stuff from cvs/rsync.
324
310
        
325
311
        for pat in self.get_ignore_list():
326
 
            if '/' in pat or '\\' in pat:
327
 
                
328
 
                # as a special case, you can put ./ at the start of a
329
 
                # pattern; this is good to match in the top-level
330
 
                # only;
331
 
                
332
 
                if (pat[:2] == './') or (pat[:2] == '.\\'):
 
312
            if '/' in pat:
 
313
                # as a special case, you can put ./ at the start of a pattern;
 
314
                # this is good to match in the top-level only;
 
315
                if pat[:2] == './':
333
316
                    newpat = pat[2:]
334
317
                else:
335
318
                    newpat = pat
349
332
 
350
333
    File text can be retrieved from the text store.
351
334
 
352
 
    TODO: Some kind of `__repr__` method, but a good one
 
335
    :todo: Some kind of `__repr__` method, but a good one
353
336
           probably means knowing the branch and revision number,
354
337
           or at least passing a description to the constructor.
355
338
    """
449
432
 
450
433
    
451
434
 
452
 
def find_renames(old_inv, new_inv):
453
 
    for file_id in old_inv:
454
 
        if file_id not in new_inv:
455
 
            continue
456
 
        old_name = old_inv.id2path(file_id)
457
 
        new_name = new_inv.id2path(file_id)
458
 
        if old_name != new_name:
459
 
            yield (old_name, new_name)
460