35
35
return expanded_file_list
38
def add_reporter_null(path, kind, entry):
39
"""Absorb add reports and do nothing."""
38
def _NullAddCallback(path, kind, entry):
42
def add_reporter_print(path, kind, entry):
43
"""Print a line to stdout for each file that's added."""
41
def _PrintAddCallback(path, kind, entry):
44
42
print "added", quotefn(path)
46
44
def _prepare_file_list(file_list):
53
51
file_list = list(file_list)
52
assert not isinstance(file_list, basestring)
57
def smart_add(file_list, recurse=True, reporter=add_reporter_null):
55
def smart_add(file_list, verbose=True, recurse=True, callback=_NullAddCallback):
58
56
"""Add files to version, optionally recursing into directories.
60
58
This is designed more towards DWIM for humans than API simplicity.
61
59
For the specific behaviour see the help for cmd_add().
63
Returns the number of files added.
65
61
file_list = _prepare_file_list(file_list)
66
62
b = Branch(file_list[0], find_root=True)
67
return smart_add_branch(b, file_list, recurse, reporter)
63
return smart_add_branch(b, file_list, verbose, recurse)
70
def smart_add_branch(branch, file_list, recurse=True, reporter=add_reporter_null):
65
def smart_add_branch(branch, file_list, verbose=True, recurse=True,
66
callback=_NullAddCallback):
71
67
"""Add files to version, optionally recursing into directories.
73
69
This is designed more towards DWIM for humans than API simplicity.
74
70
For the specific behaviour see the help for cmd_add().
76
72
This yields a sequence of (path, kind, file_id) for added files.
78
Returns the number of files added.
132
124
entry = inv.add_path(rf, kind=kind)
133
125
mutter("added %r kind %r file_id={%s}" % (rf, kind, entry.file_id))
135
reporter(rf, kind, entry)
127
callback(rf, kind, entry)
137
129
if kind == 'directory' and recurse and not sub_tree:
138
130
for subf in os.listdir(af):
146
138
file_list.append(branch.abspath(subp))
149
mutter('added %d entries', count)
143
note('added %d' % count)
152
144
branch._write_inventory(inv)
146
note("nothing new to add")
147
# should this return 1 to the shell?