~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/add.py

  • Committer: Martin Pool
  • Date: 2005-09-12 09:50:44 UTC
  • Revision ID: mbp@sourcefrog.net-20050912095044-6acfdb5611729987
- no tests in bzrlib.fetch anymore

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
18
17
from bzrlib.trace import mutter, note, warning
19
18
from bzrlib.errors import NotBranchError
20
19
from bzrlib.branch import Branch
21
20
from bzrlib.osutils import quotefn
22
 
from os.path import dirname
23
21
 
24
22
def glob_expand_for_win32(file_list):
25
23
    import glob
 
24
    
26
25
    expanded_file_list = []
27
26
    for possible_glob in file_list:
28
27
        glob_files = glob.glob(possible_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
 
96
98
 
97
99
        kind = bzrlib.osutils.file_kind(af)
98
100
 
99
 
        if not InventoryEntry.versionable_kind(kind):
 
101
        if kind != 'file' and kind != 'directory':
100
102
            if f in user_list:
101
103
                raise BadFileKindError("cannot add %s of type %s" % (f, kind))
102
104
            else:
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