18
18
from bzrlib.errors import NotBranchError
19
19
from bzrlib.branch import Branch
20
20
from bzrlib.osutils import quotefn
21
from os.path import dirname
22
23
def glob_expand_for_win32(file_list):
35
36
return expanded_file_list
38
def _NullAddCallback(path, kind, entry):
39
def add_reporter_null(path, kind, entry):
40
"""Absorb add reports and do nothing."""
41
def _PrintAddCallback(path, kind, entry):
43
def add_reporter_print(path, kind, entry):
44
"""Print a line to stdout for each file that's added."""
42
45
print "added", quotefn(path)
44
47
def _prepare_file_list(file_list):
51
54
file_list = list(file_list)
52
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.
76
from bzrlib.osutils import quotefn
77
82
from bzrlib.errors import BadFileKindError, ForbiddenFileError
78
83
import bzrlib.branch
85
assert isinstance(recurse, bool)
81
87
file_list = _prepare_file_list(file_list)
82
88
user_list = file_list[:]
122
128
mutter("%r is a bzr tree" %f)
124
entry = inv.add_path(rf, kind=kind)
125
mutter("added %r kind %r file_id={%s}" % (rf, kind, entry.file_id))
127
callback(rf, kind, entry)
130
count += __add_one(branch, inv, rf, kind, reporter)
129
132
if kind == 'directory' and recurse and not sub_tree:
130
133
for subf in os.listdir(af):
138
141
file_list.append(branch.abspath(subp))
144
mutter('added %d entries', count)
143
note('added %d' % count)
144
147
branch._write_inventory(inv)
146
note("nothing new to add")
147
# should this return 1 to the shell?
151
def __add_one(branch, inv, path, kind, reporter):
152
"""Add a file or directory, automatically add unversioned parents."""
154
# Nothing to do if path is already versioned.
155
# This is safe from infinite recursion because the branch root is
157
if inv.path2id(path) != None:
161
count = __add_one(branch, inv, dirname(path), 'directory', reporter)
163
entry = inv.add_path(path, kind=kind)
164
mutter("added %r kind %r file_id={%s}" % (path, kind, entry.file_id))
165
reporter(path, kind, entry)