~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository_reference/test_graph.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Tests for graph operations on stacked repositories."""
19
19
 
20
20
 
 
21
from bzrlib import (
 
22
    remote,
 
23
    tests,
 
24
    urlutils,
 
25
    )
21
26
from bzrlib.tests.per_repository import TestCaseWithRepository
22
27
 
23
28
 
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
 
53
 
 
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
 
72
 
 
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':
 
80
            #    continue
 
81
            self.assertEqual('Repository.get_parent_map', c.call.method)
 
82
            args = c.call.args
 
83
            location = args[0]
 
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)
 
88
 
 
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')
 
93
        # bug #388269
 
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'],
 
102
                find_ghosts=False)
 
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
 
108
            # the history.
 
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']),
 
113
            ])
 
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.