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