~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

  • Committer: Martin Pool
  • Date: 2005-09-01 12:59:42 UTC
  • Revision ID: mbp@sourcefrog.net-20050901125942-25443d6a887b9fab
- better explanation when merge fails with AmbiguousBase

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    return expanded_file_list
36
36
 
37
37
 
38
 
def _NullAddCallback(path, kind, entry):
 
38
def add_reporter_null(path, kind, entry):
 
39
    """Absorb add reports and do nothing."""
39
40
    pass
40
41
 
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)
43
45
    
44
46
def _prepare_file_list(file_list):
49
51
    if not file_list:
50
52
        file_list = ['.']
51
53
    file_list = list(file_list)
52
 
    assert not isinstance(file_list, basestring)
53
54
    return file_list
54
55
 
55
 
def smart_add(file_list, verbose=True, recurse=True, callback=_NullAddCallback):
 
56
 
 
57
def smart_add(file_list, recurse=True, reporter=add_reporter_null):
56
58
    """Add files to version, optionally recursing into directories.
57
59
 
58
60
    This is designed more towards DWIM for humans than API simplicity.
59
61
    For the specific behaviour see the help for cmd_add().
 
62
 
 
63
    Returns the number of files added.
60
64
    """
61
65
    file_list = _prepare_file_list(file_list)
62
66
    b = Branch(file_list[0], find_root=True)
63
 
    return smart_add_branch(b, file_list, verbose, recurse)
 
67
    return smart_add_branch(b, file_list, recurse, reporter)
 
68
 
64
69
        
65
 
def smart_add_branch(branch, file_list, verbose=True, recurse=True,
66
 
                     callback=_NullAddCallback):
 
70
def smart_add_branch(branch, file_list, recurse=True, reporter=add_reporter_null):
67
71
    """Add files to version, optionally recursing into directories.
68
72
 
69
73
    This is designed more towards DWIM for humans than API simplicity.
70
74
    For the specific behaviour see the help for cmd_add().
71
75
 
72
76
    This yields a sequence of (path, kind, file_id) for added files.
 
77
 
 
78
    Returns the number of files added.
73
79
    """
74
80
    import os
75
81
    import sys
78
84
    import bzrlib.branch
79
85
    import bzrlib.osutils
80
86
 
 
87
    assert isinstance(recurse, bool)
 
88
 
81
89
    file_list = _prepare_file_list(file_list)
82
90
    user_list = file_list[:]
83
91
    inv = branch.read_working_inventory()
124
132
            entry = inv.add_path(rf, kind=kind)
125
133
            mutter("added %r kind %r file_id={%s}" % (rf, kind, entry.file_id))
126
134
            count += 1 
127
 
            callback(rf, kind, entry)
 
135
            reporter(rf, kind, entry)
128
136
 
129
137
        if kind == 'directory' and recurse and not sub_tree:
130
138
            for subf in os.listdir(af):
138
146
                    file_list.append(branch.abspath(subp))
139
147
 
140
148
 
 
149
    mutter('added %d entries', count)
 
150
    
141
151
    if count > 0:
142
 
        if verbose:
143
 
            note('added %d' % count)
144
152
        branch._write_inventory(inv)
145
 
    else:
146
 
        note("nothing new to add")
147
 
        # should this return 1 to the shell?
 
153
 
 
154
    return count