74
def recreate_search(self, repository, search_bytes):
74
def recreate_search(self, repository, search_bytes, discard_excess=False):
75
"""Recreate a search from its serialised form.
77
:param discard_excess: If True, and the search refers to data we don't
78
have, just silently accept that fact - the verb calling
79
recreate_search trusts that clients will look for missing things
80
they expected and get it from elsewhere.
75
82
lines = search_bytes.split('\n')
76
83
if lines[0] == 'ancestry-of':
78
85
search_result = graph.PendingAncestryResult(heads, repository)
79
86
return search_result, None
80
87
elif lines[0] == 'search':
81
return self.recreate_search_from_recipe(repository, lines[1:])
88
return self.recreate_search_from_recipe(repository, lines[1:],
89
discard_excess=discard_excess)
83
91
return (None, FailedSmartServerResponse(('BadSearch',)))
85
def recreate_search_from_recipe(self, repository, lines):
93
def recreate_search_from_recipe(self, repository, lines,
94
discard_excess=False):
95
"""Recreate a specific revision search (vs a from-tip search).
97
:param discard_excess: If True, and the search refers to data we don't
98
have, just silently accept that fact - the verb calling
99
recreate_search trusts that clients will look for missing things
100
they expected and get it from elsewhere.
86
102
start_keys = set(lines[0].split(' '))
87
103
exclude_keys = set(lines[1].split(' '))
88
104
revision_count = int(lines[2])
98
114
search.stop_searching_any(exclude_keys.intersection(next_revs))
99
115
search_result = search.get_result()
100
if search_result.get_recipe()[3] != revision_count:
116
if (not discard_excess and
117
search_result.get_recipe()[3] != revision_count):
101
118
# we got back a different amount of data than expected, this
102
119
# gets reported as NoSuchRevision, because less revisions
103
120
# indicates missing revisions, and more should never happen as
379
396
repository = self._repository
380
397
repository.lock_read()
382
search_result, error = self.recreate_search(repository, body_bytes)
399
search_result, error = self.recreate_search(repository, body_bytes,
383
401
if error is not None:
384
402
repository.unlock()