38
43
wt_a = self.make_branch_and_tree('a')
39
44
branch_a = wt_a.branch
40
45
branch_b = self.make_branch('b')
41
branch_b.set_stacked_on_url('../a')
46
branch_b.set_stacked_on_url(
47
urlutils.relative_url(branch_b.base, branch_a.base))
42
48
branch_c = self.make_branch('c')
43
branch_c.set_stacked_on_url('../b')
49
branch_c.set_stacked_on_url(
50
urlutils.relative_url(branch_c.base, branch_b.base))
44
51
revid_1 = wt_a.commit('first commit')
45
52
return branch_a, branch_b, branch_c, revid_1
54
def make_stacked_branch_with_long_history(self):
55
builder = self.make_branch_builder('source')
56
builder.start_series()
57
builder.build_snapshot('A', None, [
58
('add', ('', 'directory', 'root-id', None))])
59
builder.build_snapshot('B', ['A'], [])
60
builder.build_snapshot('C', ['B'], [])
61
builder.build_snapshot('D', ['C'], [])
62
builder.build_snapshot('E', ['D'], [])
63
builder.build_snapshot('F', ['E'], [])
64
source_b = builder.get_branch()
65
master_b = self.make_branch('master')
66
master_b.pull(source_b, stop_revision='E')
67
stacked_b = self.make_branch('stacked')
68
stacked_b.set_stacked_on_url('../master')
69
stacked_b.pull(source_b, stop_revision='F')
70
builder.finish_series()
71
return master_b, stacked_b
73
def assertParentMapCalls(self, expected):
74
"""Check that self.hpss_calls has the expected get_parent_map calls."""
75
get_parent_map_calls = []
76
for c in self.hpss_calls:
77
# Right now, the only RPCs that get called are get_parent_map. If
78
# this changes in the future, we can change this to:
79
# if c.call.method != 'Repository.get_parent_map':
81
self.assertEqual('Repository.get_parent_map', c.call.method)
84
self.assertEqual('include-missing:', args[1])
85
revisions = sorted(args[2:])
86
get_parent_map_calls.append((location, revisions))
87
self.assertEqual(expected, get_parent_map_calls)
89
def test_doesnt_call_get_parent_map_on_all_fallback_revs(self):
90
if not isinstance(self.repository_format,
91
remote.RemoteRepositoryFormat):
92
raise tests.TestNotApplicable('only for RemoteRepository')
94
master_b, stacked_b = self.make_stacked_branch_with_long_history()
95
self.addCleanup(stacked_b.lock_read().unlock)
96
self.make_repository('target_repo', shared=True)
97
target_b = self.make_branch('target_repo/branch')
98
self.addCleanup(target_b.lock_write().unlock)
99
self.setup_smart_server_with_call_log()
100
res = target_b.repository.search_missing_revision_ids(
101
stacked_b.repository, revision_ids=['F'],
103
self.assertParentMapCalls([
104
# One call to stacked to start, which returns F=>E, and that E
105
# itself is missing, so when we step, we won't look for it.
106
('extra/stacked/', ['F']),
107
# One fallback call to extra/master, which will return the rest of
109
('extra/master/', ['E']),
110
# And then one get_parent_map call to the target, to see if it
111
# already has any of these revisions.
112
('extra/target_repo/branch/', ['A', 'B', 'C', 'D', 'E', 'F']),
114
# Before bug #388269 was fixed, there would be a bunch of extra calls
115
# to 'extra/stacked', ['D'] then ['C'], then ['B'], then ['A'].
116
# One-at-a-time for the rest of the ancestry.