41
41
return expanded_file_list
44
def add_reporter_null(path, kind, entry):
45
"""Absorb add reports and do nothing."""
49
def add_reporter_print(path, kind, entry):
50
"""Print a line to stdout for each file that's added."""
51
print "added", bzrlib.osutils.quotefn(path)
54
44
def _prepare_file_list(file_list):
55
45
"""Prepare a file list for use by smart_add_*."""
65
def smart_add(file_list, recurse=True, reporter=add_reporter_null):
55
def add_action_null(inv, path, kind):
56
"""Absorb add actions and do nothing."""
59
def add_action_print(inv, path, kind):
60
"""Print a line to stdout for each file that would be added."""
61
print "added", bzrlib.osutils.quotefn(path)
63
def add_action_add(inv, path, kind):
64
"""Add each file to the given inventory. Produce no output."""
65
entry = inv.add_path(path, kind=kind)
66
mutter("added %r kind %r file_id={%s}" % (path, kind, entry.file_id))
68
def add_action_add_and_print(inv, path, kind):
69
"""Add each file to the given inventory, and print a line to stdout."""
70
add_action_add(inv, path, kind)
71
add_action_print(inv, path, kind)
74
def smart_add(file_list, recurse=True, action=add_action_add):
66
75
"""Add files to version, optionally recursing into directories.
68
77
This is designed more towards DWIM for humans than API simplicity.
73
82
file_list = _prepare_file_list(file_list)
74
83
tree = WorkingTree.open_containing(file_list[0])[0]
75
return smart_add_tree(tree, file_list, recurse, reporter)
84
return smart_add_tree(tree, file_list, recurse, action)
78
def smart_add_tree(tree, file_list, recurse=True, reporter=add_reporter_null):
86
def smart_add_tree(tree, file_list, recurse=True, action=add_action_add):
79
87
"""Add files to version, optionally recursing into directories.
81
89
This is designed more towards DWIM for humans than API simplicity.
134
142
mutter("%r is a bzr tree", f)
136
count += __add_one(tree, inv, rf, kind, reporter)
144
count += __add_one(tree, inv, rf, kind, action)
138
146
if kind == 'directory' and recurse and not sub_tree:
139
147
for subf in os.listdir(af):
157
def __add_one(tree, inv, path, kind, reporter):
165
def __add_one(tree, inv, path, kind, action):
158
166
"""Add a file or directory, automatically add unversioned parents."""
160
168
# Nothing to do if path is already versioned.
167
count = __add_one(tree, inv, dirname(path), 'directory', reporter)
169
entry = inv.add_path(path, kind=kind)
170
mutter("added %r kind %r file_id={%s}", path, kind, entry.file_id)
171
reporter(path, kind, entry)
175
count = __add_one(tree, inv, dirname(path), 'directory', action)
176
action(inv, path, kind)