~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Martin Pool
  • Date: 2005-06-29 04:11:40 UTC
  • Revision ID: mbp@sourcefrog.net-20050629041140-6b17e65a23ffdf47
Merge John's log patch:

implements bzr log --forward --verbose
optimizes so that only logs to be printed are read (rather than reading
all and filtering out unwanted).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tree classes, representing directory at point in time.
18
18
"""
19
19
 
20
 
import os
 
20
from osutils import pumpfile, appendpath, fingerprint_file
21
21
 
22
 
import bzrlib
23
22
from bzrlib.trace import mutter, note
24
23
from bzrlib.errors import BzrError
25
 
from bzrlib.inventory import Inventory
26
 
from bzrlib.osutils import pumpfile, appendpath, fingerprint_file
27
24
 
 
25
import bzrlib
28
26
 
29
27
exporters = {}
30
28
 
67
65
 
68
66
    def _get_inventory(self):
69
67
        return self._inventory
70
 
    
71
 
    def get_file_by_path(self, path):
72
 
        return self.get_file(self._inventory.path2id(path))
73
68
 
74
69
    inventory = property(_get_inventory,
75
70
                         doc="Inventory of this Tree")
98
93
        pumpfile(self.get_file(fileid), sys.stdout)
99
94
        
100
95
        
101
 
    def export(self, dest, format='dir', root=None):
 
96
    def export(self, dest, format='dir'):
102
97
        """Export this tree."""
103
98
        try:
104
99
            exporter = exporters[format]
105
100
        except KeyError:
106
 
            from bzrlib.errors import BzrCommandError
107
101
            raise BzrCommandError("export format %r not supported" % format)
108
 
        exporter(self, dest, root)
 
102
        exporter(self, dest)
109
103
 
110
104
 
111
105
 
148
142
 
149
143
class EmptyTree(Tree):
150
144
    def __init__(self):
 
145
        from bzrlib.inventory import Inventory
151
146
        self._inventory = Inventory()
152
147
 
153
148
    def has_filename(self, filename):
228
223
######################################################################
229
224
# export
230
225
 
231
 
def dir_exporter(tree, dest, root):
 
226
def dir_exporter(tree, dest):
232
227
    """Export this tree to a new directory.
233
228
 
234
229
    `dest` should not exist, and will be created holding the
261
256
except ImportError:
262
257
    pass
263
258
else:
264
 
    def get_root_name(dest):
265
 
        """Get just the root name for a tarball.
266
 
 
267
 
        >>> get_root_name('mytar.tar')
268
 
        'mytar'
269
 
        >>> get_root_name('mytar.tar.bz2')
270
 
        'mytar'
271
 
        >>> get_root_name('tar.tar.tar.tgz')
272
 
        'tar.tar.tar'
273
 
        >>> get_root_name('bzr-0.0.5.tar.gz')
274
 
        'bzr-0.0.5'
275
 
        >>> get_root_name('a/long/path/mytar.tgz')
276
 
        'mytar'
277
 
        >>> get_root_name('../parent/../dir/other.tbz2')
278
 
        'other'
279
 
        """
280
 
        endings = ['.tar', '.tar.gz', '.tgz', '.tar.bz2', '.tbz2']
281
 
        dest = os.path.basename(dest)
282
 
        for end in endings:
283
 
            if dest.endswith(end):
284
 
                return dest[:-len(end)]
285
 
 
286
 
    def tar_exporter(tree, dest, root, compression=None):
 
259
    def tar_exporter(tree, dest, compression=None):
287
260
        """Export this tree to a new tar file.
288
261
 
289
262
        `dest` will be created holding the contents of this tree; if it
292
265
        from time import time
293
266
        now = time()
294
267
        compression = str(compression or '')
295
 
        if root is None:
296
 
            root = get_root_name(dest)
297
268
        try:
298
269
            ball = tarfile.open(dest, 'w:' + compression)
299
270
        except tarfile.CompressionError, e:
302
273
        inv = tree.inventory
303
274
        for dp, ie in inv.iter_entries():
304
275
            mutter("  export {%s} kind %s to %s" % (ie.file_id, ie.kind, dest))
305
 
            item = tarfile.TarInfo(os.path.join(root, dp))
 
276
            item = tarfile.TarInfo(dp)
306
277
            # TODO: would be cool to actually set it to the timestamp of the
307
278
            # revision it was last changed
308
279
            item.mtime = now
325
296
        ball.close()
326
297
    exporters['tar'] = tar_exporter
327
298
 
328
 
    def tgz_exporter(tree, dest, root):
329
 
        tar_exporter(tree, dest, root, compression='gz')
 
299
    def tgz_exporter(tree, dest):
 
300
        tar_exporter(tree, dest, compression='gz')
330
301
    exporters['tgz'] = tgz_exporter
331
302
 
332
 
    def tbz_exporter(tree, dest, root):
333
 
        tar_exporter(tree, dest, root, compression='bz2')
 
303
    def tbz_exporter(tree, dest):
 
304
        tar_exporter(tree, dest, compression='bz2')
334
305
    exporters['tbz2'] = tbz_exporter
335
306
 
336
307