/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/graph.py

  • Committer: Martin Pool
  • Date: 2009-03-23 07:25:27 UTC
  • mfrom: (4183 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4189.
  • Revision ID: mbp@sourcefrog.net-20090323072527-317my4n8zej1g6v9
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1443
1443
            a SearchResult from a smart server, in which case the keys list is
1444
1444
            not necessarily immediately available.
1445
1445
        """
1446
 
        self._recipe = (start_keys, exclude_keys, key_count)
 
1446
        self._recipe = ('search', start_keys, exclude_keys, key_count)
1447
1447
        self._keys = frozenset(keys)
1448
1448
 
1449
1449
    def get_recipe(self):
1456
1456
        added to the exclude list (or else ghost filling may alter the
1457
1457
        results).
1458
1458
 
1459
 
        :return: A tuple (start_keys_set, exclude_keys_set, revision_count). To
1460
 
            recreate the results of this search, create a breadth first
1461
 
            searcher on the same graph starting at start_keys. Then call next()
1462
 
            (or next_with_ghosts()) repeatedly, and on every result, call
1463
 
            stop_searching_any on any keys from the exclude_keys set. The
1464
 
            revision_count value acts as a trivial cross-check - the found
1465
 
            revisions of the new search should have as many elements as
 
1459
        :return: A tuple ('search', start_keys_set, exclude_keys_set,
 
1460
            revision_count). To recreate the results of this search, create a
 
1461
            breadth first searcher on the same graph starting at start_keys.
 
1462
            Then call next() (or next_with_ghosts()) repeatedly, and on every
 
1463
            result, call stop_searching_any on any keys from the exclude_keys
 
1464
            set. The revision_count value acts as a trivial cross-check - the
 
1465
            found revisions of the new search should have as many elements as
1466
1466
            revision_count. If it does not, then additional revisions have been
1467
1467
            ghosted since the search was executed the first time and the second
1468
1468
            time.
1476
1476
        """
1477
1477
        return self._keys
1478
1478
 
 
1479
    def is_empty(self):
 
1480
        """Return true if the search lists 1 or more revisions."""
 
1481
        return self._recipe[3] == 0
 
1482
 
 
1483
    def refine(self, seen, referenced):
 
1484
        """Create a new search by refining this search.
 
1485
 
 
1486
        :param seen: Revisions that have been satisfied.
 
1487
        :param referenced: Revision references observed while satisfying some
 
1488
            of this search.
 
1489
        """
 
1490
        start = self._recipe[1]
 
1491
        exclude = self._recipe[2]
 
1492
        count = self._recipe[3]
 
1493
        keys = self.get_keys()
 
1494
        # New heads = referenced + old heads - seen things - exclude
 
1495
        pending_refs = set(referenced)
 
1496
        pending_refs.update(start)
 
1497
        pending_refs.difference_update(seen)
 
1498
        pending_refs.difference_update(exclude)
 
1499
        # New exclude = old exclude + satisfied heads
 
1500
        seen_heads = start.intersection(seen)
 
1501
        exclude.update(seen_heads)
 
1502
        # keys gets seen removed
 
1503
        keys = keys - seen
 
1504
        # length is reduced by len(seen)
 
1505
        count -= len(seen)
 
1506
        return SearchResult(pending_refs, exclude, count, keys)
 
1507
 
1479
1508
 
1480
1509
class PendingAncestryResult(object):
1481
1510
    """A search result that will reconstruct the ancestry for some graph heads.
1491
1520
        :param repo: a repository to use to generate the ancestry for the given
1492
1521
            heads.
1493
1522
        """
1494
 
        self.heads = heads
 
1523
        self.heads = frozenset(heads)
1495
1524
        self.repo = repo
1496
1525
 
1497
1526
    def get_recipe(self):
1498
 
        raise NotImplementedError(self.get_recipe)
 
1527
        """Return a recipe that can be used to replay this search.
 
1528
 
 
1529
        The recipe allows reconstruction of the same results at a later date.
 
1530
 
 
1531
        :seealso SearchResult.get_recipe:
 
1532
 
 
1533
        :return: A tuple ('proxy-search', start_keys_set, set(), -1)
 
1534
            To recreate this result, create a PendingAncestryResult with the
 
1535
            start_keys_set.
 
1536
        """
 
1537
        return ('proxy-search', self.heads, set(), -1)
1499
1538
 
1500
1539
    def get_keys(self):
1501
1540
        """See SearchResult.get_keys.
1511
1550
                if key != NULL_REVISION]
1512
1551
        return keys
1513
1552
 
 
1553
    def is_empty(self):
 
1554
        """Return true if the search lists 1 or more revisions."""
 
1555
        if revision.NULL_REVISION in self.heads:
 
1556
            return len(self.heads) == 1
 
1557
        else:
 
1558
            return len(self.heads) == 0
 
1559
 
 
1560
    def refine(self, seen, referenced):
 
1561
        """Create a new search by refining this search.
 
1562
 
 
1563
        :param seen: Revisions that have been satisfied.
 
1564
        :param referenced: Revision references observed while satisfying some
 
1565
            of this search.
 
1566
        """
 
1567
        referenced = self.heads.union(referenced)
 
1568
        return PendingAncestryResult(referenced - seen, self.repo)
 
1569
 
1514
1570
 
1515
1571
def collapse_linear_regions(parent_map):
1516
1572
    """Collapse regions of the graph that are 'linear'.