/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

  • Committer: Robert Collins
  • Date: 2008-09-02 00:01:34 UTC
  • mfrom: (3671 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3724.
  • Revision ID: robertc@robertcollins.net-20080902000134-qz8r6v1mltygeg6t
Merge bzr.dev.

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):
 
58
    def _loader(tree, dest, root, subdir):
59
59
        mod = __import__(module, globals(), locals(), [funcname])
60
60
        func = getattr(mod, funcname)
61
 
        return func(tree, dest, root)
 
61
        return func(tree, dest, root, subdir)
62
62
    register_exporter(scheme, extensions, _loader)
63
63
 
64
64
 
65
 
def export(tree, dest, format=None, root=None):
 
65
def export(tree, dest, format=None, root=None, subdir=None):
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
    """
80
83
    global _exporters, _exporter_extensions
81
84
 
94
97
        raise errors.NoSuchExportFormat(format)
95
98
    tree.lock_read()
96
99
    try:
97
 
        return _exporters[format](tree, dest, root)
 
100
        return _exporters[format](tree, dest, root, subdir)
98
101
    finally:
99
102
        tree.unlock()
100
103
 
129
132
    return dest
130
133
 
131
134
 
 
135
def _export_iter_entries(tree, subdir):
 
136
    """Iter the entries for tree suitable for exporting.
 
137
 
 
138
    :param tree: A tree object.
 
139
    :param subdir: None or the path of a directory to start exporting from.
 
140
    """
 
141
    inv = tree.inventory
 
142
    if subdir is None:
 
143
        subdir_id = None
 
144
    else:
 
145
        subdir_id = inv.path2id(subdir)
 
146
    entries = inv.iter_entries(subdir_id)
 
147
    if subdir is None:
 
148
        entries.next() # skip root
 
149
    for entry in entries:
 
150
        # The .bzr* namespace is reserved for "magic" files like
 
151
        # .bzrignore and .bzrrules - do not export these
 
152
        if entry[0].startswith(".bzr"):
 
153
            continue
 
154
        yield entry
 
155
 
 
156
 
132
157
register_lazy_exporter(None, [], 'bzrlib.export.dir_exporter', 'dir_exporter')
133
158
register_lazy_exporter('dir', [], 'bzrlib.export.dir_exporter', 'dir_exporter')
134
159
register_lazy_exporter('tar', ['.tar'], 'bzrlib.export.tar_exporter', 'tar_exporter')