1
# Copyright (C) 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Tests for graph operations on stacked repositories."""
26
from bzrlib.tests.per_repository import TestCaseWithRepository
29
class TestGraph(TestCaseWithRepository):
31
def test_get_known_graph_ancestry_stacked(self):
32
"""get_known_graph_ancestry works correctly on stacking.
34
See <https://bugs.launchpad.net/bugs/715000>.
36
branch_a, branch_b, branch_c, revid_1 = self.make_double_stacked_branches()
37
for br in [branch_a, branch_b, branch_c]:
40
br.repository.get_known_graph_ancestry([revid_1]).topo_sort())
42
def make_double_stacked_branches(self):
43
wt_a = self.make_branch_and_tree('a')
44
branch_a = wt_a.branch
45
branch_b = self.make_branch('b')
46
branch_b.set_stacked_on_url(
47
urlutils.relative_url(branch_b.base, branch_a.base))
48
branch_c = self.make_branch('c')
49
branch_c.set_stacked_on_url(
50
urlutils.relative_url(branch_c.base, branch_b.base))
51
revid_1 = wt_a.commit('first commit')
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.