/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/export/__init__.py

1st cut merge of bzr.dev r3907

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
    When requesting a specific type of export, load the respective path.
57
57
    """
58
 
    def _loader(tree, dest, root, filtered):
 
58
    def _loader(tree, dest, root, subdir, filtered):
59
59
        mod = __import__(module, globals(), locals(), [funcname])
60
60
        func = getattr(mod, funcname)
61
 
        return func(tree, dest, root, filtered=filtered)
 
61
        return func(tree, dest, root, subdir, filtered=filtered)
62
62
    register_exporter(scheme, extensions, _loader)
63
63
 
64
64
 
65
 
def export(tree, dest, format=None, root=None, filtered=False):
 
65
def export(tree, dest, format=None, root=None, subdir=None, filtered=False):
66
66
    """Export the given Tree to the specific destination.
67
67
 
68
68
    :param tree: A Tree (such as RevisionTree) to export
76
76
                 If root is None, the default root will be
77
77
                 selected as the destination without its
78
78
                 extension.
 
79
    :param subdir: A starting directory within the tree. None means to export
 
80
        the entire tree, and anything else should specify the relative path to
 
81
        a directory to start exporting from.
79
82
    :param filtered: If True, content filtering is applied to the
80
83
                     files exported.
81
84
    """
96
99
        raise errors.NoSuchExportFormat(format)
97
100
    tree.lock_read()
98
101
    try:
99
 
        return _exporters[format](tree, dest, root, filtered=filtered)
 
102
        return _exporters[format](tree, dest, root, subdir, filtered=filtered)
100
103
    finally:
101
104
        tree.unlock()
102
105
 
131
134
    return dest
132
135
 
133
136
 
 
137
def _export_iter_entries(tree, subdir):
 
138
    """Iter the entries for tree suitable for exporting.
 
139
 
 
140
    :param tree: A tree object.
 
141
    :param subdir: None or the path of a directory to start exporting from.
 
142
    """
 
143
    inv = tree.inventory
 
144
    if subdir is None:
 
145
        subdir_id = None
 
146
    else:
 
147
        subdir_id = inv.path2id(subdir)
 
148
    entries = inv.iter_entries(subdir_id)
 
149
    if subdir is None:
 
150
        entries.next() # skip root
 
151
    for entry in entries:
 
152
        # The .bzr* namespace is reserved for "magic" files like
 
153
        # .bzrignore and .bzrrules - do not export these
 
154
        if entry[0].startswith(".bzr"):
 
155
            continue
 
156
        yield entry
 
157
 
 
158
 
134
159
register_lazy_exporter(None, [], 'bzrlib.export.dir_exporter', 'dir_exporter')
135
160
register_lazy_exporter('dir', [], 'bzrlib.export.dir_exporter', 'dir_exporter')
136
161
register_lazy_exporter('tar', ['.tar'], 'bzrlib.export.tar_exporter', 'tar_exporter')