1536
1536
return revs, ghosts
1539
class SearchResult(object):
1539
class AbstractSearchResult(object):
1541
def get_recipe(self):
1542
"""Return a recipe that can be used to replay this search.
1544
The recipe allows reconstruction of the same results at a later date.
1546
:return: A tuple of (search_kind_str, *details). The details vary by
1547
kind of search result.
1549
raise NotImplementedError(self.get_recipe)
1551
def get_network_struct(self):
1552
"""Return a tuple that can be transmitted via the HPSS protocol."""
1553
raise NotImplementedError(self.get_network_struct)
1556
"""Return the keys found in this search.
1558
:return: A set of keys.
1560
raise NotImplementedError(self.get_keys)
1563
"""Return false if the search lists 1 or more revisions."""
1564
raise NotImplementedError(self.is_empty)
1566
def refine(self, seen, referenced):
1567
"""Create a new search by refining this search.
1569
:param seen: Revisions that have been satisfied.
1570
:param referenced: Revision references observed while satisfying some
1572
:return: A search result.
1574
raise NotImplementedError(self.refine)
1577
class AbstractSearch(object):
1579
def get_search_result(self):
1580
"""Construct a network-ready search result from this search description.
1582
This may take some time to search repositories, etc.
1584
:return: A search result.
1586
raise NotImplementedError(self.get_search_result)
1589
class SearchResult(AbstractSearchResult):
1540
1590
"""The result of a breadth first search.
1542
1592
A SearchResult provides the ability to reconstruct the search or access a
1703
1753
return PendingAncestryResult(referenced - seen, self.repo)
1706
class EmptySearchResult(object):
1756
class EmptySearchResult(AbstractSearchResult):
1707
1757
"""An empty search result."""
1709
1759
def is_empty(self):
1713
class EverythingResult(object):
1763
class EverythingResult(AbstractSearchResult):
1714
1764
"""A search result that simply requests everything in the repository."""
1716
1766
def __init__(self, repo):
1717
1767
self._repo = repo
1770
return '%s(%r)' % (self.__class__.__name__, self._repo)
1719
1772
def get_recipe(self):
1720
1773
raise NotImplementedError(self.get_recipe)
1744
1797
return PendingAncestryResult(heads, self._repo)
1747
class EverythingNotInOther(object):
1800
class EverythingNotInOther(AbstractSearch):
1801
"""Find all revisions in that are in one repo but not the other."""
1749
1803
def __init__(self, to_repo, from_repo, find_ghosts=False):
1750
1804
self.to_repo = to_repo
1751
1805
self.from_repo = from_repo
1752
1806
self.find_ghosts = find_ghosts
1754
def get_search(self):
1808
def get_search_result(self):
1755
1809
return self.to_repo.search_missing_revision_ids(
1756
1810
self.from_repo, find_ghosts=self.find_ghosts)
1759
class NotInOtherForRevs(object):
1761
def __init__(self, to_repo, from_repo, revision_ids, find_ghosts=False):
1813
class NotInOtherForRevs(AbstractSearch):
1814
"""Find all revisions missing in one repo for a some specific heads."""
1816
def __init__(self, to_repo, from_repo, required_ids, if_present_ids=None,
1820
:param required_ids: revision IDs of heads that must be found, or else
1821
the search will fail with NoSuchRevision. All revisions in their
1822
ancestry not already in the other repository will be included in
1824
:param if_present_ids: revision IDs of heads that may be absent in the
1825
source repository. If present, then their ancestry not already
1826
found in other will be included in the search result.
1762
1828
self.to_repo = to_repo
1763
1829
self.from_repo = from_repo
1764
1830
self.find_ghosts = find_ghosts
1765
self.revision_ids = revision_ids
1767
def get_search(self):
1831
self.required_ids = required_ids
1832
self.if_present_ids = if_present_ids
1835
if len(self.required_ids) > 5:
1836
reqd_revs_repr = repr(list(self.required_ids)[:5])[:-1] + ', ...]'
1838
reqd_revs_repr = repr(self.required_ids)
1839
if self.if_present_ids and len(self.if_present_ids) > 5:
1840
ifp_revs_repr = repr(list(self.if_present_ids)[:5])[:-1] + ', ...]'
1842
ifp_revs_repr = repr(self.if_present_ids)
1844
return "<%s from:%r to:%r find_ghosts:%r req'd:%r if-present:%r>" % (
1845
self.__class__.__name__, self.from_repo, self.to_repo,
1846
self.find_ghosts, reqd_revs_repr, ifp_revs_repr)
1848
def get_search_result(self):
1768
1849
return self.to_repo.search_missing_revision_ids(
1769
self.from_repo, revision_ids=self.revision_ids,
1770
find_ghosts=self.find_ghosts)
1850
self.from_repo, revision_ids=self.required_ids,
1851
if_present_ids=self.if_present_ids, find_ghosts=self.find_ghosts)
1773
1854
def collapse_linear_regions(parent_map):