~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

Nathaniel McCallums patch for urandom friendliness on aix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
21
 
23
22
def glob_expand_for_win32(file_list):
24
23
    import glob
64
63
    Returns the number of files added.
65
64
    """
66
65
    file_list = _prepare_file_list(file_list)
67
 
    b = Branch.open_containing(file_list[0])
 
66
    b = Branch(file_list[0], find_root=True)
68
67
    return smart_add_branch(b, file_list, recurse, reporter)
69
68
 
70
69
        
79
78
    Returns the number of files added.
80
79
    """
81
80
    import os
 
81
    import sys
 
82
    from bzrlib.osutils import quotefn
82
83
    from bzrlib.errors import BadFileKindError, ForbiddenFileError
83
84
    import bzrlib.branch
 
85
    import bzrlib.osutils
84
86
 
85
87
    assert isinstance(recurse, bool)
86
88
 
112
114
 
113
115
        if kind == 'directory':
114
116
            try:
115
 
                sub_branch = Branch.open(af)
 
117
                sub_branch = Branch(af, find_root=False)
116
118
                sub_tree = True
117
119
            except NotBranchError:
118
120
                sub_tree = False
127
129
        elif sub_tree:
128
130
            mutter("%r is a bzr tree" %f)
129
131
        else:
130
 
            count += __add_one(branch, inv, rf, kind, reporter)
 
132
            entry = inv.add_path(rf, kind=kind)
 
133
            mutter("added %r kind %r file_id={%s}" % (rf, kind, entry.file_id))
 
134
            count += 1 
 
135
            reporter(rf, kind, entry)
131
136
 
132
137
        if kind == 'directory' and recurse and not sub_tree:
133
138
            for subf in os.listdir(af):
147
152
        branch._write_inventory(inv)
148
153
 
149
154
    return count
150
 
 
151
 
def __add_one(branch, inv, path, kind, reporter):
152
 
    """Add a file or directory, automatically add unversioned parents."""
153
 
 
154
 
    # Nothing to do if path is already versioned.
155
 
    # This is safe from infinite recursion because the branch root is
156
 
    # always versioned.
157
 
    if inv.path2id(path) != None:
158
 
        return 0
159
 
 
160
 
    # add parent
161
 
    count = __add_one(branch, inv, dirname(path), 'directory', reporter)
162
 
 
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)
166
 
 
167
 
    return count + 1