/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Martin Pool
  • Date: 2005-06-28 03:02:31 UTC
  • Revision ID: mbp@sourcefrog.net-20050628030231-d311e4ebcd467ef4
Merge John's import-speedup branch:

                                                                                         
  777 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:32 -0500
      revision-id: john@arbash-meinel.com-20050627032031-e82a50db3863b18e
      bzr selftest was not using the correct bzr

  776 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:22 -0500
      revision-id: john@arbash-meinel.com-20050627032021-c9f21fde989ddaee
      Add was using an old mutter

  775 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:02:33 -0500
      revision-id: john@arbash-meinel.com-20050627030233-9165cfe98fc63298
      Cleaned up to be less different

  774 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:54:53 -0500
      revision-id: john@arbash-meinel.com-20050627025452-4260d0e744edef43
      Allow BZR_PLUGIN_PATH='' to negate plugin loading.

  773 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:49:34 -0500
      revision-id: john@arbash-meinel.com-20050627024933-b7158f67b7b9eae5
      Finished the previous cleanup (allowing load_plugins to be called twice)

  772 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:45:08 -0500
      revision-id: john@arbash-meinel.com-20050627024508-723b1df510d196fc
      Work on making the tests pass. versioning.py is calling run_cmd directly, but plugins have been loaded.

  771 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:32:29 -0500
      revision-id: john@arbash-meinel.com-20050627023228-79972744d7c53e15
      Got it down a little bit more by removing import of tree and inventory.

  770 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:26:05 -0500
      revision-id: john@arbash-meinel.com-20050627022604-350b9773ef622f95
      Reducing the number of import from bzrlib/__init__.py and bzrlib/branch.py

  769 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:32:25 -0500
      revision-id: john@arbash-meinel.com-20050627013225-32dd044f10d23948
      Updated revision.py and xml.py to include SubElement.

  768 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:56 -0500
      revision-id: john@arbash-meinel.com-20050627010356-ee66919e1c377faf
      Minor typo

  767 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:13 -0500
      revision-id: john@arbash-meinel.com-20050627010312-40d024007eb85051
      Caching the import

  766 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:51:47 -0500
      revision-id: john@arbash-meinel.com-20050627005147-5281c99e48ed1834
      Created wrapper functions for lazy import of ElementTree

  765 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:46:37 -0500
      revision-id: john@arbash-meinel.com-20050627004636-bf432902004a94c5
      Removed all of the test imports of cElementTree

  764 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:43:59 -0500
      revision-id: john@arbash-meinel.com-20050627004358-d137fbe9570dd71b
      Trying to make bzr startup faster.

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