/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_revno.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
 
 
18
"""Black-box tests for bzr revno.
 
19
"""
 
20
 
 
21
import os
 
22
 
 
23
from bzrlib import tests
 
24
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
25
 
 
26
 
 
27
class TestRevno(tests.TestCaseWithTransport):
 
28
 
 
29
    def test_revno(self):
 
30
 
 
31
        def bzr(*args, **kwargs):
 
32
            return self.run_bzr(*args, **kwargs)[0]
 
33
 
 
34
        os.mkdir('a')
 
35
        os.chdir('a')
 
36
        bzr('init')
 
37
        self.assertEquals(int(bzr('revno')), 0)
 
38
 
 
39
        open('foo', 'wb').write('foo\n')
 
40
        bzr('add foo')
 
41
        bzr('commit -m foo')
 
42
        self.assertEquals(int(bzr('revno')), 1)
 
43
 
 
44
        os.mkdir('baz')
 
45
        bzr('add baz')
 
46
        bzr('commit -m baz')
 
47
        self.assertEquals(int(bzr('revno')), 2)
 
48
 
 
49
        os.chdir('..')
 
50
        self.assertEquals(int(bzr('revno a')), 2)
 
51
        self.assertEquals(int(bzr('revno a/baz')), 2)
 
52
 
 
53
    def test_revno_tree(self):
 
54
        # Make branch and checkout
 
55
        wt = self.make_branch_and_tree('branch')
 
56
        checkout = wt.branch.create_checkout('checkout', lightweight=True)
 
57
 
 
58
        # Get the checkout out of date
 
59
        self.build_tree(['branch/file'])
 
60
        wt.add(['file'])
 
61
        wt.commit('mkfile')
 
62
 
 
63
        # Make sure revno says we're on 1
 
64
        out,err = self.run_bzr('revno checkout')
 
65
        self.assertEqual('', err)
 
66
        self.assertEqual('1\n', out)
 
67
 
 
68
        # Make sure --tree knows it's still on 0
 
69
        out,err = self.run_bzr('revno --tree checkout')
 
70
        self.assertEqual('', err)
 
71
        self.assertEqual('0\n', out)
 
72
 
 
73
    def test_revno_tree_no_tree(self):
 
74
        # Make treeless branch
 
75
        b = self.make_branch('branch')
 
76
 
 
77
        # Try getting it's --tree revno
 
78
        out,err = self.run_bzr('revno --tree branch', retcode=3)
 
79
        self.assertEqual('', out)
 
80
        self.assertEqual('bzr: ERROR: No WorkingTree exists for "branch".\n',
 
81
            err)
 
82
 
 
83
    def test_dotted_revno_tree(self):
 
84
        builder = self.make_branch_builder('branch')
 
85
        builder.start_series()
 
86
        builder.build_snapshot('A-id', None, [
 
87
            ('add', ('', 'root-id', 'directory', None)),
 
88
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
89
        builder.build_snapshot('B-id', ['A-id'], [])
 
90
        builder.build_snapshot('C-id', ['A-id', 'B-id'], [])
 
91
        builder.finish_series()
 
92
        b = builder.get_branch()
 
93
        co_b = b.create_checkout('checkout_b', lightweight=True,
 
94
                                 revision_id='B-id')
 
95
        out, err = self.run_bzr('revno checkout_b')
 
96
        self.assertEqual('', err)
 
97
        self.assertEqual('2\n', out)
 
98
        out, err = self.run_bzr('revno --tree checkout_b')
 
99
        self.assertEqual('', err)
 
100
        self.assertEqual('1.1.1\n', out)
 
101
 
 
102
    def test_stale_revno_tree(self):
 
103
        builder = self.make_branch_builder('branch')
 
104
        builder.start_series()
 
105
        builder.build_snapshot('A-id', None, [
 
106
            ('add', ('', 'root-id', 'directory', None)),
 
107
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
108
        builder.build_snapshot('B-id', ['A-id'], [])
 
109
        builder.build_snapshot('C-id', ['A-id'], [])
 
110
        builder.finish_series()
 
111
        b = builder.get_branch()
 
112
        # The branch is now at "C-id", but the checkout is still at "B-id"
 
113
        # which is no longer in the history
 
114
        co_b = b.create_checkout('checkout_b', lightweight=True,
 
115
                                 revision_id='B-id')
 
116
        out, err = self.run_bzr('revno checkout_b')
 
117
        self.assertEqual('', err)
 
118
        self.assertEqual('2\n', out)
 
119
        out, err = self.run_bzr('revno --tree checkout_b')
 
120
        self.assertEqual('', err)
 
121
        self.assertEqual('???\n', out)
 
122
 
 
123
    def test_revno_with_revision(self):
 
124
        wt = self.make_branch_and_tree('.')
 
125
        revid1 = wt.commit('rev1')
 
126
        revid2 = wt.commit('rev2')
 
127
 
 
128
        out, err = self.run_bzr('revno -r-2 .')
 
129
        self.assertEqual('1\n', out)
 
130
 
 
131
        out, err = self.run_bzr('revno -rrevid:%s .' % revid1)
 
132
        self.assertEqual('1\n', out)
 
133
 
 
134
    def test_revno_and_tree_mutually_exclusive(self):
 
135
        wt = self.make_branch_and_tree('.')
 
136
        out, err = self.run_bzr('revno -r-2 --tree .', retcode=3)
 
137
        self.assertEqual('', out)
 
138
        self.assertEqual(
 
139
            'bzr: ERROR: --tree and --revision can not be used together\n',
 
140
            err)
 
141
 
 
142
 
 
143
class TestSmartServerRevno(tests.TestCaseWithTransport):
 
144
 
 
145
    def test_simple_branch_revno(self):
 
146
        self.setup_smart_server_with_call_log()
 
147
        t = self.make_branch_and_tree('branch')
 
148
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
149
        t.add("foo")
 
150
        revid = t.commit("message")
 
151
        self.reset_smart_call_log()
 
152
        out, err = self.run_bzr(['revno', self.get_url('branch')])
 
153
        # This figure represent the amount of work to perform this use case. It
 
154
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
155
        # being too low. If rpc_count increases, more network roundtrips have
 
156
        # become necessary for this use case. Please do not adjust this number
 
157
        # upwards without agreement from bzr's network support maintainers.
 
158
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
159
        self.assertLength(1, self.hpss_connections)
 
160
        self.assertLength(6, self.hpss_calls)
 
161
 
 
162
    def test_simple_branch_revno_lookup(self):
 
163
        self.setup_smart_server_with_call_log()
 
164
        t = self.make_branch_and_tree('branch')
 
165
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
166
        t.add("foo")
 
167
        revid1 = t.commit("message")
 
168
        revid2 = t.commit("message")
 
169
        self.reset_smart_call_log()
 
170
        out, err = self.run_bzr(['revno', '-rrevid:' + revid1,
 
171
            self.get_url('branch')])
 
172
        # This figure represent the amount of work to perform this use case. It
 
173
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
174
        # being too low. If rpc_count increases, more network roundtrips have
 
175
        # become necessary for this use case. Please do not adjust this number
 
176
        # upwards without agreement from bzr's network support maintainers.
 
177
        self.assertLength(5, self.hpss_calls)
 
178
        self.assertLength(1, self.hpss_connections)
 
179
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)