~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

(robertc) Fix WorkingTree.walkdirs to support walking an empty directory. (Marius Kruger)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2302
2302
            current_inv = None
2303
2303
            inv_finished = True
2304
2304
        while not inv_finished or not disk_finished:
 
2305
            if current_disk:
 
2306
                ((cur_disk_dir_relpath, cur_disk_dir_path_from_top),
 
2307
                    cur_disk_dir_content) = current_disk
 
2308
            else:
 
2309
                ((cur_disk_dir_relpath, cur_disk_dir_path_from_top),
 
2310
                    cur_disk_dir_content) = ((None, None), None)
2305
2311
            if not disk_finished:
2306
2312
                # strip out .bzr dirs
2307
 
                if current_disk[0][1][top_strip_len:] == '':
2308
 
                    # osutils.walkdirs can be made nicer - 
 
2313
                if (cur_disk_dir_path_from_top[top_strip_len:] == '' and
 
2314
                    len(cur_disk_dir_content) > 0):
 
2315
                    # osutils.walkdirs can be made nicer -
2309
2316
                    # yield the path-from-prefix rather than the pathjoined
2310
2317
                    # value.
2311
 
                    bzrdir_loc = bisect_left(current_disk[1], ('.bzr', '.bzr'))
2312
 
                    if current_disk[1][bzrdir_loc][0] == '.bzr':
 
2318
                    bzrdir_loc = bisect_left(cur_disk_dir_content,
 
2319
                        ('.bzr', '.bzr'))
 
2320
                    if cur_disk_dir_content[bzrdir_loc][0] == '.bzr':
2313
2321
                        # we dont yield the contents of, or, .bzr itself.
2314
 
                        del current_disk[1][bzrdir_loc]
 
2322
                        del cur_disk_dir_content[bzrdir_loc]
2315
2323
            if inv_finished:
2316
2324
                # everything is unknown
2317
2325
                direction = 1
2319
2327
                # everything is missing
2320
2328
                direction = -1
2321
2329
            else:
2322
 
                direction = cmp(current_inv[0][0], current_disk[0][0])
 
2330
                direction = cmp(current_inv[0][0], cur_disk_dir_relpath)
2323
2331
            if direction > 0:
2324
2332
                # disk is before inventory - unknown
2325
2333
                dirblock = [(relpath, basename, kind, stat, None, None) for
2326
 
                    relpath, basename, kind, stat, top_path in current_disk[1]]
2327
 
                yield (current_disk[0][0], None), dirblock
 
2334
                    relpath, basename, kind, stat, top_path in
 
2335
                    cur_disk_dir_content]
 
2336
                yield (cur_disk_dir_relpath, None), dirblock
2328
2337
                try:
2329
2338
                    current_disk = disk_iterator.next()
2330
2339
                except StopIteration:
2332
2341
            elif direction < 0:
2333
2342
                # inventory is before disk - missing.
2334
2343
                dirblock = [(relpath, basename, 'unknown', None, fileid, kind)
2335
 
                    for relpath, basename, dkind, stat, fileid, kind in 
 
2344
                    for relpath, basename, dkind, stat, fileid, kind in
2336
2345
                    current_inv[1]]
2337
2346
                yield (current_inv[0][0], current_inv[0][1]), dirblock
2338
2347
                try:
2344
2353
                # merge the inventory and disk data together
2345
2354
                dirblock = []
2346
2355
                for relpath, subiterator in itertools.groupby(sorted(
2347
 
                    current_inv[1] + current_disk[1], key=operator.itemgetter(0)), operator.itemgetter(1)):
 
2356
                    current_inv[1] + cur_disk_dir_content,
 
2357
                    key=operator.itemgetter(0)), operator.itemgetter(1)):
2348
2358
                    path_elements = list(subiterator)
2349
2359
                    if len(path_elements) == 2:
2350
2360
                        inv_row, disk_row = path_elements