~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

[merge] win32

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
 
94
94
    Returns the number of files added.
95
95
    """
96
 
    import os, errno
 
96
    import os
97
97
    from bzrlib.errors import BadFileKindError, ForbiddenFileError
98
98
    assert isinstance(recurse, bool)
99
99
 
100
100
    file_list = _prepare_file_list(file_list)
101
101
    user_list = file_list[:]
102
102
    inv = tree.read_working_inventory()
103
 
    added = []
104
 
    ignored = {}
 
103
    count = 0
105
104
 
106
105
    for f in file_list:
107
106
        rf = tree.relpath(f)
108
107
        af = tree.abspath(rf)
109
108
 
110
 
        try:
111
 
            kind = bzrlib.osutils.file_kind(af)
112
 
        except OSError, e:
113
 
            if hasattr(e, 'errno') and e.errno == errno.ENOENT:
114
 
                raise errors.NoSuchFile(rf)
115
 
            raise
 
109
        kind = bzrlib.osutils.file_kind(af)
116
110
 
117
111
        if not InventoryEntry.versionable_kind(kind):
118
112
            if f in user_list:
147
141
        elif sub_tree:
148
142
            mutter("%r is a bzr tree", f)
149
143
        else:
150
 
            added.extend(__add_one(tree, inv, rf, kind, action))
 
144
            count += __add_one(tree, inv, rf, kind, action)
151
145
 
152
146
        if kind == 'directory' and recurse and not sub_tree:
153
147
            for subf in os.listdir(af):
154
148
                subp = bzrlib.osutils.pathjoin(rf, subf)
155
149
                if subf == bzrlib.BZRDIR:
156
150
                    mutter("skip control directory %r", subp)
 
151
                elif tree.is_ignored(subp):
 
152
                    mutter("skip ignored sub-file %r", subp)
157
153
                else:
158
 
                    ignore_glob = tree.is_ignored(subp)
159
 
                    if ignore_glob is not None:
160
 
                        mutter("skip ignored sub-file %r", subp)
161
 
                        if ignore_glob not in ignored:
162
 
                            ignored[ignore_glob] = []
163
 
                        ignored[ignore_glob].append(subp)
164
 
                    else:
165
 
                        mutter("queue to add sub-file %r", subp)
166
 
                        file_list.append(tree.abspath(subp))
167
 
 
168
 
 
169
 
    mutter('added %d entries', len(added))
 
154
                    mutter("queue to add sub-file %r", subp)
 
155
                    file_list.append(tree.abspath(subp))
 
156
 
 
157
 
 
158
    mutter('added %d entries', count)
170
159
    
171
 
    if len(added) > 0:
 
160
    if count > 0:
172
161
        tree._write_inventory(inv)
173
162
 
174
 
    return added, ignored
 
163
    return count
175
164
 
176
165
def __add_one(tree, inv, path, kind, action):
177
166
    """Add a file or directory, automatically add unversioned parents."""
180
169
    # This is safe from infinite recursion because the tree root is
181
170
    # always versioned.
182
171
    if inv.path2id(path) != None:
183
 
        return []
 
172
        return 0
184
173
 
185
174
    # add parent
186
 
    added = __add_one(tree, inv, dirname(path), 'directory', action)
 
175
    count = __add_one(tree, inv, dirname(path), 'directory', action)
187
176
    action(inv, path, kind)
188
177
 
189
 
    return added + [path]
 
178
    return count + 1