~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

Merge in format-5 work - release bzr 0.1rc1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
from bzrlib.inventory import InventoryEntry
17
18
from bzrlib.trace import mutter, note, warning
18
19
from bzrlib.errors import NotBranchError
19
20
from bzrlib.branch import Branch
20
21
from bzrlib.osutils import quotefn
 
22
from os.path import dirname
21
23
 
22
24
def glob_expand_for_win32(file_list):
23
25
    import glob
24
 
    
25
26
    expanded_file_list = []
26
27
    for possible_glob in file_list:
27
28
        glob_files = glob.glob(possible_glob)
63
64
    Returns the number of files added.
64
65
    """
65
66
    file_list = _prepare_file_list(file_list)
66
 
    b = Branch(file_list[0], find_root=True)
 
67
    b = Branch.open_containing(file_list[0])
67
68
    return smart_add_branch(b, file_list, recurse, reporter)
68
69
 
69
70
        
78
79
    Returns the number of files added.
79
80
    """
80
81
    import os
81
 
    import sys
82
 
    from bzrlib.osutils import quotefn
83
82
    from bzrlib.errors import BadFileKindError, ForbiddenFileError
84
83
    import bzrlib.branch
85
 
    import bzrlib.osutils
86
84
 
87
85
    assert isinstance(recurse, bool)
88
86
 
98
96
 
99
97
        kind = bzrlib.osutils.file_kind(af)
100
98
 
101
 
        if kind != 'file' and kind != 'directory':
 
99
        if not InventoryEntry.versionable_kind(kind):
102
100
            if f in user_list:
103
101
                raise BadFileKindError("cannot add %s of type %s" % (f, kind))
104
102
            else:
114
112
 
115
113
        if kind == 'directory':
116
114
            try:
117
 
                sub_branch = Branch(af, find_root=False)
 
115
                sub_branch = Branch.open(af)
118
116
                sub_tree = True
119
117
            except NotBranchError:
120
118
                sub_tree = False
129
127
        elif sub_tree:
130
128
            mutter("%r is a bzr tree" %f)
131
129
        else:
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)
 
130
            count += __add_one(branch, inv, rf, kind, reporter)
136
131
 
137
132
        if kind == 'directory' and recurse and not sub_tree:
138
133
            for subf in os.listdir(af):
152
147
        branch._write_inventory(inv)
153
148
 
154
149
    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