17
17
import types, os, sys, stat
20
from osutils import quotefn, appendpath
20
from osutils import quotefn
21
21
from errors import bailout
22
from trace import mutter, note
24
def smart_add(file_list, verbose=False, recurse=True):
23
def smart_add(file_list, verbose=False, recurse=False):
25
24
"""Add files to version, optionall recursing into directories.
27
26
This is designed more towards DWIM for humans than API simplicity.
28
27
For the specific behaviour see the help for cmd_add().
31
assert not isinstance(file_list, basestring)
30
assert not isinstance(file_list, types.StringTypes)
32
31
b = bzrlib.branch.Branch(file_list[0], find_root=True)
33
32
inv = b.read_working_inventory()
34
tree = b.working_tree()
37
35
for f in file_list:
41
## TODO: It's OK to add root but only in recursive mode
43
39
bzrlib.mutter("smart add of %r" % f)
45
41
if bzrlib.branch.is_control_file(af):
46
42
bailout("cannot add control file %r" % af)
48
44
kind = bzrlib.osutils.file_kind(f)
50
if kind != 'file' and kind != 'directory':
51
bailout("can't add file of kind %r" % kind)
53
versioned = (inv.path2id(rf) != None)
56
mutter("branch root doesn't need to be added")
58
mutter("%r is already versioned" % f)
47
bzrlib.warning("%r is already versioned" % f)
49
elif kind == 'directory':
52
bzrlib.warning("%r is already versioned" % f)
55
# TODO: don't add, but recurse down
60
file_id = bzrlib.branch.gen_file_id(rf)
61
inv.add_path(rf, kind=kind, file_id=file_id)
62
bzrlib.mutter("added %r kind %r file_id={%s}" % (rf, kind, file_id))
65
bzrlib.textui.show_status('A', kind, quotefn(f))
67
if kind == 'directory' and recurse:
68
for subf in os.listdir(af):
69
subp = appendpath(rf, subf)
70
if subf == bzrlib.BZRDIR:
71
mutter("skip control directory %r" % subp)
72
elif tree.is_ignored(subp):
73
mutter("skip ignored sub-file %r" % subp)
75
mutter("queue to add sub-file %r" % (subp))
76
file_list.append(subp)
58
bailout("can't smart_add file kind %r" % kind)
60
file_id = bzrlib.branch.gen_file_id(rf)
61
inv.add_path(rf, kind=kind, file_id=file_id)
62
bzrlib.mutter("added %r kind %r file_id={%s}" % (rf, kind, file_id))
80
note('added %d' % count)
65
bzrlib.textui.show_status('A', kind, quotefn(f))
81
68
b._write_inventory(inv)