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()
105
106
for f in file_list:
106
107
rf = tree.relpath(f)
107
108
af = tree.abspath(rf)
109
kind = bzrlib.osutils.file_kind(af)
111
kind = bzrlib.osutils.file_kind(af)
113
if hasattr(e, 'errno') and e.errno == errno.ENOENT:
114
raise errors.NoSuchFile(rf)
111
117
if not InventoryEntry.versionable_kind(kind):
112
118
if f in user_list:
142
148
mutter("%r is a bzr tree", f)
144
count += __add_one(tree, inv, rf, kind, action)
150
added.extend(__add_one(tree, inv, rf, kind, action))
146
152
if kind == 'directory' and recurse and not sub_tree:
147
153
for subf in os.listdir(af):
148
154
subp = bzrlib.osutils.pathjoin(rf, subf)
149
155
if subf == bzrlib.BZRDIR:
150
156
mutter("skip control directory %r", subp)
151
elif tree.is_ignored(subp):
152
mutter("skip ignored sub-file %r", subp)
154
mutter("queue to add sub-file %r", subp)
155
file_list.append(tree.abspath(subp))
158
mutter('added %d entries', count)
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))
161
172
tree._write_inventory(inv)
174
return added, ignored
165
176
def __add_one(tree, inv, path, kind, action):
166
177
"""Add a file or directory, automatically add unversioned parents."""
169
180
# This is safe from infinite recursion because the tree root is
170
181
# always versioned.
171
182
if inv.path2id(path) != None:
175
count = __add_one(tree, inv, dirname(path), 'directory', action)
186
added = __add_one(tree, inv, dirname(path), 'directory', action)
176
187
action(inv, path, kind)
189
return added + [path]