94
94
Returns the number of files added.
97
97
from bzrlib.errors import BadFileKindError, ForbiddenFileError
98
98
assert isinstance(recurse, bool)
100
100
file_list = _prepare_file_list(file_list)
101
101
user_list = file_list[:]
102
102
inv = tree.read_working_inventory()
106
105
for f in file_list:
107
106
rf = tree.relpath(f)
108
107
af = tree.abspath(rf)
111
kind = bzrlib.osutils.file_kind(af)
113
if hasattr(e, 'errno') and e.errno == errno.ENOENT:
114
raise errors.NoSuchFile(rf)
109
kind = bzrlib.osutils.file_kind(af)
117
111
if not InventoryEntry.versionable_kind(kind):
118
112
if f in user_list:
148
142
mutter("%r is a bzr tree", f)
150
added.extend(__add_one(tree, inv, rf, kind, action))
144
count += __add_one(tree, inv, rf, kind, action)
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)
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)
165
mutter("queue to add sub-file %r", subp)
166
file_list.append(tree.abspath(subp))
169
mutter('added %d entries', len(added))
154
mutter("queue to add sub-file %r", subp)
155
file_list.append(tree.abspath(subp))
158
mutter('added %d entries', count)
172
161
tree._write_inventory(inv)
174
return added, ignored
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:
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)
189
return added + [path]