~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/export/__init__.py

resolve conflicts against trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
143
143
    :param subdir: None or the path of an entry to start exporting from.
144
144
    :param skip_special: Whether to skip .bzr files.
145
145
    """
146
 
    inv = tree.inventory
147
 
    if subdir is None:
148
 
        subdir_object = None
149
 
    else:
150
 
        subdir_id = inv.path2id(subdir)
151
 
        if subdir_id is not None:
152
 
            subdir_object = inv[subdir_id]
153
 
        # XXX: subdir is path not an id, so NoSuchId isn't proper error
154
 
        else:
155
 
            raise errors.NoSuchId(tree, subdir)
156
 
    if subdir_object is not None and subdir_object.kind != 'directory':
157
 
        yield subdir_object.name, subdir_object
158
 
        return
159
 
    else:
160
 
        entries = inv.iter_entries(subdir_object)
161
 
    if subdir is None:
162
 
        entries.next() # skip root
163
 
    for entry in entries:
 
146
    if subdir == '':
 
147
        subdir = None
 
148
    if subdir is not None:
 
149
        subdir = subdir.rstrip('/')
 
150
    entries = tree.iter_entries_by_dir()
 
151
    entries.next() # skip root
 
152
    for path, entry in entries:
164
153
        # The .bzr* namespace is reserved for "magic" files like
165
154
        # .bzrignore and .bzrrules - do not export these
166
 
        if skip_special and entry[0].startswith(".bzr"):
 
155
        if skip_special and path.startswith(".bzr"):
167
156
            continue
168
 
        if subdir is None:
169
 
            if not tree.has_filename(entry[0]):
 
157
        if path == subdir:
 
158
            if entry.kind == 'directory':
 
159
                continue
 
160
            final_path = entry.name
 
161
        elif subdir is not None:
 
162
            if path.startswith(subdir + '/'):
 
163
                final_path = path[len(subdir) + 1:]
 
164
            else:
170
165
                continue
171
166
        else:
172
 
            if not tree.has_filename(os.path.join(subdir, entry[0])):
173
 
                continue
174
 
        yield entry
 
167
            final_path = path
 
168
        if not tree.has_filename(path):
 
169
            continue
 
170
        yield final_path, entry
175
171
 
176
172
 
177
173
register_lazy_exporter(None, [], 'bzrlib.export.dir_exporter', 'dir_exporter')