~bzr/ubuntu/lucid/bzr/beta-ppa

« back to all changes in this revision

Viewing changes to bzrlib/export/__init__.py

  • Committer: Martin Pool
  • Date: 2010-08-18 04:26:39 UTC
  • mfrom: (129.1.8 packaging-karmic)
  • Revision ID: mbp@sourcefrog.net-20100818042639-mjoxtngyjwiu05fo
* PPA rebuild for lucid.
* PPA rebuild for karmic.
* PPA rebuild onto jaunty.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
Such as non-controlled directories, tarfiles, zipfiles, etc.
20
20
"""
21
21
 
22
 
from bzrlib.trace import mutter
23
22
import os
24
23
import bzrlib.errors as errors
25
24
 
55
54
 
56
55
    When requesting a specific type of export, load the respective path.
57
56
    """
58
 
    def _loader(tree, dest, root, subdir, filtered):
 
57
    def _loader(tree, dest, root, subdir, filtered, per_file_timestamps):
59
58
        mod = __import__(module, globals(), locals(), [funcname])
60
59
        func = getattr(mod, funcname)
61
 
        return func(tree, dest, root, subdir, filtered=filtered)
 
60
        return func(tree, dest, root, subdir, filtered=filtered,
 
61
                    per_file_timestamps=per_file_timestamps)
62
62
    register_exporter(scheme, extensions, _loader)
63
63
 
64
64
 
65
 
def export(tree, dest, format=None, root=None, subdir=None, filtered=False):
 
65
def export(tree, dest, format=None, root=None, subdir=None, filtered=False,
 
66
           per_file_timestamps=False):
66
67
    """Export the given Tree to the specific destination.
67
68
 
68
69
    :param tree: A Tree (such as RevisionTree) to export
81
82
        a directory to start exporting from.
82
83
    :param filtered: If True, content filtering is applied to the
83
84
                     files exported.
 
85
    :param per_file_timestamps: Whether to use the timestamp stored in the 
 
86
        tree rather than now(). This will do a revision lookup 
 
87
        for every file so will be significantly slower.
84
88
    """
85
89
    global _exporters, _exporter_extensions
86
90
 
99
103
        raise errors.NoSuchExportFormat(format)
100
104
    tree.lock_read()
101
105
    try:
102
 
        return _exporters[format](tree, dest, root, subdir, filtered=filtered)
 
106
        return _exporters[format](tree, dest, root, subdir, filtered=filtered,
 
107
                                  per_file_timestamps=per_file_timestamps)
103
108
    finally:
104
109
        tree.unlock()
105
110
 
138
143
    """Iter the entries for tree suitable for exporting.
139
144
 
140
145
    :param tree: A tree object.
141
 
    :param subdir: None or the path of a directory to start exporting from.
 
146
    :param subdir: None or the path of an entry to start exporting from.
142
147
    """
143
148
    inv = tree.inventory
144
149
    if subdir is None:
145
 
        subdir_id = None
 
150
        subdir_object = None
146
151
    else:
147
152
        subdir_id = inv.path2id(subdir)
148
 
    entries = inv.iter_entries(subdir_id)
 
153
        if subdir_id is not None:
 
154
            subdir_object = inv[subdir_id]
 
155
        # XXX: subdir is path not an id, so NoSuchId isn't proper error
 
156
        else:
 
157
            raise errors.NoSuchId(tree, subdir)
 
158
    if subdir_object is not None and subdir_object.kind != 'directory':
 
159
        yield subdir_object.name, subdir_object
 
160
        return
 
161
    else:
 
162
        entries = inv.iter_entries(subdir_object)
149
163
    if subdir is None:
150
164
        entries.next() # skip root
151
165
    for entry in entries: