~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2006-07-31 07:18:54 UTC
  • mto: (1852.14.2 status-benchmarks)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: robertc@robertcollins.net-20060731071854-d1fe7dd1ee353097
Tweak the Tree.walkdirs interface more to be more useful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1490
1490
            disk_top = disk_top[:-1]
1491
1491
        top_strip_len = len(disk_top) + 1
1492
1492
        disk_iterator = osutils.walkdirs(disk_top, prefix)
1493
 
        current_inv = inventory_iterator.next()
 
1493
        try:
 
1494
            current_inv = inventory_iterator.next()
 
1495
            inv_finished = False
 
1496
        except StopIteration:
 
1497
            current_inv = None
 
1498
            inv_finished = True
1494
1499
        current_disk = disk_iterator.next()
1495
 
        inv_finished = False
1496
1500
        disk_finished = False
1497
1501
        while not inv_finished or not disk_finished:
1498
1502
            if not disk_finished:
1505
1509
                    if current_disk[1][bzrdir_loc][0] == '.bzr':
1506
1510
                        # we dont yield the contents of, or, .bzr itself.
1507
1511
                        del current_disk[1][bzrdir_loc]
1508
 
            direction = cmp(current_inv[0][0], current_disk[0][0])
 
1512
            if inv_finished:
 
1513
                # everything is unknown
 
1514
                direction = -1
 
1515
            else:
 
1516
                direction = cmp(current_inv[0][0], current_disk[0][0])
1509
1517
            if direction < 0:
1510
 
                # inventory is before disk - unknown.
1511
 
                dirblock = [(relpath, basename, kind, stat, top_path[top_strip_len:], None, None) for relpath, basename, kind, stat, top_path in current_disk[1]]
1512
 
                yield (current_disk[0][0], current_disk[0][1][top_strip_len:], None), dirblock
 
1518
                # disk is before inventory - unknown
 
1519
                dirblock = [(relpath, basename, kind, stat, None, None) for relpath, basename, kind, stat, top_path in current_disk[1]]
 
1520
                yield (current_disk[0][0], None), dirblock
1513
1521
                try:
1514
1522
                    current_disk = disk_iterator.next()
1515
1523
                except StopIteration:
1516
1524
                    disk_finished = True
1517
1525
            elif direction > 0:
1518
 
                # disk is before inventory - missing
 
1526
                # inventory is before disk - missing.
1519
1527
                try:
1520
1528
                    current_inv = inventory_iterator.next()
1521
1529
                except StopIteration:
1523
1531
            else:
1524
1532
                # versioned present directory
1525
1533
                # merge the inventory and disk data together
1526
 
#                dirblock = [(relpath, basename, kind, stat, top_path, None, None, None) for relpath, basename, kind, stat, top_path in current_disk[1]]
 
1534
#                dirblock = [(relpath, basename, kind, stat, None, None) for relpath, basename, kind, stat, top_path in current_disk[1]]
1527
1535
#                yield current_inv
1528
1536
                dirblock = []
1529
1537
                for relpath, subiterator in itertools.groupby(sorted(current_inv[1] + current_disk[1]), operator.itemgetter(1)):
1530
1538
                    path_elements = list(subiterator)
1531
1539
                    if len(path_elements) == 2:
1532
1540
                        # versioned, present file
1533
 
                        dirblock.append((path_elements[0][0], path_elements[0][1], path_elements[1][2], path_elements[1][3], path_elements[0][4], path_elements[0][5], path_elements[0][6]))
 
1541
                        dirblock.append((path_elements[0][0], path_elements[0][1], path_elements[1][2], path_elements[1][3], path_elements[0][4], path_elements[0][5]))
1534
1542
                    elif len(path_elements[0]) == 5:
1535
1543
                        # unknown disk file
1536
 
                        dirblock.append((path_elements[0][0], path_elements[0][1], path_elements[0][2], path_elements[0][3], path_elements[0][4][top_strip_len:], None, None))
 
1544
                        dirblock.append((path_elements[0][0], path_elements[0][1], path_elements[0][2], path_elements[0][3], None, None))
1537
1545
                yield current_inv[0], dirblock
1538
1546
                try:
1539
1547
                    current_inv = inventory_iterator.next()
1544
1552
                except StopIteration:
1545
1553
                    disk_finished = True
1546
1554
 
1547
 
        #for dirinfo, dirblock in self._walkdirs(prefix):
1548
 
        #    yield dirinfo, dirblock
1549
 
 
1550
1555
    def _walkdirs(self, prefix=""):
1551
1556
        _directory = 'directory'
1552
 
        pending = [('', '', _directory, None, '', None, None)]
 
1557
        # get the root in the inventory
1553
1558
        inv = self.inventory
 
1559
        top_id = inv.path2id(prefix)
 
1560
        if top_id is None:
 
1561
            pending = []
 
1562
        else:
 
1563
            pending = [(prefix, '', _directory, None, top_id, None)]
1554
1564
        while pending:
1555
1565
            dirblock = []
1556
1566
            currentdir = pending.pop()
1557
 
            # 0 - relpath, 1- basename, 2- kind, 3- stat, 4-toppath
1558
 
            top = currentdir[4]
 
1567
            # 0 - relpath, 1- basename, 2- kind, 3- stat, 4-id, 5-kind
 
1568
            top_id = currentdir[4]
1559
1569
            if currentdir[0]:
1560
1570
                relroot = currentdir[0] + '/'
1561
1571
            else:
1562
1572
                relroot = ""
1563
1573
            # FIXME: stash the node in pending
1564
 
            entry = inv[inv.path2id(top)]
 
1574
            entry = inv[top_id]
1565
1575
            for name, child in entry.sorted_children():
1566
 
                toppath = relroot + name
1567
 
                dirblock.append((toppath, name, child.kind, None, toppath,
 
1576
                dirblock.append((relroot + name, name, child.kind, None,
1568
1577
                    child.file_id, child.kind
1569
1578
                    ))
1570
 
            yield (currentdir[0], top, entry.file_id), dirblock
 
1579
            yield (currentdir[0], entry.file_id), dirblock
1571
1580
            # push the user specified dirs from dirblock
1572
1581
            for dir in reversed(dirblock):
1573
1582
                if dir[2] == _directory: